Changes between Version 11 and Version 12 of Internationalization


Ignore:
Timestamp:
Apr 13, 2014, 10:08:30 PM (10 years ago)
Author:
Adrián Chaves
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Internationalization

    v11 v12  
    55To internationalize a caption or tooltip (or any other XML attribute) of a GUI XML `object` element, remove the attribute from the `object` element that contains it, and add a new `translatableAttribute` element within the `object` element that used to contain the old attribute, with the name of the old attribute as the value of the `id` attribute of this new element, and the value of the old attribute as the content of this new element.
    66
    7   '''   Note:'''    Use "caption" as id of translatableAttribute to translate the caption of an object element.
     7  '''    Note:'''     Use "caption" as id of translatableAttribute to translate the caption of an object element.
    88
    99'''Original:'''
     
    1212<object type="button" tooltip="Adjust game settings.">Options</object>
    1313}}}
    14 
    1514'''Internationalized:'''
    1615
     
    2120</object>
    2221}}}
    23 
    2422== Internationalizing Captions By Parts ==
    2523You might need to internationalize only parts of a caption. This is the case when, for translators’ sake, you want to mark each paragraph of a multiline caption for translation, or when you want to strip out formatting content (such as "[font]" tags) from the translatable content.
     
    3634</object>
    3735}}}
    38 
    3936'''Internationalized:'''
    4037
     
    4845</object>
    4946}}}
    50 
    5147== Internationalizing !JavaScript Code Within GUI Files ==
    5248Simply put: '''you cannot'''.
     
    5955
    6056XML file:
     57
    6158{{{
    6259<action on="Load">
     
    6461</action>
    6562}}}
    66 
    6763'''Wrong:'''
    6864
    6965XML file:
     66
    7067{{{
    7168<action on="Load">
     
    7370</action>
    7471}}}
    75 
    7672'''Internationalized:'''
    7773
    7874XML file:
     75
    7976{{{
    8077<action on="Load">
     
    8279</action>
    8380}}}
     81!JavaScript file included by the GUI file:
    8482
    85 !JavaScript file included by the GUI file:
    8683{{{
    8784function getBuildTimeString()
     
    9087}
    9188}}}
    92 
    9389= Internationalizing !JavaScript Files =
    9490== Internationalizing Strings in !JavaScript ==
     
    123119
    124120=== Using String Formatting Instead of Concatenating Strings in !JavaScript ===
    125 
    126121You should '''never''' concatenate translatable strings, as the position of each member of the concatenation may change in other languages. Instead, use the `sprintf` global function for string formatting:
    127122
     
    132127progressCaption = "Uploading… (" + Math.floor(100*done) + "%)";
    133128}}}
    134 
    135129'''Internationalized:'''
    136130
     
    139133progressCaption = sprintf(translate("Uploading… (%f%%)"), Math.floor(100*done));
    140134}}}
    141 
    142135== Formatting Dates in JavaScript ==
    143 
    144136Given a date in [http://en.wikipedia.org/wiki/Unix_time UNIX time], you can format the date using the following engine function:
    145137
     
    147139dateString = Engine.formatMillisecondsIntoDateString(unixTime*1000, translate("yyyy-MM-dd HH:mm:ss"));
    148140}}}
    149 
    150141You can modify the format string (second parameter) as you wish, using any [https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table ICU date formatting symbols].
    151142
     
    153144Internationalizing strings from data files that are loaded by !JavaScript files is a two-step process. You must:
    154145
    155  1. Configure the [wiki:Implementation_of_Internationalization_and_Localization#MessageExtractionSystem message extraction system] to extract the translatable strings from the data file.
     146 1. Configure the [wiki:Implementation_of_Internationalization_and_Localization#MessageExtraction message extraction system] to extract the translatable strings from the data file.
    156147 1. Use an internationalization function on the !JavaScript side after you load the data file.
    157148
     
    165156   * Strings from JSON data defined within an XML element.
    166157
    167 To configure the message extraction system to extract strings from a new data file, you must edit the `l10n/messages.json` file of the mod folder. In the `messages.json` file of the main mod, `public`, you can find examples of all the supported types of data extraction. For more information, see the [wiki:Implementation_of_Internationalization_and_Localization#MessageExtractionSystem message extraction system documentation.]
     158To configure the message extraction system to extract strings from a new data file, you must edit the `l10n/messages.json` file of the mod folder. In the `messages.json` file of the main mod, `public`, you can find examples of all the supported types of data extraction. For more information, see the [wiki:Implementation_of_Internationalization_and_Localization#MessageExtraction message extraction system documentation.]
    168159
    169160== Internationalizing Content that !JavaScript Files Load from Data Files ==
     
    177168fileContent = Engine.translateLines(Engine.ReadFile(pathToFile));
    178169}}}
    179 
    180170If the !JavaScript file obtains the data as an object, you can use the `translateObjectKeys()` global function instead, which expects the object with the data and an array with the names of the object properties that must be translated. For example, from the game code:
    181171