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

feat: Add f_lang function to emulate python f-strings for translations #5962

Merged
merged 2 commits into from
Oct 12, 2021

Conversation

stephanegigandet
Copy link
Contributor

Fixes #5961

From a discussion with @alexgarel who suggested python's f-strings.

This is to make it possible to use named variables in translations.
e.g. "blablabla {some_variable} blabla {some_other_variable} bla."

Benefits:

  • easier to read/understand than the %s
  • function calls are cleaner, no need to remember order of variables (or to change them if we want to rephrase the source string differently)
  • makes it possible to have translations where the order of the variable differs by language
  • The {variable} is quote close to the ${variable} in perl

For existing strings, I think we can keep the %s for now (unless there's a good reason to change them), so that translators don't have to retranslate them.

For new strings, I think named parameters is better.

@stephanegigandet stephanegigandet added the Translations We use a non-standard version of GetText, lack language variants support translate.openfoodfacts.org label Oct 11, 2021
@stephanegigandet stephanegigandet requested a review from a team as a code owner October 11, 2021 15:02
@sonarcloud
Copy link

sonarcloud bot commented Oct 11, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@stephanegigandet stephanegigandet merged commit 435f898 into main Oct 12, 2021
@stephanegigandet stephanegigandet deleted the f_strings branch October 12, 2021 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Translations We use a non-standard version of GetText, lack language variants support translate.openfoodfacts.org
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use named variables for interpolations in string translations (Python f-string vs sprintf)
2 participants