Model Localization - openmpp/openmpp.github.io GitHub Wiki
Home > Model Development Topics > Model Localization
This topic describes how to provide translations for model-specific run-time messages.
- Multilingual Support forthcoming content
- Quick start
- How model finds translated message
- Model developer: How to mark strings for translation in model code
You can provide translated messages for your model by editing modelName.message.ini
file located in the same directory where modelName.exe
is.
For example:
dir /B openmpp_win_20180205\models\bin
....
modelOne.exe
modelOne.ini
modelOne.message.ini
modelOne.sqlite
modelOne.message.ini
is translated messages for modelOne.exe
Message.ini file must be UTF-8 encoded and it contain model translated messages:
;
; modelOne localized messages
;
[FR]
Run %d = Exécution: %d
[fr-CA]
Run %d = Exécution: %d
;
; Example of multi-line translated message:
;
"Scenario processing" = "\
Traitment \
du scénario\
"
[en]
; Model = Model
If translation the same as original message you can exclude it, e.g.: Model = Model
is not required.
At start model determine list user preferred languages.
For example if current environment is French Canadian and model default language is EN then language list will be: (fr-ca, fr, en)
.
User language preference can be changed in Windows Control Panel or by Linux LANG environment variable. You can override environment language by using model command-line or ini-file argument:
modelOne.exe -OpenM.MessageLanguage es-EC
To find translated message model does lookup in:
modelName.message.ini
- database table
model_word
- database table
lang_word
Search done in order of user preferred languages.
For example, if modelOne.message.ini
is same as above and database table model_word
contains entry:
fr-CA Done. Fini.
Then model messages in French Canadian environment can be similar to:
2014-03-17 17:14:24.0023 Model: modelOne
2014-03-17 17:14:24.0070 Exécution 101
....
2014-03-17 17:14:24.0179 Fini.
As you can see for current user language fr-CA
model found two messages translated in "generic fr
" French: "Exécution" and "Fini",
however "Model" still untranslated. To fix this you can update modelOne.message.ini
by adding:
[fr-CA]
Model = Modèle
Then result would look like:
2014-03-17 17:14:24.0023 Modèle: modelOne
2014-03-17 17:14:24.0070 Exécution 101
....
2014-03-17 17:14:24.0179 Fini.
Omc model compiler automatically include first "const char *"
argument of
theLog->logMsg("some message");
theLog->logFormatted("some format %d %g %s",....);
- macro
LT("some message")
WriteLogEntry("some message");
WriteDebugLogEntry("some message");
WarningMsg("some message");
-
ModelExit("some message");
into outputmodel.message.ini
file, which can be used as translation starting point.
If your source code directory already contains translated code/model.message.ini
then such file is merged
with newly added model messages into output bin/model.message.ini
, which you can forward to translation team.
It is possible to use macro LT("something")
in order to build concatenated message,
however LT is "strictly inline" because it returns temporary const char *
pointer. As result following will crash your model:
const char * myBadDay = LT("nice day");
if (myBadDay .... // memory access violation, model crash
How to avoid string concatenation. String concatenation considered as bad practice by any translation guide. For example, if you have something like:
string msg = LT("Table has ") + std::to_string(rowCount) + LT(" rows");
theLog->logMsg(msg.c_str());
then try to replace it with:
theLog->logFormatted("Table has %d rows", rowCount);
Non-translatable strings. Not every output in your model you want to translate For example, you may don't want to translate your model trace output:
WriteDebugLogEntry(NO_LT("------------"));
WriteDebugLogEntry(NO_LT("{1, 2, 3, 4}"));
WriteDebugLogEntry(NO_LT("------------"));
Please use NO_LT
macro to disable unnecessary translation.