Adding optional fallback to root language bundle #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I understand the fact that CAL10n doesn’t fall back to a ‘root’ language in the same way that java resource bundles do, and I understand that this was done for reasons of ‘least surprise’. However, I’d like to add the option of a fall-back. I’d like to use CAL10n, but without this feature, using CAL10n on my project is tricky. Therefore, I have implemented a change to allow a fall-back. I have tried to ensure it has the least impact on other developers or people currently using the library. So, if it looks a bit hacky (and it probably is) it’s because I’m trying to make the least changes possible.
Projects using CAL10n which wish to set this fall-back have to call
Settings.setRootLanguageFallbackEnabled(true);
before loading any bundles. Projects who want to use CAL10n in the traditional way need to do nothing.The reason I would like this change is that the distribution of language packs is done totally separately to the building of my product. Therefore, at compile time there’s only likely to be one set of language files in the product (English). This means that if someone deploys the product on a system with a different locale, they need a new language pack. It would be far easier if the language files I provided were for a ‘root’ language, which could be fallen back to. This means that (for example) if a customer moved our application from a data centre in Germany to a data centre in Thailand, it doesn’t matter what the locale settings for those environments are, the application will still run and will still have logging (currently CAL10n throws an exception if the language files cannot be found, and thus there is no logging). English might be not the ideal language here, but it’s better than the app simply not running or not having any logging.