开发者

HTML templating in C++ and translations

开发者 https://www.devze.com 2022-12-29 07:23 出处:网络
I\'m using HTML_Template for templating in my C++-based web app (don\'t ask).I chose that because it was very simple and it turns out to be a good solution.

I'm using HTML_Template for templating in my C++-based web app (don't ask). I chose that because it was very simple and it turns out to be a good solution.

The only problem right now is that I would like to be able to include translatable strings in the HTML templates (HTML_Tem开发者_运维知识库plate does not really support that).

Ultimately, what I would like is to have a single file that contains all the strings to be translated. It can then be given to a translator and plugged back in to the app and used depending on which language the user chose in settings.

I've been going back and forth on some options and was wondering what others felt was the best choice (or if there's a better choice that isn't listed)

  1. Extend HTML_Template to include a tag for holding the literal string to translate. So, for example, in the HTML I would put something like

    <TMPL_TRANS "this is the text to translate"/>

  2. Use a completely separate scheme for translation and preprocess the HTML files to generate the final template files (without the special translation lingo). For example, in the pre-processed file, translatable text would look like this:

    {{this is the text to translate}}

    and the final would look like:

    this is the text to translate

  3. Don't do anything and let the translators find the string to translate in the html and js files themselves.


You may want to consider arrays, if not already.

A popular implementation for translating strings is to use tables and indices. One index is for the language and the second index is for the string. Create a function that returns strings based on these two indices:
const std::string& Get_String(unsigned int language_index, unsigned int string_index);

Each language would have a table of strings (or const char *). There would be a table of pointers to language tables, one for each supported language.

The biggest pain is to convert existing code to use this system.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号