Changes between Version 10 and Version 11 of Implementation_of_Internationalization_and_Localization


Ignore:
Timestamp:
Apr 26, 2014, 6:59:14 PM (10 years ago)
Author:
Adrián Chaves
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Implementation_of_Internationalization_and_Localization

    v10 v11  
    3434
    3535=== Localization Functions ===
    36 The `L10n` singleton provides many localization functions that you can use from C++, some of which are also published to be used in JavaScript.
     36The `L10n` singleton provides many localization functions that you can use from C++, some of which are also published to be used in JavaScript:
    3737
    38 Translation functions ([wiki:Internationalization] explains how to use them):
     38 * [http://svn.wildfiregames.com/docs/classL10n-members.html L10n members]
    3939
    40 {{{
    41 std::string Translate(const std::string& sourceString);
    42 std::string TranslateWithContext(const std::string& context, const std::string& sourceString);
    43 std::string TranslatePlural(const std::string& singularSourceString, const std::string& pluralSourceString, int number);
    44 std::string TranslatePluralWithContext(const std::string& context, const std::string& singularSourceString, const std::string& pluralSourceString, int number);
    45 std::string TranslateLines(const std::string& sourceString);
    46 }}}
    47 Date and time functions:
    48 
    49 {{{
    50 // parseDateTime() and localizeDateTime() are used to convert dates from strings
    51 // into icu::UDate and the other way around. These are used in
    52 // “gui/scripting/ScriptFunctions.cpp”.
    53 UDate ParseDateTime(const std::string& dateTimeString, const std::string& dateTimeFormat, const Locale& locale);
    54 std::string LocalizeDateTime(const UDate& dateTime, DateTimeType type, DateFormat::EStyle style);
    55 
    56 // Converts a string from UNIX timestamp (in milliseconds, not seconds) into a
    57 // string with the specified format. See the ‘Internationalization’ page in the
    58 // documentation for more information.
    59 std::string FormatMillisecondsIntoDateString(int milliseconds, const std::string& formatString);
    60 }}}
    61 Number functions:
    62 
    63 {{{
    64 // Returns the specified floating-point number as a string using the current
    65 // locale.
    66 std::string FormatDecimalNumberIntoString(double number);
    67 }}}
    68 Path functions:
    69 
    70 {{{
    71 // Returns the localized version of the specified path if there is one.
    72 // Otherwise, it returns sourcePath.
    73 // This is used for image localization (see below).
    74 VfsPath LocalizePath(VfsPath sourcePath);
    75 }}}
    7640== GUI ==
    7741=== Text ===
     
    8953
    9054== Functions Published for JavaScript ==
    91 '''TODO''': Link to svn.wildfiregames.com/docs when #67 gets committed.
    9255
    93 The `source/i18n/scripting/JSInterface_L10n.cpp` file publishes some of the functions that the `L10n` singleton offers, as well as some custom internationalization functions based on the `L10n` functionality.
     56The `source/i18n/scripting/JSI_L10n.cpp` file publishes some of the functions that the `L10n` singleton offers, as well as some custom internationalization functions based on the `L10n` functionality.
    9457
    95 The following functions from `L10n` are published:
     58 * [http://svn.wildfiregames.com/docs/namespaceJSI__L10n.html JSI_L10n functions]
    9659
    97 {{{
    98 scriptInterface.RegisterFunction<std::string, &GetCurrentLocale>("GetCurrentLocale");
    99 scriptInterface.RegisterFunction<void, std::string, &SetLocale>("SetLocale");
    100 
    101 scriptInterface.RegisterFunction<std::vector<std::string>, &GetSupportedLocaleCodes>("GetSupportedLocaleCodes");
    102 scriptInterface.RegisterFunction<std::vector<std::wstring>, &GetSupportedLocaleDisplayNames>("GetSupportedLocaleDisplayNames");
    103 scriptInterface.RegisterFunction<int, &GetCurrentLocaleIndex>("GetCurrentLocaleIndex");
    104 
    105 scriptInterface.RegisterFunction<std::wstring, std::wstring, &Translate>("Translate");
    106 scriptInterface.RegisterFunction<std::wstring, std::string, std::wstring, &TranslateWithContext>("TranslateWithContext");
    107 scriptInterface.RegisterFunction<std::wstring, std::wstring, std::wstring, int, &TranslatePlural>("TranslatePlural");
    108 scriptInterface.RegisterFunction<std::wstring, std::string, std::wstring, std::wstring, int, &TranslatePluralWithContext>("TranslatePluralWithContext");
    109 scriptInterface.RegisterFunction<std::wstring, std::wstring, &TranslateLines>("TranslateLines");
    110 
    111 scriptInterface.RegisterFunction<std::wstring, int, std::wstring, &FormatMillisecondsIntoDateString>("FormatMillisecondsIntoDateString");
    112 
    113 scriptInterface.RegisterFunction<std::wstring, double, &FormatDecimalNumberIntoString>("FormatDecimalNumberIntoString");
    114 }}}
    115 The following custom functions are also published:
    116 
    117 {{{
    118 // Returns the build time of the game formatted for the current locale.
    119 scriptInterface.RegisterFunction<std::wstring, int, &GetBuildTimestamp>("GetBuildTimestamp"); // in source/gui/scripting/ScriptFunctions.cpp
    120 
    121 // Translates an array of strings, avoiding what would otherwise be many calls
    122 // to the C++ engine from JavaScript.
    123 scriptInterface.RegisterFunction<std::vector<std::wstring>, std::vector<std::wstring>, &TranslateArray>("TranslateArray");
    124 
    125 // Simply returns the string that it receives. This function is required to mark
    126 // some strings from translation in places where they should not be translated
    127 // yet, so that translate() cannot be used. The point of this function is that
    128 // strings passed to it are catched by the message extraction system (see
    129 // below). For more information, see:
    130 // http://www.gnu.org/software/gettext/manual/html_node/Special-cases.html
    131 scriptInterface.RegisterFunction<std::wstring, std::wstring, &MarkToTranslate>("MarkToTranslate");
    132 }}}
    13360== JavaScript-Side Implementation ==
    13461The following sections describe some implementation details that are specific to the JavaScript side.