Closed dirkvranckaert closed 2 years ago
Hi, it LGTM. Whould you like to do a PR?
Otherwise I'll implement it in a couple of weeks.
Thank you so much
@ilteoood Created PR #186
PR merged
@ilteoood when can we expect an update of the library including this fix?
@dirkvranckaert Has been released with version 0.32.0
The Issue
I'm using the library for all my translation work in all my Flutter apps. However on every setup I face the same issue, translation fallback...
This is the setup I'm using in my
main.dart
for my latest project:So a bunch of supported languages, and fallback locale file set to
en
. See below some sample json's to explain the problem. If I would leave out a root-json-block (such as theblock
in the example json's) then the standard fallback mechanism using spread operator would merge the two files and I would end up with the frenchtitle
and the englishblock
. However in the samples below you see that a nested key is missing, and with the standard implementation the maps are not 'correctly' merged together. The missing link here is no deep merge of the maps.So with the below provided translation files, translating
block.label2
would result in a proper French or English translated text. However translatingblock.label1
will always end up to be translated when the device is in English locale, but when in French locale that single key is not falled back for.The Fix
However the fix should be quite easy. To achieve this I'm using
MyFileTranslationLoader
which is an exact copy of theFileTranslationLoader
but I replaced the_loadFallback()
with this one:The
MapUtil
class (file:map_util.dart
) looks like this:The sample files
The English file (en.json):
The French file (fr.json):