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

Localizations improvement #42

Open
bohdanudreambit opened this issue Jun 3, 2021 · 1 comment
Open

Localizations improvement #42

bohdanudreambit opened this issue Jun 3, 2021 · 1 comment
Labels
enhancement New feature or request question Further information is requested

Comments

@bohdanudreambit
Copy link

There are two problems in implementation of localization.

Problem 1. Translate function requires from us to know full and strange keys like this:

locale?.translate(
           ’Review this form below, and tap AGREE if you\’re ready to continue.’) ??
         ’Review this form below, and tap AGREE if you\’re ready to continue.’,

Problem 2. Current implementation can’t properly handle cases when we need to insert variable into random place of the string. RP just concatinates sequance of texts and variables but some languages might require to change the order of words. For example:

_errorMessage =
      “${locale?.translate(‘Should be between’) ?? ‘Should be between’} ${widget.answerFormat.minValue} 
${locale?.translate(‘and’) ?? ‘and’} ${widget.answerFormat.maxValue}“;

Working on the private fork of research package repo for company we faced these issues.
There are great solution to solve these problems.
Solution for Problem 1. Use getters in RPLocalization, for example:
String get reviewAndAgreeToContinue => translate(“reviewAndAgreeToContinue”);
Solution for Problem 2. Use functions similarly to getters, like this one:
String valueShouldBeBetween(Object minValue, Object maxValue);

Our main goals are to stay closer to Flutter internationalization and improve your package. If anybody interested in this idea please let me know and I will create PR soon.

@MadsVSChristensen MadsVSChristensen added the enhancement New feature or request label Aug 12, 2021
@bardram
Copy link
Contributor

bardram commented Jun 13, 2023

Problem 1 has been fixed in version 0.7.1 for a while. See the tutorial on using localization in Research Package.

However, problem 2 is more fundamental. I would like to get input on this. One idea is to use $ placeholders in a string and allow the translate methods to take parameters. In this case, the example above would look something like this:

locale?.translate(‘between_values’, [minValue, maxValue]);

where the between_values is defined as

  "between_values" : "Should be between $0 and $1."

in the locale file.

Would this work. Or are there better options?

@bardram bardram added the question Further information is requested label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants