kiwix / kiwix/libkiwix

Use mustache lambda to do translation in our templates

Open
#751 3 comments 0 reactions 1 assignee Claimed by @veloman-yunkan View on GitHub
enhancement
Dominant language
C++
Stars
197
Forks
102
Avg merge
5d 16h
Merged PRs (30d)
7

Description

Following #679

The current implementation of i18n use templating a two level :
- Render parameterized messages (translate)
- Render the HTML template (using translated text)

This is somehow complicated (Where should we use `{{}}` or `{{{}}}` ? Cpp code need to know that we use translated message and translate it before rendering the template, ...)

As mustache allow the using of lambda to compute text at runtime, we could use this to have HTML templates directly using the parameterized key.
([lambda feature](https://github.com/kainjow/Mustache/blob/master/tests/tests.cpp?rgh-link-date=2022-04-06T15%3A04%3A51Z#L644-L734), [lambda rendering](https://github.com/kainjow/Mustache/blob/master/tests/tests.cpp?rgh-link-date=2022-04-06T15%3A04%3A51Z#L851))

If we create a "translator" lambda (called `t`), we could write templates this way :

`[blabla] title="{{#t}}searchbox-tooltip BOOK_TITLE={{title}}{{/t}}" aria-label="{{#t}}searchbox-tooltip BOOK_TITLE={{title}}{{/t}}">`

We would have to write a custom parser for the `BOOK_TITLE=...` parameters but it will simplify the cpp code as it will move "all" the templating in the template and avoid us to pre-render in cpp the translated text for the template.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.