-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Internationalization of kiwix-serve's backend #679
Conversation
cb659d9
to
ffb5373
Compare
Codecov Report
@@ Coverage Diff @@
## master #679 +/- ##
==========================================
+ Coverage 60.55% 61.09% +0.54%
==========================================
Files 56 58 +2
Lines 3732 3789 +57
Branches 2060 2080 +20
==========================================
+ Hits 2260 2315 +55
- Misses 1471 1473 +2
Partials 1 1
Continue to review full report at Codecov.
|
0a6b256
to
7f9f562
Compare
7f9f562
to
f82bd4c
Compare
@mgautierfr This PR is becoming pretty big. I think that it makes sense for you to throw a quick glance at it lest I move too far ahead with an approach that you may criticize in the end. Please note that intermediate commits contain some temporary solutions that get replaced in the end. The current state reflects my vision of how error messages and templates should be translated in the C++ code. |
99c18eb
to
04d0f46
Compare
@veloman-yunkan Thx for this PR trying to tackling the complex problem of internationalisation. Unfortunately @mgautierfr is pretty busy these weeks and it might take a two weeks before you get a feedback from him. That said, I believe 5os PR desserves an explication comment, 5is is really too big to be obvious. |
I am planning to split this PR into at least two parts
|
04d0f46
to
6c5d6c8
Compare
6c5d6c8
to
79c0b36
Compare
80ecc77
to
34d069e
Compare
79c0b36
to
dbe9108
Compare
e8d8b63
to
3d576df
Compare
3d576df
to
f8b3d2b
Compare
The (failing) tests now demonstrate that some text in the taskbar is not translated. Will fix in the next commit.
The new test fails since the "Go to the main page" button is not yet internationalized.
The new test fails since the "Go to random page" button is not yet internationalized.
At this point a potential issue has been revealed. Now we produce the final HTML via 2-level template expansion 1. Render parameterized messages 2. Render the HTML template In which templates we should use double mustache "{{}}" (HTML-escaping) tags and where we may use triple mustache "{{{}}}" (non-escaping) tags?
In the absence of the "userlang" query parameter in the URL, the value of the "Accept-Language" header is used. However, it is assumed that "Accept-Language" specifies a single language (rather than a comma separated list of languages possibly weighted with quality values). Example: Accept-Language: fr // should work Accept-Language: fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5 // The requested language will be considered to be // "fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5". // The i18n code will fail to find resources for such a language // and will use the default "en" instead.
4d230c7
to
927c125
Compare
Rebased-fixup on master. I agree with the PR as it is now. I've few concern/improvement on it but it can be handle later, I will open issues for them. |
The story of search_results.css static/skin/search_results.css was extracted from static/templates/no_search_result.html before the latter was dropped. static/templates/no_search_result.html in turn seems to be a copied and edited version of static/templates/search_result.html. In the context of exploratory work on the internationalization of kiwix-serve (PR #679) I noticed duplication of inline CSS across those two templates and intended to eliminated it. That goal was not fully accomplished (static/templates/search_result.html remained untouched) because by that time PR #679 grew too big and the efforts were diverted into splitting it into smaller ones. Thus search_results.css slipped into one of those small PRs, without making much sense because nothing really justifies preserving custom CSS in the "Fulltext search unavailable" error page. At the same time, it served as the only case where a link to a cacheable resource is generated in C++ code (rather than found in a template). This poses certain problems to the handling of cache-ids. A workaround is to expel the URL into a template so that it is processed by `kiwix-resources`. This commit merely demonstrates that solution. But whether it should be preserved (or rather the "Fulltext search unavailable" page should be deprived of CSS) is questionable.
Yes I think we should be able to ingest it. I've created this task to track the work. Can you confirm that the translatewiki bot will have access to commit to this repository? |
@Abijeet Thank you! |
The story of search_results.css static/skin/search_results.css was extracted from static/templates/no_search_result.html before the latter was dropped. static/templates/no_search_result.html in turn seems to be a copied and edited version of static/templates/search_result.html. In the context of exploratory work on the internationalization of kiwix-serve (PR #679) I noticed duplication of inline CSS across those two templates and intended to eliminated it. That goal was not fully accomplished (static/templates/search_result.html remained untouched) because by that time PR #679 grew too big and the efforts were diverted into splitting it into smaller ones. Thus search_results.css slipped into one of those small PRs, without making much sense because nothing really justifies preserving custom CSS in the "Fulltext search unavailable" error page. At the same time, it served as the only case where a link to a cacheable resource is generated in C++ code (rather than found in a template). This poses certain problems to the handling of cache-ids. A workaround is to expel the URL into a template so that it is processed by `kiwix-resources`. This commit merely demonstrates that solution. But whether it should be preserved (or rather the "Fulltext search unavailable" page should be deprived of CSS) is questionable.
The story of search_results.css static/skin/search_results.css was extracted from static/templates/no_search_result.html before the latter was dropped. static/templates/no_search_result.html in turn seems to be a copied and edited version of static/templates/search_result.html. In the context of exploratory work on the internationalization of kiwix-serve (PR #679) I noticed duplication of inline CSS across those two templates and intended to eliminated it. That goal was not fully accomplished (static/templates/search_result.html remained untouched) because by that time PR #679 grew too big and the efforts were diverted into splitting it into smaller ones. Thus search_results.css slipped into one of those small PRs, without making much sense because nothing really justifies preserving custom CSS in the "Fulltext search unavailable" error page. At the same time, it served as the only case where a link to a cacheable resource is generated in C++ code (rather than found in a template). This poses certain problems to the handling of cache-ids. A workaround is to expel the URL into a template so that it is processed by `kiwix-resources`. This commit merely demonstrates that solution. But whether it should be preserved (or rather the "Fulltext search unavailable" page should be deprived of CSS) is questionable.
Addresses the C++ part of kiwix/kiwix-tools#59
This PR introduces facilities for supporting internationalized textual output from the kiwix-serve backend (C++ code).
static/i18n/
(one file per language). Those JSON files are compiled into C++ code by a new scriptkiwix-compile-i18n
.kiwix::ParameterizedMessage
class.ParameterizedMessage(msgId, [msgParams])
creates a message object with the specified id and (optional) parameters. The text of the message for the desired language must be obtained via theParameterizedMessage::getText(const std::string& language)
method.userlang
query parameter. Adding support for user language selection via cookies and/or the Accept-Language header should be easy.