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 | | }}} |
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 | | }}} |