slang icon indicating copy to clipboard operation
slang copied to clipboard

Support 'deferred loading'

Open westlinkin opened this issue 1 year ago • 5 comments

When using Flutter Web, all the translations go into main.dart.js, making this file very big. So the web app loads very slowly the first time user opens it. But most users will only use one (two at most) translations.

Is Slang support deferred loading? making each translation into separate files, only loading them if needed

westlinkin avatar Apr 13 '23 07:04 westlinkin

Flutter has this feature but it seems that we cannot check if the library is loaded yet.

Only loadLibrary is not enough as all translation access is non-async so there needs to be a mechanism to fallback to the base translations.

The logic would be if <locale> is loaded, then use this, otherwise use <base locale>

Tienisto avatar Apr 13 '23 20:04 Tienisto

We can just load the and together, (if target locale === base locale, then only need to load one locale file). If the user switches to another locale, just load that file.

westlinkin avatar Apr 14 '23 09:04 westlinkin

yes, but what should String a = t.myTranslation return? This getter is not a future.

Tienisto avatar Apr 14 '23 09:04 Tienisto

the < base locale > is always loaded, just use the < base locale >'s tranlation. after other tranlsation's is downloaded, reload the correct translations. Is that ok?

westlinkin avatar Apr 14 '23 12:04 westlinkin

Thinking about this again, I think that this is technically possible. But don't expect this feature soon as I don't have much time for this.

Tienisto avatar Apr 15 '23 15:04 Tienisto