-
Notifications
You must be signed in to change notification settings - Fork 88
Locale member field on generated localization class, #18
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
base: master
Are you sure you want to change the base?
Conversation
and use its canonicalized name when invoking Intl.message. This allows clients to handle translations for multiple locales, using different instances of the generated localization class.
Hi @nielsenko, thanks for the PR! Seems this creates a breaking change on how some API is used till now, for example how you can get current locale (till now it was by calling Maybe to postpone this change till the next major version release |
Linked issue from IntelliJ IDE plugin: localizely/flutter-intl-intellij#26 |
You can still get the current locale by calling |
+1 , merging this would indeed solve the multiple localization issue. |
Hi @nielsenko, @Claudishe, Thank you for your contribution and feedback! I've tested the PR code, and it looks like a solution for the multiple localization issue. I agree with the @aleksakrstic that we should postpone this change till the next major version release as it solves the mentioned issue, and maybe to try to find a way to ease this transition. In case I missed something, or if there is a way to avoid mentioned breaking change, please let us know. |
Hi @lzoran Thanks for your reply, and sorry for the delayed response. Yes, I noticed that you advocate calling However, since you ask explicitly, howto allow direct The idea is to ensure that the field If you agree with this idea, then I can implement it tomorrow. It is a very minor change. * Actually I don't like that ** I'm not sure |
Hi @nielsenko Using I am more for using something like I am for leaving this PR open till we come to the moment to release next major version (date not yet known), since the PR contains useful code changes. |
Some complain: https://github.com/chaldea-center/intl_utils 1. multi-localizationsimply modified the solution of @nielsenko . Here are some changes:
static Future<S> load(Locale locale, {bool override = false}) {
final localeName = locale.canonicalizedName;
return initializeMessages(localeName).then((_) {
final localizations = S(locale);
if (override || S._current == null) {
Intl.defaultLocale = localeName;
S._current = localizations;
}
return localizations;
});
} To get current locale:
2. hot-reloadSee: add a function called Map<String, LibraryLoader> get _deferredLibraries => {
'ar': () => new Future.value(null),
'en': () => new Future.value(null),
'es': () => new Future.value(null),
'ja': () => new Future.value(null),
'ko': () => new Future.value(null),
'zh': () => new Future.value(null),
'zh_Hant': () => new Future.value(null),
};
Future<void> reloadMessages() async {
for (final lib in _deferredLibraries.values) {
await lib();
}
messages_ar.messages.messages.clear();
messages_ar.messages.messages.addAll(messages_ar.MessageLookup().messages);
messages_en.messages.messages.clear();
messages_en.messages.messages.addAll(messages_en.MessageLookup().messages);
// more languages...
} Changes:
// root StatefuleWidget
@override
void reassemble() {
super.reassemble();
reloadMessages();
} Sure, if you are using vscode/jetbrain plugin, you should change to use something like File Watcher to watch l10n directory and run |
Hi @narumishi |
I will join the complaint bandwagon on this issue. I have been searching for a solution to this issue for a month now since I did not think about the underlying issue being in this package. I disagree with the overall opinion here that this PR is not worthy being merged yet because a new major release would be needed to announce the breaking change. Please, fix this issue already! |
Any news on this bug? It is still an issue and it would be great if it can be fixed. |
I am still actively maintaining my fork (and hence this PR) as I think this is the right way to fix this issue. Ever since opening my PR, I am using my fork instead of the official package. |
Make the Locale a member field on the generated localization class, and use its canonicalized name when invoking Intl.message. This allows clients to handle translations for multiple locales, using different instances of the generated localization class.