long1eu / flutter_i18n

This plugin create a binding between your translations from .arb files and your Flutter app.
Apache License 2.0
252 stars 55 forks source link

Generated list of supported locales is incorrect #113

Open fl0cke opened 4 years ago

fl0cke commented 4 years ago

I have manually specified the order of locales in my app as

supportedLocales: const [
  Locale('en'),
  Locale('nb'),
],

together with two translation files for en and nb. However, everytime i start the app i get the message that the application's locale (en) not support by the localization delegate. So after investigating i noticed that the plugin generates the following list of supported locales:

List<Locale> get supportedLocales {
  return const <Locale>[
    Locale("nb", ""),
    Locale("en", ""),
  ];
}

Which, according to the official documentation, is not correct and probably the reason why the locale resolution fails (emphasis mine):

The primary language subtag must not be null. The region subtag is optional. When there is no region/country subtag, the parameter should be omitted or passed null instead of an empty-string.

noordawod commented 4 years ago

Could be a bug indeed, but if a change is introduce now which fixes your problem, it will most probably break all other uses. Any chance you can just add an empty countryCode for each of the locales and check if this fixes the problem?

This can be fixed to follow the rules when we increase the major version number, but not before I think.

fl0cke commented 4 years ago

Any chance you can just add an empty countryCode for each of the locales and check if this fixes the problem?

Haven't checked that. But one can use the provided resolutionCallback and set withCountry to false, which also fixed the problem. However, since the current implementation is clearly in violation of the Locale spec, it should be fixed at some point in the future 👍