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.

Doesn't work with Vue and vuex-i18n

See original GitHub issue

Describe the bug There is an icon in the vscode sidebar, but got empty content. The app is built with Vue.js(2.6.10) and Vuex-i18n(1.13.1), and the i18n works well, but the extension just doesnโ€™t work whether I config locale path or not.

Extension Version i18n Ally (1.13.6)

Framework/i18n package you are using Vue.js(2.6.10), vuex-i18n (1.13.1)

Device Infomation

  • OS: Windows
  • Version: 7
  • VSCode Version: 1.41.1

Extension Log Sorry I canโ€™t paste the log from the cloud environment, but it seems normal, you can see it from the picture below. It detects vue successfully and the locales loading path is correct, too.

Screenshots image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
gregverescommented, Apr 9, 2020

@pureliumy I can share with you my config that works. I am using Vue and Vue-i18n.

first my i18n plugin file (imported from main.ts)

import Vue from 'vue';
import VueI18n from 'vue-i18n';
import messages from '@/locales';

Vue.use(VueI18n);

console.log(messages);
export default new VueI18n({
  locale: process.env.VUE_APP_I18N_LOCALE || 'en-us',
  fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en-us',
  messages: messages
});

I store my locale files in /src/locales/{en, fr, โ€ฆ} like this: /src/locales/ index.ts โ€” en โ€” initial.json โ€” activities.json โ€” index.ts โ€” fr โ€” initial.json โ€” activities.json โ€” index.ts

the locales/index.ts file looks like this:

import en from './en';
import fr from './fr';

export default {
  en: en.messages,
  fr: fr.messages
};

the en / fr index.ts file looks like this:

import initial from './_initial.json';
import activities from './activities.json';

export default {
  messages: { ...initial, ...activities }
};

the activities.json file looks like this:

{
  "activities": {
    "addLeagueBtn": "Add a League or Ladder",
  }
}

Ok, thatโ€™s how the code is setup. Now lets look at how I have the extension hooked up: I like to keep everything configured at the workspace level rather than the user level so that when I switch machines everything is the same. So, in my project directory, there is a .vscode folder and in there is a settings.json for my VSCode settings. It contains the following:

  "i18n-ally.localesPaths": "src/locales",
  "i18n-ally.keystyle": "nested",
  "i18n-ally.sourceLanguage": "en",
  "i18n-ally.displayLanguage": "en",
  "i18n-ally.sortKeys": true,
  "i18n-ally.keepFulfilled": true,
  "i18n-ally.enabledParsers": "json",

I just checked and there is nothing defined in the user settings.json file.

With this setup, I see the following in the output tab:

๐Ÿˆถ Activated, v1.15.1

โ€•โ€•โ€•โ€•โ€•โ€•

๐Ÿ’ผ Workspace root changed to "c:\Users\gregv\source\repos\SquashSpider\SquashSpider\SkyCourt.UI\ui"
๐Ÿ“ฆ Packages file "package.json" found
๐Ÿ•ณ Packages file "pubspec.yaml" not exists
๐Ÿ•ณ Packages file "composer.json" not exists
๐Ÿ•ณ Packages file "Gemfile" not exists
๐ŸŒž Enabled
โœ… "Vue" framework(s) detected, extension enabled.
๐Ÿงฌ Parsers "json" enabled.

๐Ÿš€ Initializing loader "c:\Users\gregv\source\repos\SquashSpider\SquashSpider\SkyCourt.UI\ui"
๐Ÿ“‚ Directory structure: dir
๐Ÿ—ƒ Path Matcher Regex: /^(?<locale>[\w-_]+)(?:.*\/|^).*\.(json5?|ya?ml|jsx?|tsx?|mjs|ini|pot|php?)$/

๐Ÿ“‚ Loading locales under c:\Users\gregv\source\repos\SquashSpider\SquashSpider\SkyCourt.UI\ui\src\locales
	๐Ÿ“‘ Loading (en) en/activities.json
	๐Ÿ“‘ Loading (en) en/money.json
	๐Ÿ“‘ Loading (en) en/_initial.json
	๐Ÿ“‘ Loading (fr) fr/activities.json
	๐Ÿ“‘ Loading (fr) fr/money.json
	๐Ÿ“‘ Loading (fr) fr/_initial.json

๐Ÿ‘€ Watching change on c:\Users\gregv\source\repos\SquashSpider\SquashSpider\SkyCourt.UI\ui\src\locales

โœ… Loading finished

โ€•โ€•โ€•โ€•โ€•โ€•

This gets me all setup. Then I can do the following things in VSCode:

  1. I can see translations in my vue files right beside the usage.
  2. I can select some text, press ctrl-. to bring up the actions menu and โ€œextract text into i18n messagesโ€ comes up. It walks me through a series of three questions: a. what the key should be (I can use โ€˜.โ€™ in the name to indicate nested keys) a. what form of translation mechanism I want in the vue file a. which file I want to save the key/message into

This all works really well when setup. I am really greatful for this extension.

I hope this helps you get the extension working in your project. I donโ€™t think I missed any part of the configuration.

0reactions
antfucommented, Apr 21, 2020

Closing this for now. Feel free to reopen if you still have any questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue-i18n undefined in vuex [duplicate]
But surprisingly doesn't work... it says this.$i18n is not defined, but it is. enter image description here Any thoughts?? import storeย ...
Read more >
How to use $t from vue-i18n inside Vuex action - Get Help
A problem that I am having is dynamic changing. So I can now access the t() function in my vuex store, but when...
Read more >
Vue i18n: Building a multi-language app with locale switcher
Vue i18n is a key process needed to localize your Vue apps and websites. Learn how to set up a Vue app with...
Read more >
vuex-i18n/readme.md
19, The vuex-i18n plugin is intended to be used for applications that use vuex as ; 20, store and require localized messages. Make...
Read more >
Vue 2 Localization with Vue I18n: A Step-by-Step Guide
json file. Note ยป If you have an existing Vue project, and don't want to install the Vue CLI, you can recreate the...
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