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

Dynamic Translations (e.g. via network) #52

Closed
Tienisto opened this issue Feb 5, 2022 · 4 comments
Closed

Dynamic Translations (e.g. via network) #52

Tienisto opened this issue Feb 5, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@Tienisto
Copy link
Member

Tienisto commented Feb 5, 2022

Motivation
To reduce asset size, developers can extract the translations to the server.
The translations will be fetched at runtime.

Developer Experience
Because every key needs to be known at compile time, the base translations must be available.

// strings.i18n.json
{
  "greet": "Welcome {name}"
}

Now load a locale:

// your logic, represents ONE locale!
Map fetchFromServer() {
  return {
    'greet': 'Hello {name}'
  }
}

// via LocaleSettings
void example1() {
  String a = t.greet(name: 'Tom'); // "Welcome Tom"

  Map data = fetchFromServer(); 
  LocaleSettings.loadCustom(data); // the new load function
  String b = t.greet(name: 'Tom'); // "Hello Tom"
}

// via dependency injection
void example2() {
  String a = t.greet(name: 'Tom'); // "Welcome Tom"

  Map data = fetchFromServer();
  final t2 = AppLocaleUtils.buildCustom(data); // the new build function
  String b = t2.greet(name: 'Tom'); // "Hello Tom"
}

This will blow up the generated file. Therefore, this should be opt-in.

targets:
  $default:
    builders:
      fast_i18n:
        options:
          contexts:
            dynamic_translations: true # enable this feature
@Tienisto Tienisto added the enhancement New feature or request label Feb 5, 2022
@erabti
Copy link

erabti commented Mar 21, 2022

When can we expect this to land @Tienisto ?

@Tienisto
Copy link
Member Author

Currently, I have no plans to implement this feature because there are still lots of open questions.

This library generates the locale enum - should all locales be specified and how?
The base translations have to be included beforehand which is annoying.

Why do you want this feature? Only to reduce asset size?

@erabti
Copy link

erabti commented Mar 22, 2022

Yes, reducing asset size and the ability to change strings remotely.

@Tienisto
Copy link
Member Author

Released in v3.0.0-dev.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants