|
|
(5 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | The {{MOD|localize}} module handle translation in several language of your application. This module is very small in size and very efficient.
| + | {{MODULE |
− | | + | |name=localize |
− | == Usage ==
| + | |category=Tool |
− | | + | |image=raw.githubusercontent.com/aoineko-fr/MSXgl/main/engine/doc/img/sample_loc.png |
− | The translation process consists of 3 elements:
| + | |dependency1= |
− | * A source file (or several) in which the user places his translations for each supported language.
| + | |dependency2= |
− | * A header file with resulting data generated by the Build tool from the source files.
| + | |dependency3= |
− | * A module to be initialized in the code, then functions to select a language and to retrieve a given text's translation.
| + | |sample1=s_loc |
− | | + | |sample2= |
− | === Translation source file ===
| + | |sample3= |
− | A translation source file is a text file (encoded as UTF-8) that must include:
| + | }} |
− | * A tag that defines each language section as: <tt>[language]</tt>.
| |
− | * A translation list in the form: <tt>key = "text"</tt>.
| |
− | | |
− | For example:
| |
− | [en]
| |
− | Start = "Start"
| |
− | Options = "Options"
| |
− | Exit = "Exit"
| |
− |
| |
− | [fr]
| |
− | Start = "Commencer"
| |
− | Options = "Options"
| |
− | Exit = "Quitter"
| |
− |
| |
− | [ja]
| |
− | Start = "スタート"
| |
− | Options = "オプション"
| |
− | Exit = "しゅうりょう"
| |
− | | |
− | You can use as many localization files as you like.
| |
− | You can, for example, group everything together in a single file, have different thematic files (menu, in-game, per mission, etc.), have a file for each language, etc.
| |
− | The Build Tool will gather them all together to generate the file you'll use in your code.
| |
− | | |
− | Language codes can be anything you like, but must contain only alphanumeric or '<tt>_</tt>' characters.
| |
− | We recommend using the [https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes 2-letter ISO 639-1 codes] to define a language. The use of some given codes enables automatic conversion of UTF-8 characters into those compatible with MSX default fonts. The following are currently supported:
| |
− | | |
− | {| class="wikitable sortable"
| |
− | |- | |
− | ! Code<br/>ISO 639-1 !! Code<br/>ISO 639-2 !! Language !! Notes !! Conversion !! Font layout
| |
− | |-
| |
− | | <tt>en</tt> || <tt>eng</tt> || English || ✓
| |
− | |rowspan="16"| Latin
| |
− | |rowspan="16"| <img width="100%" src="https://raw.githubusercontent.com/aoineko-fr/MSXgl/main/engine/datasrc/font/BIOS/font_bios_latin.png" /> | |
− | |-
| |
− | | <tt>fr</tt> || <tt>fra fre</tt> || French || ✓ (missing [ÀÂÈÊËÎÏÔÙÛŸ] accents and [Œœ])<br/>Convert: Œ→O+E, œ→o+e
| |
− | |-
| |
− | | <tt>de</tt> || <tt>deu ger</tt> || German || Missing [ßẞ]
| |
− | |-
| |
− | | <tt>es</tt> || <tt>spa</tt> || Spanish, Castilian || ✓
| |
− | |-
| |
− | | <tt>da</tt> || <tt>dan</tt> || Danish || Missing [Øø]
| |
− | |-
| |
− | | <tt>no</tt> || <tt>nor</tt> || Norwegian || Missing [Øø]
| |
− | |-
| |
− | | <tt>nl</tt> || <tt>nld dut</tt> || Dutch || ✓
| |
− | |-
| |
− | | <tt>fi</tt> || <tt>fin</tt> || Finnish || ✓ (missing rare [ŠšŽž])
| |
− | |-
| |
− | | <tt>is</tt> || <tt>isl ice</tt> || Icelandic || Missing [ÁÐðÍÓÚÝýÞþ]
| |
− | |-
| |
− | | <tt>ga</tt> || <tt>gle</tt> || Irish|| ✓
| |
− | |-
| |
− | | <tt>it</tt> || <tt>ita</tt> || Italian || ✓
| |
− | |-
| |
− | | <tt>pl</tt> || <tt>pol</tt> || Polish || Missing [ĄąĆćĘꣳŃńÓŚśŹźŻż]
| |
− | |-
| |
− | | <tt>pt</tt> || <tt>por</tt> || Portuguese || ✓ (missing [ÁÍÓÚÂÊÔÀÒÈÌÙÏ] accents)
| |
− | |-
| |
− | | <tt>sk</tt> || <tt>slk slo</tt> || Slovak || Missing [žŕľšťýďčĺň]
| |
− | |-
| |
− | | <tt>sv</tt> || <tt>swe</tt> || Swedish || ✓
| |
− | |-
| |
− | | <tt>tr</tt> || <tt>tur</tt> || Turkish || Missing [ı]
| |
− | |-
| |
− | | <tt>ja</tt> || <tt>jpn</tt> || Japanese || Missing [◯゙◯゚] and [ゐゑヰヱ] (archaic characters)<br/>Convert: ◯゙→◯+゛, ◯゚→◯+゜ || Kana || <img width="100%" src="https://raw.githubusercontent.com/aoineko-fr/MSXgl/main/engine/datasrc/font/BIOS/font_bios_japanese2.png" />
| |
− | |- | |
− | | <tt>ko</tt> || <tt>kor</tt> || Korean || ''To check... seems broken'' || Hangul || <img width="100%" src="https://raw.githubusercontent.com/aoineko-fr/MSXgl/main/engine/datasrc/font/BIOS/font_bios_hangul.png" />
| |
− | |-
| |
− | | <tt>ar</tt> || <tt>ara</tt> || Arabic || ''To check... reverse order'' || Arabic || <img width="100%" src="https://raw.githubusercontent.com/aoineko-fr/MSXgl/main/engine/datasrc/font/BIOS/font_bios_arabic2.png" /> | |
− | |-
| |
− | | <tt>uk</tt> || <tt>ukr</tt> || Ukrainian || Missing [іїєґ] | |
− | |rowspan="2"| Cyrillic
| |
− | |rowspan="2"| <img width="100%" src="https://raw.githubusercontent.com/aoineko-fr/MSXgl/main/engine/datasrc/font/BIOS/font_bios_cyrillic.png" /> | |
− | |-
| |
− | | <tt>ru</tt> || <tt>rus</tt> || Russian || Missing [ё]
| |
− | |} | |
− | | |
− | In translation entries, the key can only use alphanumeric or '<tt>_</tt>' characters.
| |
− | | |
− | <u>Notes</u>:
| |
− | * The MSXgl translation file format respects the format of the <tt>.ini</tt> files, so you can benefit from syntax highlighting if you use this extension. That said, this is not mandatory and you could, for example, use a <tt>.loc</tt> extension for your localization file.
| |
− | * Language code <tt>int</tt> and <tt>max</tt> are reserved and must not be used.
| |
− | | |
− | === Generated header file === | |
− | | |
− | By adding source files to your project configuration (<tt>project_config.js</tt>; see [[Modules/localize#Settings|bellow]]), the build tool will automatically group your source files into a header file for inclusion in your code.
| |
− | | |
− | You'll get warning messages if some of your translation keys exist in one language but not in another. The same applies if the same key is defined several times for the same language.
| |
− | | |
− | === Use the module in your code === | |
− | | |
− | In your code, you only need 3 functions to use the location system:
| |
− | * <tt>Loc_Initialize</tt> to initialize the localization module.
| |
− | * <tt>Loc_SetLanguage</tt> to set the current language to use.
| |
− | * <tt>Loc_GetText</tt> to get a given text translation in the current language.
| |
− | | |
− | For example:
| |
− | // Include the generated header file
| |
− | #include "my_localization.h"
| |
− |
| |
− | // Set the root data generated by the Build tool
| |
− | Loc_Initialize(g_LocData, TEXT_MAX);
| |
− |
| |
− | // Select French language
| |
− | Loc_SetLanguage(LANG_FR);
| |
− |
| |
− | // Display the text corresponding to 'HELLO' key
| |
− | Print_DrawTextAt(10, 10, Loc_GetText(TEXT_HELLO));
| |
− | | |
− | == Dependencies ==
| |
− | Dependency on other modules: ''None''.
| |
− | | |
− | == Settings ==
| |
− | | |
− | The localization process can be customized in your Build tool configuration file, <tt>project_config.js</tt>.
| |
− | | |
− | Available options:
| |
− | //-- List files to be localized (array)
| |
− | LocFiles = [ "file1.ini", "file2.ini" ];
| |
− |
| |
− | //-- Localization output filename (string)
| |
− | LocOutput = "localization.h";
| |
− |
| |
− | //-- Localization structure name (string)
| |
− | LocStruct = "g_LocData";
| |
− | | |
− | <u>Note</u>: If <tt>LocFiles</tt> is empty (default value), the localization process is disabled.
| |
− | | |
− | == Appendix ==
| |
− | * See also: Sample program {{SAMPLE|s_loc}}
| |
− | | |
− | == Documentation ==
| |
− | {{FRAME_DOC|localize}}
| |
− | | |
− | [[category:Module]][[category:Module/Gameplay]]
| |
The localize module handle translation in several language of your application. This module is very small in size and very efficient.
Usage
To use this module, include "localize.h" in your source code, and add "localize" to the modules list (LibModules) in your project's configuration file (project_config.js).
The translation process consists of 3 elements:
- A source file (or several) in which the user places his translations for each supported language.
- A header file with resulting data generated by the Build tool from the source files.
- A module to be initialized in the code, then functions to select a language and to retrieve a given text's translation.
Translation source file
A translation source file is a text file (encoded as UTF-8) that must include:
- A tag that defines each language section as: [language].
- A translation list in the form: key = "text".
For example:
[en]
Start = "Start"
Options = "Options"
Exit = "Exit"
[fr]
Start = "Commencer"
Options = "Options"
Exit = "Quitter"
[ja]
Start = "スタート"
Options = "オプション"
Exit = "しゅうりょう"
You can use as many localization files as you like.
You can, for example, group everything together in a single file, have different thematic files (menu, in-game, per mission, etc.), have a file for each language, etc.
The Build Tool will gather them all together to generate the file you'll use in your code.
Language codes can be anything you like, but must contain only alphanumeric or '_' characters.
We recommend using the 2-letter ISO 639-1 codes to define a language. The use of some given codes enables automatic conversion of UTF-8 characters into those compatible with MSX default fonts. The following are currently supported:
Code ISO 639-1 |
Code ISO 639-2 |
Language |
Notes |
Conversion |
Font layout
|
en |
eng |
English |
✓
|
Latin
|
|
fr |
fra fre |
French |
✓ (missing [ÀÂÈÊËÎÏÔÙÛŸ] accents and [Œœ]) Convert: Œ→O+E, œ→o+e
|
de |
deu ger |
German |
Missing [ßẞ]
|
es |
spa |
Spanish, Castilian |
✓
|
da |
dan |
Danish |
Missing [Øø]
|
no |
nor |
Norwegian |
Missing [Øø]
|
nl |
nld dut |
Dutch |
✓
|
fi |
fin |
Finnish |
✓ (missing rare [ŠšŽž])
|
is |
isl ice |
Icelandic |
Missing [ÁÐðÍÓÚÝýÞþ]
|
ga |
gle |
Irish |
✓
|
it |
ita |
Italian |
✓
|
pl |
pol |
Polish |
Missing [ĄąĆćĘꣳŃńÓŚśŹźŻż]
|
pt |
por |
Portuguese |
✓ (missing [ÁÍÓÚÂÊÔÀÒÈÌÙÏ] accents)
|
sk |
slk slo |
Slovak |
Missing [ÁČčĎďÍĹ弾ŇňÓÔŔ੹ŤťÚÝýŽž]
|
sv |
swe |
Swedish |
✓
|
tr |
tur |
Turkish |
Missing [ĞğıİŞş]
|
ja |
jpn |
Japanese |
Missing [◯゙◯゚] and [ゐゑヰヱ] (archaic characters) Convert: ◯゙→◯+゛, ◯゚→◯+゜ |
Kana |
|
ko |
kor |
Korean |
To check... seems broken |
Hangul |
|
ar |
ara |
Arabic |
To check... reverse order |
Arabic |
|
uk |
ukr |
Ukrainian |
Missing [ҐґЄєІіЇїЙй]
|
Cyrillic
|
|
ru |
rus |
Russian |
Missing [ЁёЪ]
|
In translation entries, the key can only use alphanumeric or '_' characters.
Notes:
- The MSXgl translation file format respects the format of the .ini files, so you can benefit from syntax highlighting if you use this extension. That said, this is not mandatory and you could, for example, use a .loc extension for your localization file.
- Language code int and max are reserved and must not be used.
By adding source files to your project configuration (project_config.js; see bellow), the build tool will automatically group your source files into a header file for inclusion in your code.
You'll get warning messages if some of your translation keys exist in one language but not in another. The same applies if the same key is defined several times for the same language.
Use the module in your code
In your code, you only need 3 functions to use the location system:
- Loc_Initialize to initialize the localization module.
- Loc_SetLanguage to set the current language to use.
- Loc_GetText to get a given text translation in the current language.
For example:
// Include the generated header file
#include "my_localization.h"
// Set the root data generated by the Build tool
Loc_Initialize(g_LocData, TEXT_MAX);
// Select French language
Loc_SetLanguage(LANG_FR);
// Display the text corresponding to 'HELLO' key
Print_DrawTextAt(10, 10, Loc_GetText(TEXT_HELLO));
Samples
See module use cases in the sample programs:
Settings
The localization process can be customized in your Build tool configuration file, project_config.js.
Available options:
//-- List files to be localized (array)
LocFiles = [ "file1.ini", "file2.ini" ];
//-- Localization output filename (string)
LocOutput = "localization.h";
//-- Localization structure name (string)
LocStruct = "g_LocData";
Note: If LocFiles is empty (default value), the localization process is disabled.
Dependencies
Dependency on other modules: None
Documentation