question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to import Quasar language packs in Vite

See original GitHub issue

What happened?

In Webpack, I would use the following to import languages from the quasar node_modules folder are per the Quasar docs:

      import(
        // https://quasar.dev/options/quasar-language-packs#dynamical-non-ssr-
        /* webpackInclude: /(en-US|de|fr|it|nb-NO|pt-BR)\.js$/ */
        `quasar/lang/${val}`
      )

It looks like import.meta.glob is the best proposed alternative but it isn’t compatible with node_module imports: https://github.com/vitejs/vite/issues/5728.

At the moment there doesn’t seem to be a good way to import these languages from the node_modules folder other than by either symlinking or copying them across manually and storing them in the src/ folder somewhere: https://github.com/vitejs/vite/issues/5728#issuecomment-1074586601

Ideally it would be useful to establish a ‘best practice’ for overcoming this issue in Quasar projects in Vite.

What did you expect to happen?

Be able to import the Quasar language files from node_modules so changes are pulled in to the app on a update automatically.

Reproduction URL

Not applicable

How to reproduce?

N/A

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

Quasar CLI Commands/Configuration (@quasar/cli | @quasar/app-webpack | @quasar/app-vite)

Platforms/Browsers

No response

Quasar info output

No response

Relevant log output

No response

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
rstoenescucommented, Apr 7, 2022

Long story short (extract from my additions to the docs below). The examples are with boot files, but I think you can infer how to use in vue files also.

  1. Non-SSR
// -- With @quasar/app-vite --

import { Quasar } from 'quasar'

// relative path to your node_modules/quasar/..
// change to YOUR path
const langList = import.meta.glob('../../node_modules/quasar/lang/*.mjs')
// or just a select few (example below with only DE and FR):
// import.meta.glob('../../node_modules/quasar/lang/(de|fr).mjs')

export default async () => {
  const langIso = 'de' // ... some logic to determine it (use Cookies Plugin?)

  try {
    langList[ `../../node_modules/quasar/lang/${ langIso }.mjs` ]().then(lang => {
      Quasar.lang.set(lang.default)
    })
  }
  catch (err) {
    // Requested Quasar Language Pack does not exist,
    // let's not break the app, so catching error
  }
}
  1. SSR Mostly same thing, only that Quasar.lang.set requires a second parameter. Quasar.lang.set(lang.default, ssrContext)
1reaction
maggie0002commented, Apr 12, 2022

Looks good, an adapted version using the same method seems to be working for me. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quasar Language Packs
A Quasar Language Pack refers to the internationalization of Quasar's own components, some of which have labels. WARNING. It should be noted that...
Read more >
[SOLVED] Dynamic set of Quasar lang from store value
I have a value that is set in my store that should be read to determine what language quasar will use. Following the...
Read more >
How do I translate Quasar component? - Stack Overflow
import en from 'quasar/lang/en-us.js' /* import other languages */ import { state, } from '@state/modules/i18n'; const locale = state.locale; ...
Read more >
Adding full i18n to Quasar. If you are wanting to translate your…
First, you need to install vue-i18n into your project. ... failed: 'Aktion fehlgeschlagen', ... import(`quasar/lang/${lang.value}`).then(language =>
Read more >
Getting Started with the Quasar Framework - Section.io
There are three ways in which we can install Quasar as listed below. ... website or app CSS code to RTL if a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found