Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug(translations): One locale file doesn't load, despite being valid json. All others of the same nature do. #803

Closed
1 task done
majora2007 opened this issue Sep 23, 2024 · 3 comments

Comments

@majora2007
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Which Transloco package(s) are the source of the bug?

Transloco

Is this a regression?

Yes

Current behavior

  1. Switch from English -> Irish
  2. Expect to see key lookups the same as en.json (default) aka user-preferences.tap-to-paginate-label
  3. Actually seeing all keys looked as ga.user-preferences.tap-to-paginate-label which breaks every key in the app.

Expected behavior

To work as it did previously, lookup as user-preferences.tap-to-paginate-label and thus render the localization changes.

Please provide a link to a minimal reproduction of the bug, if you won't provide a link the issue won't be handled.

https://demo.kavitareader.com/settings#preferences

Transloco Config

provideTransloco(translocoOptions),
        provideTranslocoLocale({
          defaultLocale: 'en'
        }),
        provideTranslocoPersistTranslations({
          loader: HttpLoader,
          storage: { useValue: localStorage },
          ttl: 604800
        }),
        provideTranslocoPersistLang({
          storage: {
            useValue: localStorage,
          },
        }),
const translocoOptions = {
  config: {
    reRenderOnLangChange: true,
    availableLangs: transformLanguageCodes(languageCodes),
    prodMode: environment.production,
    defaultLang: 'en',
    fallbackLang: 'en',
    missingHandler: {
      useFallbackTranslation: true,
      allowEmpty: false,
    },
  } as TranslocoConfig
};
function transformLanguageCodes(arr: Array<string>) {
    const transformedArray: Array<string> = [];

    arr.forEach(code => {
        // Add the original code
        transformedArray.push(code);

        // Check if the code has a hyphen (like uk-UA)
        if (code.includes('-')) {
            // Transform hyphen to underscore and add to the array
            const transformedCode = code.replace('-', '_');
            transformedArray.push(transformedCode);
        }
    });

    return transformedArray;
}

Please provide the environment you discovered this bug in

Transloco: 7.4.3
Angular: 17.3.4
Node: v20.11.1
Package Manager: Node
OS:Windows

"@jsverse/transloco": "^7.4.3",
    "@jsverse/transloco-locale": "^7.0.1",
    "@jsverse/transloco-persist-lang": "^7.0.1",
    "@jsverse/transloco-persist-translations": "^7.0.1",
    "@jsverse/transloco-preload-langs": "^7.0.1",

Browser

No response

Additional context

You can reproduce this here:
https://demo.kavitareader.com/
Demouser/Demouser64

  1. Click here: https://demo.kavitareader.com/settings#preferences
  2. Change locale to Irish.
  3. Locale file is here: https://github.com/Kareadita/Kavita/blob/develop/UI/Web/src/assets/langs/ga.json

I would like to make a pull request for this bug

No

@majora2007
Copy link
Author

Some follow up information, my other locales work completely fine. I can load any other language and it renders perfectly. So the message in the console might be misleading.

The 3rd image shows that the locale looks valid, the keys are there (and I guess the prepended language code is fine).

I'm a bit stumped at the issue though. The json looks fine, the key is there in localStorage showing valid json.

image
image
image

@majora2007 majora2007 changed the title Bug(translations): Locale keys are having language prefix prepended when not default language Bug(translations): One locale file doesn't load, despite being valid json. All others of the same nature do. Sep 23, 2024
@aindriu80
Copy link

I don't know why it doesn't work.. I took some screenshots. Here is the login screen

2024-10-17_10-50

it displays ga.login.forgot-password

2024-10-17_10-47

ga.login.forgot-password in the code

2024-10-17_10-47_1

on weblate.org there is the translation:

2024-10-17_10-47_2

All translations have been translated:

2024-10-17_10-48

I've tried a new browser - chromnium - then cleared all data in the console - it switched back to English, I went to settings and selected Irish/Gaeilge and the keys are displayed

@majora2007
Copy link
Author

This was solved. The language code was not added to the available languages. Weblate does not use the same language codes as Transloco, so manual mapping is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants