Interpolation broken by change in 3.13.1
See original GitHub issueDescribe the bug We upgraded from LinguiJS 3.13.0 to 3.13.1 and started seeing many errors logged in the console, all looking like this:
Plurals for locale en aren't loaded. Use i18n.loadLocaleData method to load plurals for specific locale. Using other plural rule as a fallback.
We are definitely loading the locale data though, so we investigated further.
Looking into the few changes in 3.13.1, the only significant commit seems to be f8f47a2. And ignoring the formatting changes in that commit, the only functional change that I can find is that it bypasses the property getters for locale
, locales
, and localeData
when calling interpolate()
. To be honest, I have no idea why that would have fixed the problem that a locale did not get immediately activated?
In any case, while bypassing the getters for locale
and locales
makes no functional difference, bypassing the getter for localeData
seems to break the functionality. _localeData
is of type AllLocaleData
, but localeData
is of type LocaleData
, and the getter looks like this:
get localeData(): LocaleData {
return this._localeData[this._locale] ?? {}
}
So really you can’t substitute localeData
with _localeData
as they are different things, causing the error inside the interpolate
function.
To Reproduce
I am not sure if there’s anything specific required to trigger the error, as far as I can tell we’re using Lingui in a pretty basic way.
import {i18n, Messages} from '@lingui/core';
import {I18nProvider} from '@lingui/react';
import {en as enPlurals, type PluralCategory} from 'make-plural/plurals';
import {messages as enMessages} from '~/src/i18n/en.po';
i18n.loadLocaleData({
en: {plurals: enPlurals},
});
i18n.load('en', enMessages);
i18n.activate('en');
function Foo() {
return <Trans>Hello</Trans>;
}
Expected behavior The console shouldn’t be full of the above error 😃
Additional context
- jsLingui version 1.3.1
- Babel version @7.16.10
- Using
@lingui/loader
with Webpack 5.67.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (5 by maintainers)
Top GitHub Comments
Damn, you’re right. Will push a fix today
Looks good now, thanks!