Skip to content
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

Add support for flavour override #50

Closed
neokree opened this issue Jul 1, 2020 · 3 comments
Closed

Add support for flavour override #50

neokree opened this issue Jul 1, 2020 · 3 comments

Comments

@neokree
Copy link

neokree commented Jul 1, 2020

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:

  • dev/res/values/strings.xml
  • main/res/values/strings.xml
  • prod/res/values/strings.xml

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:

  • /assets/i18n/en.json
  • /assets/i18n/dev/en.json

What do you think?

@bratan
Copy link
Member

bratan commented Jul 1, 2020

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

@neokree
Copy link
Author

neokree commented Jul 1, 2020

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:

  • FREE/PRO app. The same text in a page can change based on the flavour on which is compiled (like the splash screen, or an intro text)
  • Development environments (DEV/QA/PROD). The text that declares the environment itself, for example

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
Copy link
Member

bratan commented Jul 5, 2020

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.

@bratan bratan closed this as completed Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants