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

FallbackLocale not working #87

Closed
Quadrubo opened this issue Dec 10, 2022 · 4 comments
Closed

FallbackLocale not working #87

Quadrubo opened this issue Dec 10, 2022 · 4 comments
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers

Comments

@Quadrubo
Copy link
Contributor

The FallbackLocale option is not working correctly.

// config/app.php
'locale' => 'de',

 'fallback_locale' => 'en',
// resources/lang/en/app.php
return [

    'jetstream' => [

        'Forgot Password' => 'Forgot Password',
        'Two-factor Confirmation' => 'Two-factor Confirmation',
        'Email Verification' => 'Email Verification',

    ],

];
// resources/lang/de/app.php
<?php

return [

    'jetstream' => [

        // 'Forgot Password' => 'Passwort vergessen',
        'Two-factor Confirmation' => 'Zwei-Faktor-Authentifizierung',
        'Email Verification' => 'E-Mail-Verifizierung',

    ],

];
// resources/js/app.js
.use(i18nVue, {
    lang: 'de',
    fallbackLang: 'en',
    resolve: async lang => {
        const langs = import.meta.glob('../lang/*.json');
        return await langs[`../lang/${lang}.json`]();
    }
})

I would expect the trans function to use the fallbackLocale. Instead it echoes out the translation string.

// 'Forgot Password' is set in de/app.php, locale = 'de', fallbackLocale = 'en'
console.log(trans('app.jetstream.Forgot Password')); // -> Passwort vergessen

// 'Forgot Password' is not set in de/app.php, locale = 'de', fallbackLocale = 'en'
console.log(trans('app.jetstream.Forgot Password')); // -> app.jetstream.Forgot Password
@xiCO2k xiCO2k added the bug Something isn't working label Dec 13, 2022
@xiCO2k
Copy link
Owner

xiCO2k commented Dec 13, 2022

Will review that one thanks for the issue.

@xiCO2k xiCO2k added enhancement New feature or request good first issue Good for newcomers labels Jan 21, 2023
@lenssoft
Copy link
Contributor

I am experiencing the same issue. I think it could be fixed in setLanguege method.
image

Instead of setting this.activeMessages[key] = null better use the fallbackLang and those messages to be kept in fallbackMessages
this.activeMessages[key] = this.fallbackMessages[key] || null

It would comet with the drawback that fallback lang must always be loaded and extra memory usage due to keeping them in fallbackMessages

@xiCO2k
Copy link
Owner

xiCO2k commented Feb 24, 2023

Hey @lenssoft if you can, please submit a PR for that, and I will review it.

Thanks.

@xiCO2k
Copy link
Owner

xiCO2k commented Mar 2, 2023

Fixed on #103

@xiCO2k xiCO2k closed this as completed Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants