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

Add static public property for acessing current localisation #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/i18n-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ export class I18nGenerator implements IDisposable, InsertActionProviderDelegate
casesContent += " else ";
}
casesContent += `if ("${normalized}" == lang) {\n`;
casesContent += ` return SynchronousFuture<WidgetsLocalizations>(const _I18n_${normalized}());\n`;
casesContent += ` I18n.current = const _I18n_${normalized}();\n`;
casesContent += " }\n";
}

for (let languageCode in languageCodes) {
if (languageCodes.hasOwnProperty(languageCode)) {
const normalized = languageCodes[languageCode];
casesContent += ` else if ("${languageCode}" == languageCode) {\n`;
casesContent += ` return SynchronousFuture<WidgetsLocalizations>(const _I18n_${normalized}());\n`;
casesContent += ` I18n.current = const _I18n_${normalized}();\n`;
casesContent += " }\n";
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -646,7 +647,8 @@ class GeneratedLocalizationsDelegate extends LocalizationsDelegate<WidgetsLocali
final String lang = I18n._locale != null ? I18n._locale.toString() : "";
final String languageCode = I18n._locale != null ? I18n._locale.languageCode : "";
{cases}
return SynchronousFuture<WidgetsLocalizations>(const I18n());
I18n.current ??= const I18n();
return SynchronousFuture<WidgetsLocalizations>(I18n.current);
}

@override
Expand Down