esskar / vscode-flutter-i18n-json

VS Code extension to create a binding between your translations from .json files and your Flutter app.
92 stars 22 forks source link

can't change language ,new version bug #44

Closed Owen-Hw closed 4 years ago

Owen-Hw commented 4 years ago

new version bug ,can't change language. -------------old version-------- @override Future load(Locale _locale) { I18n._locale ??= _locale; I18n._shouldReload = false; final Locale locale = I18n._locale; final String lang = locale != null ? locale.toString() : ""; final String languageCode = locale != null ? locale.languageCode : ""; …… } ---------new version--------------------- @override Future load(Locale locale) { I18n._locale ??= locale; I18n._shouldReload = false; final String lang = I18n._locale != null ? locale.toString() : ""; final String languageCode = I18n._locale != null ? locale.languageCode : ""; ...... }

Owen-Hw commented 4 years ago

change: I18n._locale ??= locale; I18n._shouldReload = false; final String lang = I18n._locale != null ? I18n._locale.toString() : ""; final String languageCode = I18n._locale != null ? I18n._locale.languageCode : "";

nohli commented 4 years ago

I'm having a similar problem with the new version.

More precisely:

void updateLocale(BuildContext context) {
  if (english ?? false)
    I18n.locale = Locale('en', 'US');
  else
    I18n.locale = Localizations.localeOf(context) ?? Locale('en', 'US');
}

in combination with

  @override
  initState() {
    super.initState();
    I18n.onLocaleChanged = onLocaleChanged;
  }

  void onLocaleChanged(Locale _locale) {
    if (mounted) setState(() {});
  }

doesn't work any more. This can change the device language to English back and forth.

Installing the old version in Visual Studio Code has helped.

esskar commented 4 years ago

pushed a new version; please retry. sorry for the bug

nohli commented 4 years ago

works :) dankeschön!