-
Notifications
You must be signed in to change notification settings - Fork 11
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
Support packages #1
Comments
I'm not sure what you mean by "simple solution for using it in Flutter or Angular project" because I'm using it within both AngularDart and Flutter projects. On the other hand, I'm completely ignoring "official" standard and I'm just using this package ... so if you desire some kind of bridge between "official" and "great" and you are offering to build it as a by-product of your thesis, I will gladly incorporate it into this project and glory will be yours forever! |
Can you provide an example how you handle switching locales on fly and how you access locales in widgets? π |
@dafesimonek Would you mind pasting a few lines of code here? Thanks! |
We use 'provider' package for on the fly changes:
class AppConfigModel extends ChangeNotifier {
String _languageCode;
String get languageCode => _languageCode;
set languageCode(String value) {
_languageCode = value;
notifyListeners();
}
}
ChangeNotifierProvider<AppConfigModel>.value(
value: AppConfigModel()),
ProxyProvider<AppConfigModel, Messages>(builder: (_, appConfig, __) {
// TODO add other languages here
switch (appConfig.languageCode) {
case 'cs':
log.i('Setting messages to Czech');
return Messages_cs();
case 'en':
log.i('Setting messages to English');
return Messages();
}
log.w(
'Unknown language code "${appConfig.languageCode}", falling back to default English');
return Messages();
}),
class SomeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
// use provider's ConsumerX syntax sugar to access multiple models at once
return Consumer3<AppConfigModel, Messages, LoginModel>(
builder: _buildContent,
);
}
Widget _buildContent(BuildContext context, AppConfigModel appConfig,
Messages messages, LoginModel loginModel, Widget _) {
return Text('Text from i69n: ${messages.app_name}');
} |
Hmm, just an idea, in order to make this package better. Wouldn't it be better to generate files like
where In contrast to the current state, where individual translations are generated substantially separately. TL;DR; this part is the biggest issue to make by program (or I do not see how to do it easily), w/o any complicated parsing. And complicates a lot creating Flutter's Localization delegate and especially using the package.
And that is pitty, cause the yaml idea and implementation for this package is super awesome! As an example, take a look at Intl implementation of generated files https://github.com/tenhobi/flashcards/tree/0dbc194dbde6acc197e211352c7c16a3e0ff3121/common/lib/src/i18n/generated TL;DR; The propose is to
Dunno, share your opinion, please. βοΈ Maybe I'm just wrong. π€·ββ |
Dude. First of all - thanks for your suggestions. Second - why would you stuff everything on one issue? And the third ... we will have to discuss it in Czech, preferably in person ... DevFest? Next Flutter Meetup? However, if I understand correctly: Message accessor which would generate that ugly switch statement - good idea, but I'm not sure if it's possible ... build_runner is quite restrictive. I'm not sure if I can generate a file based on several inputs ... maybe not. Must investigate. Sharing common interface - that's already happening, everything extends "English" at this point. |
We can discuss it at the next Flutter Meetup. π |
This package is, of course, superior π₯ to the default localization packages. Althrough it doesn't provide a simple solution for using it in Flutter or Angular project.
It would be super nice to create support packages β with inspiration in BLoC packages structure β which would contain
i69n
,flutter_i69n
andangular_i69n
inpackages/
directory.This would increase the ability to adapt this package. For example, this is some other package about easy localization which has support for Flutter which gives it right on the spot better prestigue to use it. People are lazy and don't wanna repeat yourselves (or dumb and they cannot create proper support packages).
For Flutter it would mean to create, probably, only
Localizations
andLocalizationsDelegate
classes and maybe (?) modify a bit the current package to support loading proper file using locale codes, if it isn't already supported now. Dunno, further investigation would be needed.Some other resources:
Personal interest: I would like to use this backage as part of my Bachelor's Thesis, for it's simplicity, so I can try to create the Flutter package or help with it.
The text was updated successfully, but these errors were encountered: