EugeneMeles / laravel-react-i18n

Allows to connect your `Laravel` Framework translation files with `React`.
MIT License
73 stars 8 forks source link

translation is not working #6

Closed umairali closed 1 year ago

umairali commented 1 year ago

I am trying like below code but only the default language is showing. on npm run build files are generating in build assets folder but translation is not working.

        <LaravelReactI18nProvider
            lang={'en'}
            fallbackLang={'en'}
            resolve={async (lang) => {
                const langs = import.meta.glob('../../lang/*.json');
                try {
                    return await langs[`/lang/${lang}.json`]()
                } catch (e) {
                    //
                }
            }}
        >
            <React.StrictMode>
                <Main/>
            </React.StrictMode>
        </LaravelReactI18nProvider>
import { useLaravelReactI18n } from 'laravel-react-i18n';

const { t, tChoice, setLang, getActiveLanguage, isLoaded } = useLaravelReactI18n();

t('Test')
umairali commented 1 year ago

I tried laravel 8 with mix and laravel 10 with vite but both did not translate.

EugeneMeles commented 1 year ago

Hi, you can try this pero as example: https://github.com/parth391/react-ssr-i18n

abraaoz commented 1 year ago

The problem is:

return await langs[`/lang/${lang}.json`]()

Replace it with:

return await langs[`../../lang/${lang}.json`]()