Closed MilosKarakas closed 1 year ago
@ilteoood Any idea when you could review this PR? Thanks.
@ilteoood Hey, do you have any feedback on this?
Hi @MilosKarakas, Sorry but I'm in honeymoon rn with limited internet connection.
I'll check it when I'll go home, I promise.
Hi @ilteoood , thanks for the response. Have a nice time during honeymoon 😄
Hi @MilosKarakas, I've looked at this implementation and, sincerely I don't like it too.
It's too complicated and do too much stuff for a single method. I've not finished yet, but here is my proposal: https://github.com/ilteoood/flutter_i18n/pull/198
Can you look at it and give me a suggestion pls?
Matteo
Hey @ilteoood I'll take a look until the end of next week and give you my opinion.
Regards, Miloš
Sorry, I'm still overloaded with work. I'll let you know as soon as I am done looking into it.
Hi, I just completed the PR that enables translation with FlutterI18n instance, and without context. Basically I made BuildContext nullable in 4 functions that required it: translate(..), plural(..), currentLocale(..) and refresh(..). I added an optional named parameter FlutterI18n? instance to all of these, and have added it to I18nText and I18nPlural widgets as well. I decided to go with this kind of implementation to avoid adding additional 4 functions to the FlutterI18n class. IMHO it would make it too bloated. I am not completely satisfied with this solution either, since you need to pass null for BuildContext each time you translate without it, but I didn't have any better ideas how to implement it.
I have added tests as well.
Now you can register a FlutterI18n instance, and call for translator, for instance, somewhere in your data layer, like this:
Whenever you pass an instance that is not null it will avoid trying to use the context. When instance is not passed context is used. Developers must take care not to set both BuildContext and instance to null.