vscode-flutter-i18n-json icon indicating copy to clipboard operation
vscode-flutter-i18n-json copied to clipboard

Need to get Locale object

Open lakshmanaprabhu opened this issue 5 years ago • 3 comments

Team, Is that possible to fetch the current locale used in that app? (Particularly, while changing locale manually)

Tried to fetch the current locale,

  • Locale myLocale = Localizations.localeOf(context);

    import 'dart:ui' as ui;

  • Locale myLocale = ui.window.locale;

But, both returns device locale. Actually, I want a locale from generated/I18n._locale.

is that possible?

lakshmanaprabhu avatar May 01 '20 16:05 lakshmanaprabhu

You could use code like this:

Localizations.of<I18n>(context, WidgetsLocalizations).cancel == 'Cancel'

gcemcw4 avatar May 14 '20 12:05 gcemcw4

Thanks for the reply. In my case, I have multiple languages to choose from.

Why don't we add getter method for Locale in I18n.dart ? like, static Locale get locale => _locale;

Seems, it helps me better. Thoughts?

lakshmanaprabhu avatar Jun 17 '20 08:06 lakshmanaprabhu

Yeah, it could simplify my life to have this getter too

QuentinSc avatar Jun 21 '20 09:06 QuentinSc