lokalise / i18n-ally

🌍 All in one i18n extension for VS Code
https://marketplace.visualstudio.com/items?itemName=lokalise.i18n-ally
MIT License
4k stars 321 forks source link

Extension not working at the first time VS Code startup #626

Closed alexanderniebuhr closed 3 years ago

alexanderniebuhr commented 3 years ago

the key page.login.ms365 is used in the svelte file, but the extension does not find it in its overview. Or I am misunderstanding that view

<script>
  import { useRouter } from "@svelteuse/router";
  import { onMount } from "svelte";
  import { msalInstance } from "../logic/auth.js";
  import { t } from "svelte-i18n";

  onMount(() => {
    console.log("onMount Login Page");
    async function init() {
      let redirectResponse = await msalInstance.handleRedirectPromise();
      if (redirectResponse !== null) {
        $useRouter.navigate("/");
        window.location.reload();
      }
    }
    init();
  });

  async function handle365Login(event) {
    console.log("LOGIN EVENT");

    msalInstance.loginRedirect().catch((e) => {
      console.error(e);
    });
  }
</script>

<f-button class="bg-light-300" on:click={(e) => handle365Login(e)}>
  {$t("page.login.ms365")}
</f-button>

<style>
</style>

image

terales commented 3 years ago

This means that this key is not found in locale files. Do you have this key there?

alexanderniebuhr commented 3 years ago

Yes, I think so. For example, my en-GB.json

{
  "layout": {
    "default": {
      "logout": "Log out",
      "news": "News"
    }
  },
  "page": {
    "login": {
      "ms365": "Sign in with Microsoft 365"
    }
  }
}

for some more help, my global settings

    "i18n-ally.extract.autoDetect": false,
    "i18n-ally.translate.deepl.apiKey": "***:fx",
    "i18n-ally.translate.deepl.enableLog": true,
    "i18n-ally.translate.deepl.useFreeApiEntry": true,
    "i18n-ally.translate.engines": [
        "deepl",
        "google"
    ],
    "i18n-ally.displayLanguage": "de-DE",
    "i18n-ally.indent": 2,
    "i18n-ally.tabStyle": "space",
    "i18n-ally.translate.overrideExisting": true,
    "i18n-ally.translate.parallels": 5,
    "i18n-ally.namespace": true,
    "i18n-ally.includeSubfolders": false,

and my workspace settings

{
  "i18n-ally.localesPaths": [
    "locales"
  ],
  "i18n-ally.sortKeys": true,
  "i18n-ally.keepFulfilled": false,
  "i18n-ally.translate.saveAsCandidates": false,
  "i18n-ally.keystyle": "nested",
  "i18n-ally.sourceLanguage": "de-DE",
  "i18n-ally.extract.keygenStrategy": "random",
}
terales commented 3 years ago

Thanks! Can you share your logs, please?

I suspect that locales were not loaded and this setting could help:

"i18n-ally.enabledParsers": ["json"],

Here is how to find logs: image

alexanderniebuhr commented 3 years ago

Logs here, before adding the setting. Going to test the setting

🈶 Activated, v2.6.18

――――――

💼 Workspace root changed to "c:\Users\Alexander\Documents\projects\frix\repguide\application"
📦 Packages file "package.json" found
🕳 Packages file "pubspec.yaml" not exists
🕳 Packages file "composer.json" not exists
🕳 Packages file "Gemfile" not exists
🌞 Enabled
🧩 Enabled frameworks: Svelte, General
🧬 Enabled parsers: json, yaml, json5

📈 Telemetry id: ******
🚀 Initializing loader "c:\Users\Alexander\Documents\projects\frix\repguide\application"
📂 Directory structure: file
🗃 Path Matcher Regex: /^(?<locale>[\w-_]+)\.(?<ext>json|ya?ml|json5)$/

📂 Loading locales under c:\Users\Alexander\Documents\projects\frix\repguide\application\locales
    📑 Loading (cs-CZ) cs-CZ.json [1626269686787.7852]
    📑 Loading (da-DK) da-DK.json [1626269686990.7874]
    📑 Loading (de-DE) de-DE.json [1626269672219.7832]
    📑 Loading (en-GB) en-GB.json [1626269824842.562]
    📑 Loading (es-ES) es-ES.json [1626269827576.0632]
    📑 Loading (fr-FR) fr-FR.json [1626269828522.563]
    📑 Loading (hu-HU) hu-HU.json [1626269751406.3557]
    📑 Loading (it-IT) it-IT.json [1626269830854.5654]
    📑 Loading (nl-NL) nl-NL.json [1626269836824.0635]
    📑 Loading (pl-PL) pl-PL.json [1626269740087.768]
    📑 Loading (sl-SI) sl-SI.json [1626269838628.063]
    📑 Loading (sv-SE) sv-SE.json [1626269764733.0642]

👀 Watching change on c:\Users\Alexander\Documents\projects\frix\repguide\application\locales
✅ Loading finished

――――――

📤 Loading review data
alexanderniebuhr commented 3 years ago

@terales yes adding the setting, does work. However, I would expect it to work without that setting, since json should be supported by default :/

"i18n-ally.enabledParsers": ["json"],
antfu commented 3 years ago

Yes, json is enabled by default. Can you share a repro?

alexanderniebuhr commented 3 years ago

https://github.com/frickegroup/repguide (you wouldn't be able to run it with npm run... it breaks currently)

One thing to note. It just occurs on a fully clean restart on VSCode on the first time. So clean restart VSCode, open Login.svelte click left on the i18n-ally Icon, and see that keys are not matched. If you run command Reload Window it gets picked up.

terales commented 3 years ago

Can't fix it as we cannot catch the root cause of it. Let's close for now and stick to reloading VS Code as a workaround.

alexanderniebuhr commented 3 years ago

@terales yup, I agree that we can stick to the workaround. It's not the biggest deal, and the workaround is very "stable". However in my opinion this should be kept in backlog.

alexanderniebuhr commented 3 years ago

Trying to find a fix and provide a PR. Came a bit further with the debugging. It is caused by the CurrentFile class, i guess.

The .watch() method is always called on activate In the method the extension tries to load activeTextEditor, however that is undefined on start without an editor open. https://github.com/lokalise/i18n-ally/blob/a2c65497cd22a8b32f45f6547ad6ba507813b279/src/core/CurrentFile.ts#L43-L43

Normally I would think it should get then updated with the subscription onDidChangeActiveTextEditor -- but as far I can tell, it does call the update function, but it is not picking up -- likely caused by some hidden exception in the stack

Another test I did was to check if using Global.loader.getCoverage(node) in the ProgressProvider would work -- it worked. https://github.com/lokalise/i18n-ally/blob/c92656fb802fff8d23c4e1710f60375652326df6/src/views/providers/ProgressProvider.ts#L38-L38

Currently I am thinking of two things, but want your opinion.

  1. Try to find a work, to set CurrentFile to empty if no activeTextEditor is found, which then symlinks to global or a default file path. Not biggest fan of this
  2. Use the Global.loader for the Views Progress, Tree, Usage Report and hide the View Current File if no activeTextEditor is found

/cc @antfu any ideas with the provided foundings?

alexanderniebuhr commented 3 years ago

@antfu @terales works now with my test project. So I think https://github.com/lokalise/i18n-ally/commit/bee57f2816c4cf8eab06e694a4e21832c1d173eb did it

antfu commented 3 years ago

@alexanderniebuhr Glad to hear that! And thanks for the investigation 🙌

terales commented 3 years ago

@alexanderniebuhr great to hear that! Thanks a lot for the investigation!