diff --git a/src/i18n-generator.ts b/src/i18n-generator.ts index 963985e..8df3f5c 100644 --- a/src/i18n-generator.ts +++ b/src/i18n-generator.ts @@ -253,7 +253,7 @@ export class I18nGenerator implements IDisposable, InsertActionProviderDelegate casesContent += " else "; } casesContent += `if ("${normalized}" == lang) {\n`; - casesContent += ` return SynchronousFuture(const _I18n_${normalized}());\n`; + casesContent += ` I18n.current = const _I18n_${normalized}();\n`; casesContent += " }\n"; } @@ -261,7 +261,7 @@ export class I18nGenerator implements IDisposable, InsertActionProviderDelegate if (languageCodes.hasOwnProperty(languageCode)) { const normalized = languageCodes[languageCode]; casesContent += ` else if ("${languageCode}" == languageCode) {\n`; - casesContent += ` return SynchronousFuture(const _I18n_${normalized}());\n`; + casesContent += ` I18n.current = const _I18n_${normalized}();\n`; casesContent += " }\n"; } } @@ -590,6 +590,7 @@ class I18n implements WidgetsLocalizations { const I18n(); static Locale _locale; static bool _shouldReload = false; + static I18n current; static set locale(Locale newLocale) { _shouldReload = true; @@ -646,7 +647,8 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate(const I18n()); + I18n.current ??= const I18n(); + return SynchronousFuture(I18n.current); } @override