Skip to content

Instantly share code, notes, and snippets.

@titusdecali
Last active December 28, 2021 22:46
Show Gist options
  • Save titusdecali/4ec3cdd8e8ce54e5e65785001d44d6aa to your computer and use it in GitHub Desktop.
Save titusdecali/4ec3cdd8e8ce54e5e65785001d44d6aa to your computer and use it in GitHub Desktop.
Vue3 i18n main.js setup
import { createApp } from 'vue'
import App from './App.vue'
// i18n
import I18n from './i18n.js'
const i18n = createI18n({
locale:
localStorage.getItem('lang') ||
// Detect user's browser language
I18n.detectLanguage() ||
process.env.VUE_APP_I18N_LOCALE,
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'ko',
// Load selected lang's .json file
messages: I18n.loadLocaleMessages()
})
const app = createApp(App)
app.use(i18n)
app.mount('#app')
@ATLANT-Z
Copy link

А откуда, блть, ты берёшь createI18n. Где здесь импорт

@titusdecali
Copy link
Author

А откуда, блть, ты берёшь createI18n. Где здесь импорт

It's included in the i18n package.
Please follow my guide:
https://medium.com/better-programming/vue-i18n-ultimate-guide-fb3d9db48c94

@ATLANT-Z
Copy link

Sry for my lang, but it's so annoying.

I've this error

in ./src/locales/ru.json
Syntax Error: Final loader (./node_modules/@intlify/vue-i18n-loader/lib/index.js) didn't return a Buffer or String
 @ ./src/locales sync [A-Za-z0-9-_,\s]+\.json$/

I've been trying to solve this for 5 hours
Can u help me with it?

@ATLANT-Z
Copy link

ATLANT-Z commented Oct 13, 2021

Aaand. Is it okay, that my ru.json look like next img after >vue-translation-manager translate command
image

@titusdecali
Copy link
Author

It looks like you are returning null as the key, but it may only accept key value pairs with a string as the value.
If you are using vue-translation-manager, it should give you a name for the key and not just null.

if you’ve been fighting this for five hours, it’s probably easier to start over again and follow my guide exactly.

@ATLANT-Z
Copy link

I have followed your guidance very closely.
null fields disappear after I save the file with BabelEdit after PreTranslate.

Oh my goodness.
The mistake was that one of the translation fields contained just such a string.
test@gmail.com
If you remove the @, then everything is ok.
Explain to me, please, what kind of game?

@titusdecali
Copy link
Author

If it’s a string, the @ shouldn’t matter. It’s hard to say what went wrong without seeing the code directly.

@ATLANT-Z
Copy link

Can i show u? Have u free time to think about it?

@demircancelebi
Copy link

For people coming this far, you need to run npm install vue-i18n@next to be able to import { createI18n } from 'vue-i18n'
https://vue-i18n.intlify.dev/guide/migration/breaking.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment