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

Templating to aid enriching localized content with HTML #33

Closed
nilmerg opened this issue May 28, 2020 · 1 comment · Fixed by #41
Closed

Templating to aid enriching localized content with HTML #33

nilmerg opened this issue May 28, 2020 · 1 comment · Fixed by #41
Labels
enhancement New feature or request
Milestone

Comments

@nilmerg
Copy link
Member

nilmerg commented May 28, 2020

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

Content that can be translated to other languages may sometimes require changes to its structure. Total %d for example may get translated in German to %d Gesamt.
There may also be entire sentences which get translated. If they're translated to a language such as Arabic the sentence may reversed as textual content in Arabic is written from right to left (RTL).

To make this possible, source code must mark the entire content in a single message as localizable. e.g. t('Total %d'). String concatenation is not possible.

In case a developer wants to enrich parts of the content with HTML, this is currently not possible in such a case. Say I'd want to put Total in a span to style it differently, the result would look like this: (Example taken from https://github.com/Icinga/icingadb-web/pull/94/files)

<span class="meta">Total</span> %d

Though, this would require rendering the HTML instantly and allow the translator to change the markup. Both are undesirable side-effects.

Describe the solution you'd like

There is already the possibility to format content using the class FormattedString. Why not extend it so that it supports a simple form of templating. This could look like this:

{{#total}}Total{{/total}} %d

Given the following code:

FormattedString::create(
    '{{#total}}Total{{/total}} %d',
    ['total' => Html::tag('span')]
);

The result could be:

<span>Total</span> 1234

and in German:

1234 <span>Gesamt</span>

@lippserd
Copy link
Member

lippserd commented Sep 9, 2020

I'd stick with Mustache here and begin the block with {{#total}}...

@nilmerg nilmerg added the enhancement New feature or request label May 26, 2021
nilmerg added a commit to Icinga/icingadb-web that referenced this issue May 26, 2021
@nilmerg nilmerg added this to the 0.4.0 milestone Jun 24, 2021
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

Successfully merging a pull request may close this issue.

2 participants