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

Consider using a template engine for string building #1212

Open
lmoureaux opened this issue Aug 7, 2022 · 0 comments
Open

Consider using a template engine for string building #1212

lmoureaux opened this issue Aug 7, 2022 · 0 comments
Labels
enhancement New feature or request question Further information is requested refactoring This issue requires code refactoring

Comments

@lmoureaux
Copy link
Contributor

Is your feature request related to a problem? Please describe.

When constructing complex text, we're limited by the plural-handling capabilities of gettext (Qt's own solution has the same limitations). This becomes obvious with messages where two or more plural forms can appear, such as %1 citizen(s) (is|are) made happier using %2 luxury good(s).

Describe the solution you'd like

We should have a better way to format such complex strings. One solution is to use ICU directly: its class MessageFormat allows for very complex templates. We already depend on ICU through Qt.
I believe that simple strings should still go through gettext or Qt, but we could fetch the translated template with it and then format it:

icu::MessageFormat format = qstring_to_icu(_("some template here"));
QString formatted = icu_to_qstring(format.format(args...));

The two conversion functions look easy to implement since both ICU and QString use UTF-16 for the internal representation. Maybe we'll want a small wrapper to avoid writing ICU code as this might be confusing.

A translator guide will be needed to help them with the uncommon format (in terms of Freeciv21 strings).

Describe alternatives you've considered

Splitting sentences is a bad option because not all language like the same sentence structures as English. Using (s) is also a bad option for languages with many plurals.
Grantlee is another templating engine, but it suffers from the same drawbacks with respect to translations as gettext and Qt.

Additional context

#1206 #1208 #1209 #1210
Discord discussion at https://discord.com/channels/378908274113904641/753356257007501454/1005933097428201552

@lmoureaux lmoureaux added enhancement New feature or request question Further information is requested refactoring This issue requires code refactoring labels Aug 7, 2022
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 refactoring This issue requires code refactoring
Projects
None yet
Development

No branches or pull requests

1 participant