Jesway / flutter_translate

Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter.
MIT License
401 stars 118 forks source link

Add support for flavour override #50

Closed neokree closed 3 years ago

neokree commented 4 years ago

Hi,

In Android, when a project have multiple flavours, the system will bundle toghether all strings, based on the current build. So with this configuration:

If I compile the dev flavour, the strings usable are the ones from main + dev. If there is a string called app_name in main, and it is also present in dev, then the dev one overrides the main one.

I would like to have a similar feature for flutter_translate. Even if there is not the concept of flavours for dart code, the same thing can be recreated using environment variables or something similar.

I think that something like: delegate.loadFlavour('dev') could do the trick. maybe with something like this in the asset folder:

What do you think?

bratan commented 4 years ago

Hi @neokree, can you give me an example on why you would use different localized strings for the same language?

neokree commented 4 years ago

Sure. My current use case is a "whitelabel" app, that must be compiled for different clients. The problem is that a section for a client must be called "A", while the other one wants to call it "B".

This is a very specific case, but I can also see other use cases for this feature:

Obviously in all these situation you can handle it in code using if/else and adding all versions of the same translation in the same file, using either a prefix/suffix or an object group. However, these solutions increase the number of translations in the localization file, which can become a problem for medium/large apps, and also needs to use additional code in the usage part (the if/else checks for each type of build config).

bratan commented 4 years ago

Thanks for the example and explanation.

It seems this feature might be helpful in some very specific cases.

I will not be implementing it at the moment though, but feel free to submit a pull request if you wish.