Pyrogenesis  trunk
L10n.h
Go to the documentation of this file.
1 /* Copyright (c) 2017 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef L10N_H
24 #define L10N_H
25 
26 #include <string>
27 #include <vector>
28 
29 #include "lib/code_annotation.h"
32 #include "lib/file/vfs/vfs_path.h"
33 #include "ps/Singleton.h"
34 
35 #define g_L10n L10n::GetSingleton()
36 
37 /**
38  * %Singleton for internationalization and localization.
39  *
40  * @sa http://trac.wildfiregames.com/wiki/Internationalization_and_Localization
41  */
42 class L10n : public Singleton<L10n>
43 {
44  /**
45  * Marks the L10n class as ‘noncopyable’.
46  *
47  * This is required, as the class works as a singleton.
48  *
49  * @sa #NONCOPYABLE(className)
50  */
52 public:
53 
54  /**
55  * Creates an instance of L10n.
56  *
57  * L10n is a singleton. Use Instance() instead of creating you own instances
58  * of L10n.
59  */
60  L10n();
61 
62  /**
63  * Handles the descruction of L10n.
64  *
65  * Never destroy the L10n singleton manually. It must run as long as the
66  * game runs, and it is destroyed automatically when you quit the game.
67  */
68  ~L10n();
69 
70  /**
71  * Types of dates.
72  *
73  * @sa LocalizeDateTime()
74  */
75  enum DateTimeType {
76  DateTime, ///< Both date and time.
77  Date, ///< Only date.
78  Time ///< Only time.
79  };
80 
81  /**
82  * Returns the current locale.
83  *
84  * @sa GetCurrentLocaleString()
85  * @sa GetSupportedLocaleBaseNames()
86  * @sa GetAllLocales()
87  * @sa ReevaluateCurrentLocaleAndReload()
88  */
89  Locale GetCurrentLocale() const;
90 
91  /**
92  * Returns the code of the current locale.
93  *
94  * A locale code is a string such as "de" or "pt_BR".
95  *
96  * @sa GetCurrentLocale()
97  * @sa GetSupportedLocaleBaseNames()
98  * @sa GetAllLocales()
99  * @sa ReevaluateCurrentLocaleAndReload()
100  */
101  std::string GetCurrentLocaleString() const;
102 
103  /**
104  * Returns a vector of locale codes supported by ICU.
105  *
106  * A locale code is a string such as "de" or "pt_BR".
107  *
108  * @return Vector of supported locale codes.
109  *
110  * @sa GetSupportedLocaleBaseNames()
111  * @sa GetCurrentLocale()
112  *
113  * @sa http://www.icu-project.org/apiref/icu4c/classicu_1_1Locale.html#a073d70df8c9c8d119c0d42d70de24137
114  */
115  std::vector<std::string> GetAllLocales() const;
116 
117  /**
118  * Saves the specified locale in the game configuration file.
119  *
120  * The next time that the game starts, the game uses the locale in the
121  * configuration file if there are translation files available for it.
122  *
123  * SaveLocale() checks the validity of the specified locale with
124  * ValidateLocale(). If the specified locale is not valid, SaveLocale()
125  * returns @c false and does not save the locale to the configuration file.
126  *
127  * @param localeCode Locale to save to the configuration file.
128  * @return Whether the specified locale is valid (@c true) or not
129  * (@c false).
130  */
131  bool SaveLocale(const std::string& localeCode) const;
132  ///@overload SaveLocale
133  bool SaveLocale(const Locale& locale) const;
134 
135  /**
136  * Returns an array of supported locale codes sorted alphabetically.
137  *
138  * A locale code is a string such as "de" or "pt_BR".
139  *
140  * If yours is a development copy (the ‘config/dev.cfg’ file is found in the
141  * virtual filesystem), the output array may include the special “long”
142  * locale code.
143  *
144  * @return Array of supported locale codes.
145  *
146  * @sa GetSupportedLocaleDisplayNames()
147  * @sa GetAllLocales()
148  * @sa GetCurrentLocale()
149  *
150  * @sa http://trac.wildfiregames.com/wiki/Implementation_of_Internationalization_and_Localization#LongStringsLocale
151  */
152  std::vector<std::string> GetSupportedLocaleBaseNames() const;
153 
154  /**
155  * Returns an array of supported locale names sorted alphabetically by
156  * locale code.
157  *
158  * A locale code is a string such as "de" or "pt_BR".
159  *
160  * If yours is a development copy (the ‘config/dev.cfg’ file is found in the
161  * virtual filesystem), the output array may include the special “Long
162  * Strings” locale name.
163  *
164  * @return Array of supported locale codes.
165  *
166  * @sa GetSupportedLocaleBaseNames()
167  *
168  * @sa http://trac.wildfiregames.com/wiki/Implementation_of_Internationalization_and_Localization#LongStringsLocale
169  */
170  std::vector<std::wstring> GetSupportedLocaleDisplayNames() const;
171 
172  /**
173  * Returns the ISO-639 language code of the specified locale code.
174  *
175  * For example, if you specify the ‘en_US’ locate, it returns ‘en’.
176  *
177  * @param locale Locale code.
178  * @return Language code.
179  *
180  * @sa http://www.icu-project.org/apiref/icu4c/classicu_1_1Locale.html#af36d821adced72a870d921ebadd0ca93
181  */
182  std::string GetLocaleLanguage(const std::string& locale) const;
183 
184  /**
185  * Returns the programmatic code of the entire locale without keywords.
186  *
187  * @param locale Locale code.
188  * @return Locale code without keywords.
189  *
190  * @sa http://www.icu-project.org/apiref/icu4c/classicu_1_1Locale.html#a4c1acbbdf95dc15599db5f322fa4c4d0
191  */
192  std::string GetLocaleBaseName(const std::string& locale) const;
193 
194  /**
195  * Returns the ISO-3166 country code of the specified locale code.
196  *
197  * For example, if you specify the ‘en_US’ locate, it returns ‘US’.
198  *
199  * @param locale Locale code.
200  * @return Country code.
201  *
202  * @sa http://www.icu-project.org/apiref/icu4c/classicu_1_1Locale.html#ae3f1fc415c00d4f0ab33288ceadccbf9
203  */
204  std::string GetLocaleCountry(const std::string& locale) const;
205 
206  /**
207  * Returns the ISO-15924 abbreviation script code of the specified locale code.
208  *
209  * @param locale Locale code.
210  * @return Script code.
211  *
212  * @sa http://www.icu-project.org/apiref/icu4c/classicu_1_1Locale.html#a5e0145a339d30794178a1412dcc55abe
213  */
214  std::string GetLocaleScript(const std::string& locale) const;
215 
216  /**
217  * Returns @c true if the current locale is the special “Long Strings”
218  * locale. It returns @c false otherwise.
219  *
220  * @return Whether the current locale is the special “Long Strings”
221  * (@c true) or not (@c false).
222  */
223  bool UseLongStrings() const;
224 
225  /**
226  * Returns an array of paths to files in the virtual filesystem that provide
227  * translations for the specified locale code.
228  *
229  * @param locale Locale code.
230  * @return Array of paths to files in the virtual filesystem that provide
231  * translations for @p locale.
232  */
233  std::vector<std::wstring> GetDictionariesForLocale(const std::string& locale) const;
234 
235  std::wstring GetFallbackToAvailableDictLocale(const Locale& locale) const;
236 
237  std::wstring GetFallbackToAvailableDictLocale(const std::string& locale) const;
238 
239  /**
240  * Returns the code of the recommended locale for the current user that the
241  * game supports.
242  *
243  * “That the game supports” means both that a translation file is available
244  * for that locale and that the locale code is either supported by ICU or
245  * the special “long” locale code.
246  *
247  * The mechanism to select a recommended locale follows this logic:
248  * 1. First see if the game supports the specified locale,\n
249  * @p configLocale.
250  * 2. Otherwise, check the system locale and see if the game supports\n
251  * that locale.
252  * 3. Else, return the default locale, ‘en_US’.
253  *
254  * @param configLocaleString Locale to check for support first. Pass an
255  * empty string to check the system locale directly.
256  * @return Code of a locale that the game supports.
257  *
258  * @sa http://trac.wildfiregames.com/wiki/Implementation_of_Internationalization_and_Localization#LongStringsLocale
259  */
260  std::string GetDictionaryLocale(const std::string& configLocaleString) const;
261 
262  /**
263  * Saves an instance of the recommended locale for the current user that the
264  * game supports in the specified variable.
265  *
266  * “That the game supports” means both that a translation file is available
267  * for that locale and that the locale code is either supported by ICU or
268  * the special “long” locale code.
269  *
270  * The mechanism to select a recommended locale follows this logic:
271  * 1. First see if the game supports the specified locale,\n
272  * @p configLocale.
273  * 2. Otherwise, check the system locale and see if the game supports\n
274  * that locale.
275  * 3. Else, return the default locale, ‘en_US’.
276  *
277  * @param configLocaleString Locale to check for support first. Pass an
278  * empty string to check the system locale directly.
279  * @param outLocale The recommended locale.
280  *
281  * @sa http://trac.wildfiregames.com/wiki/Implementation_of_Internationalization_and_Localization#LongStringsLocale
282  */
283  void GetDictionaryLocale(const std::string& configLocaleString, Locale& outLocale) const;
284 
285  /**
286  * Determines the best, supported locale for the current user, makes it the
287  * current game locale and reloads the translations dictionary with
288  * translations for that locale.
289  *
290  * To determine the best locale, ReevaluateCurrentLocaleAndReload():
291  * 1. Checks the user game configuration.
292  * 2. If the locale is not defined there, it checks the system locale.
293  * 3. If none of those locales are supported by the game, the default\n
294  * locale, ‘en_US’, is used.
295  *
296  * @sa GetCurrentLocale()
297  */
299 
300  /**
301  * Returns @c true if the locale is supported by both ICU and the game. It
302  * returns @c false otherwise.
303  *
304  * It returns @c true if both of these conditions are true:
305  * 1. ICU has resources for that locale (which also ensures it’s a valid\n
306  * locale string).
307  * 2. Either a dictionary for language_country or for language is\n
308  * available.
309  *
310  * @param locale Locale to check.
311  * @return Whether @p locale is supported by both ICU and the game (@c true)
312  * or not (@c false).
313  */
314  bool ValidateLocale(const Locale& locale) const;
315  ///@overload ValidateLocale
316  bool ValidateLocale(const std::string& localeCode) const;
317 
318  /**
319  * Returns the translation of the specified string to the
320  * @link L10n::GetCurrentLocale() current locale@endlink.
321  *
322  * @param sourceString String to translate to the current locale.
323  * @return Translation of @p sourceString to the current locale, or
324  * @p sourceString if there is no translation available.
325  */
326  std::string Translate(const std::string& sourceString) const;
327 
328  /**
329  * Returns the translation of the specified string to the
330  * @link L10n::GetCurrentLocale() current locale@endlink in the specified
331  * context.
332  *
333  * @param context Context where the string is used. See
334  * http://www.gnu.org/software/gettext/manual/html_node/Contexts.html
335  * @param sourceString String to translate to the current locale.
336  * @return Translation of @p sourceString to the current locale in the
337  * specified @p context, or @p sourceString if there is no
338  * translation available.
339  */
340  std::string TranslateWithContext(const std::string& context, const std::string& sourceString) const;
341 
342  /**
343  * Returns the translation of the specified string to the
344  * @link L10n::GetCurrentLocale() current locale@endlink based on the
345  * specified number.
346  *
347  * @param singularSourceString String to translate to the current locale,
348  * in English’ singular form.
349  * @param pluralSourceString String to translate to the current locale, in
350  * English’ plural form.
351  * @param number Number that determines the required form of the translation
352  * (or the English string if no translation is available).
353  * @return Translation of the source string to the current locale for the
354  * specified @p number, or either @p singularSourceString (if
355  * @p number is 1) or @p pluralSourceString (if @p number is not 1)
356  * if there is no translation available.
357  */
358  std::string TranslatePlural(const std::string& singularSourceString, const std::string& pluralSourceString, int number) const;
359 
360  /**
361  * Returns the translation of the specified string to the
362  * @link L10n::GetCurrentLocale() current locale@endlink in the specified
363  * context, based on the specified number.
364  *
365  * @param context Context where the string is used. See
366  * http://www.gnu.org/software/gettext/manual/html_node/Contexts.html
367  * @param singularSourceString String to translate to the current locale,
368  * in English’ singular form.
369  * @param pluralSourceString String to translate to the current locale, in
370  * English’ plural form.
371  * @param number Number that determines the required form of the translation
372  * (or the English string if no translation is available). *
373  * @return Translation of the source string to the current locale in the
374  * specified @p context and for the specified @p number, or either
375  * @p singularSourceString (if @p number is 1) or
376  * @p pluralSourceString (if @p number is not 1) if there is no
377  * translation available.
378  */
379  std::string TranslatePluralWithContext(const std::string& context, const std::string& singularSourceString, const std::string& pluralSourceString, int number) const;
380 
381  /**
382  * Translates a text line by line to the
383  * @link L10n::GetCurrentLocale() current locale@endlink.
384  *
385  * TranslateLines() is helpful when you need to translate a plain text file
386  * after you load it.
387  *
388  * @param sourceString Text to translate to the current locale.
389  * @return Line by line translation of @p sourceString to the current
390  * locale. Some of the lines in the returned text may be in English
391  * because there was not translation available for them.
392  */
393  std::string TranslateLines(const std::string& sourceString) const;
394 
395  /**
396  * Parses the date in the input string using the specified date format, and
397  * returns the parsed date as a UNIX timestamp in milliseconds (not
398  * seconds).
399  *
400  * @param dateTimeString String containing the date to parse.
401  * @param dateTimeFormat Date format string to parse the input date, defined
402  * using ICU date formatting symbols.
403  * @param locale Locale to use when parsing the input date.
404  * @return Specified date as a UNIX timestamp in milliseconds (not seconds).
405  *
406  * @sa GetCurrentLocale()
407  *
408  * @sa http://en.wikipedia.org/wiki/Unix_time
409  * @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
410  */
411  UDate ParseDateTime(const std::string& dateTimeString, const std::string& dateTimeFormat, const Locale& locale) const;
412 
413  /**
414  * Returns the specified date using the specified date format.
415  *
416  * @param dateTime Date specified as a UNIX timestamp in milliseconds
417  * (not seconds).
418  * @param type Whether the formatted date must show both the date and the
419  * time, only the date or only the time.
420  * @param style ICU style for the formatted date.
421  * @return String containing the specified date with the specified date
422  * format.
423  *
424  * @sa http://en.wikipedia.org/wiki/Unix_time
425  * @sa http://icu-project.org/apiref/icu4c521/classicu_1_1DateFormat.html
426  */
427  std::string LocalizeDateTime(const UDate dateTime, const DateTimeType& type, const DateFormat::EStyle& style) const;
428 
429  /**
430  * Returns the specified date using the specified date format.
431  *
432  * @param milliseconds Date specified as a UNIX timestamp in milliseconds
433  * (not seconds).
434  * @param formatString Date format string defined using ICU date formatting
435  * symbols. Usually, you internationalize the format string and
436  * get it translated before you pass it to
437  * FormatMillisecondsIntoDateString().
438  * @param useLocalTimezone Boolean useful for durations
439  * @return String containing the specified date with the specified date
440  * format.
441  *
442  * @sa http://en.wikipedia.org/wiki/Unix_time
443  * @sa https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table
444  */
445  std::string FormatMillisecondsIntoDateString(const UDate milliseconds, const std::string& formatString, bool useLocalTimezone) const;
446 
447  /**
448  * Returns the specified floating-point number as a string, with the number
449  * formatted as a decimal number using the
450  * @link L10n::GetCurrentLocale() current locale@endlink.
451  *
452  * @param number Number to format.
453  * @return Decimal number formatted using the current locale.
454  */
455  std::string FormatDecimalNumberIntoString(double number) const;
456 
457  /**
458  * Returns the localized version of the specified path if there is one for
459  * the @link L10n::GetCurrentLocale() current locale@endlink.
460  *
461  * If there is no localized version of the specified path, it returns the
462  * specified path.
463  *
464  * For example, if the code of the current locale is ‘de_DE’, LocalizePath()
465  * splits the input path into folder path and file name, and checks whether
466  * the ‘<folder>/l10n/de/<file>’ file exists. If it does, it returns that
467  * path. Otherwise, it returns the input path, verbatim.
468  *
469  * This function is used for file localization (for example, image
470  * localization).
471  *
472  * @param sourcePath %Path to localize.
473  * @return Localized path if it exists, @c sourcePath otherwise.
474  *
475  * @sa http://trac.wildfiregames.com/wiki/Localization#LocalizingImages
476  */
477  VfsPath LocalizePath(const VfsPath& sourcePath) const;
478 
479  /**
480  * Loads @p path into the dictionary if it is a translation file of the
481  * @link L10n::GetCurrentLocale() current locale@endlink.
482  */
483  Status ReloadChangedFile(const VfsPath& path);
484 
485 private:
486 
487  /**
488  * Dictionary that contains the translations for the
489  * @link L10n::GetCurrentLocale() current locale@endlink and the matching
490  * English strings, including contexts and plural forms.
491  *
492  * @sa LoadDictionaryForCurrentLocale()
493  */
495 
496  /**
497  * Locale that the game is currently using.
498  *
499  * To get the current locale, use its getter: GetCurrentLocale(). You can
500  * also use GetCurrentLocaleString() to get the locale code of the current
501  * locale.
502  *
503  * To change the value of this variable:
504  * 1. Save a new locale to the game configuration file with SaveLocale().
505  * 2. Reload the translation dictionary with\n
506  * ReevaluateCurrentLocaleAndReload().
507  */
509 
510  /**
511  * Vector with the locales that the game supports.
512  *
513  * The list of available locales is calculated when the game starts. Call
514  * LoadListOfAvailableLocales() to refresh the list.
515  *
516  * @sa GetSupportedLocaleBaseNames()
517  * @sa GetSupportedLocaleDisplayNames()
518  */
519  std::vector<Locale*> availableLocales;
520 
521  /**
522  * Whether the game is using the default game locale (@c true), ‘en_US’, or
523  * not (@c false).
524  *
525  * This variable is used in the L10n implementation for performance reasons.
526  * Many localization steps can be skipped when this variable is @c true.
527  */
529 
530  /**
531  * Whether the game is using the special game locale with the longest
532  * strings of each translation (@c true) or not (@c false).
533  *
534  * @sa http://trac.wildfiregames.com/wiki/Implementation_of_Internationalization_and_Localization#LongStringsLocale
535  */
537 
538  /**
539  * Loads the translation files for the
540  * @link L10n::GetCurrentLocale() current locale@endlink.
541  *
542  * This method loads every file in the ‘l10n’ folder of the game virtual
543  * filesystem that is prefixed with the code of the current locale followed
544  * by a dot.
545  *
546  * For example, if the code of the current locale code is ‘de’,
547  * LoadDictionaryForCurrentLocale() loads the ‘l10n/de.engine.po’ and
548  * ‘l10n/de.public.po’ translation files.
549  *
550  * @sa dictionary
551  * @sa ReadPoIntoDictionary()
552  */
554 
555  /**
556  * Determines the list of locales that the game supports.
557  *
558  * LoadListOfAvailableLocales() checks the locale codes of the translation
559  * files in the ‘l10n’ folder of the virtual filesystem. If it finds a
560  * translation file prefixed with a locale code followed by a dot, it
561  * determines that the game supports that locale.
562  *
563  * @sa availableLocales
564  */
566 
567  /**
568  * Loads the specified content of a PO file into the specified dictionary.
569  *
570  * Used by LoadDictionaryForCurrentLocale() to add entries to the game
571  * translations @link dictionary.
572  *
573  * @param poContent Content of a PO file as a string.
574  * @param dictionary Dictionary where the entries from the PO file should be
575  * stored.
576  */
577  void ReadPoIntoDictionary(const std::string& poContent, tinygettext::Dictionary* dictionary) const;
578 
579  /**
580  * Creates an ICU date formatted with the specified settings.
581  *
582  * @param type Whether formatted dates must show both the date and the time,
583  * only the date or only the time.
584  * @param style ICU style to format dates by default.
585  * @param locale Locale that the date formatter should use to parse strings.
586  * It has no relevance for date formatting, only matters for date
587  * parsing.
588  * @return ICU date formatter.
589  */
590  DateFormat* CreateDateTimeInstance(const DateTimeType& type, const DateFormat::EStyle& style, const Locale& locale) const;
591 };
592 
593 #endif // L10N_H
UDate ParseDateTime(const std::string &dateTimeString, const std::string &dateTimeFormat, const Locale &locale) const
Parses the date in the input string using the specified date format, and returns the parsed date as a...
Definition: L10n.cpp:350
~L10n()
Handles the descruction of L10n.
Definition: L10n.cpp:66
std::string GetLocaleScript(const std::string &locale) const
Returns the ISO-15924 abbreviation script code of the specified locale code.
Definition: L10n.cpp:290
bool ValidateLocale(const Locale &locale) const
Returns true if the locale is supported by both ICU and the game.
Definition: L10n.cpp:107
bool useLongStrings
Whether the game is using the special game locale with the longest strings of each translation (true)...
Definition: L10n.h:536
void LoadDictionaryForCurrentLocale()
Loads the translation files for the current locale.
Definition: L10n.cpp:467
Only time.
Definition: L10n.h:78
Both date and time.
Definition: L10n.h:76
Only date.
Definition: L10n.h:77
std::vector< Locale * > availableLocales
Vector with the locales that the game supports.
Definition: L10n.h:519
Locale currentLocale
Locale that the game is currently using.
Definition: L10n.h:508
bool currentLocaleIsOriginalGameLocale
Whether the game is using the default game locale (true), ‘en_US’, or not (false).
Definition: L10n.h:528
std::string Translate(const std::string &sourceString) const
Returns the translation of the specified string to the current locale.
Definition: L10n.cpp:296
DateFormat * CreateDateTimeInstance(const DateTimeType &type, const DateFormat::EStyle &style, const Locale &locale) const
Creates an ICU date formatted with the specified settings.
Definition: L10n.cpp:545
void LoadListOfAvailableLocales()
Determines the list of locales that the game supports.
Definition: L10n.cpp:498
bool UseLongStrings() const
Returns true if the current locale is the special “Long Strings” locale.
Definition: L10n.cpp:226
L10n()
Creates an instance of L10n.
Definition: L10n.cpp:45
bool SaveLocale(const std::string &localeCode) const
Saves the specified locale in the game configuration file.
Definition: L10n.cpp:80
std::string TranslateLines(const std::string &sourceString) const
Translates a text line by line to the current locale.
Definition: L10n.cpp:334
std::string GetLocaleBaseName(const std::string &locale) const
Returns the programmatic code of the entire locale without keywords.
Definition: L10n.cpp:278
Definition: path.h:77
DateTimeType
Types of dates.
Definition: L10n.h:75
std::vector< std::wstring > GetDictionariesForLocale(const std::string &locale) const
Returns an array of paths to files in the virtual filesystem that provide translations for the specif...
Definition: L10n.cpp:115
NONCOPYABLE(L10n)
Marks the L10n class as ‘noncopyable’.
Status ReloadChangedFile(const VfsPath &path)
Loads path into the dictionary if it is a translation file of the current locale. ...
Definition: L10n.cpp:427
std::wstring GetFallbackToAvailableDictLocale(const Locale &locale) const
Definition: L10n.cpp:134
std::vector< std::string > GetSupportedLocaleBaseNames() const
Returns an array of supported locale codes sorted alphabetically.
Definition: L10n.cpp:231
std::vector< std::string > GetAllLocales() const
Returns a vector of locale codes supported by ICU.
Definition: L10n.cpp:215
i64 Status
Error handling system.
Definition: status.h:171
Locale GetCurrentLocale() const
Returns the current locale.
Definition: L10n.cpp:75
std::string GetCurrentLocaleString() const
Returns the code of the current locale.
Definition: L10n.cpp:267
void ReadPoIntoDictionary(const std::string &poContent, tinygettext::Dictionary *dictionary) const
Loads the specified content of a PO file into the specified dictionary.
Definition: L10n.cpp:532
std::string TranslatePlural(const std::string &singularSourceString, const std::string &pluralSourceString, int number) const
Returns the translation of the specified string to the current locale based on the specified number...
Definition: L10n.cpp:312
std::vector< std::wstring > GetSupportedLocaleDisplayNames() const
Returns an array of supported locale names sorted alphabetically by locale code.
Definition: L10n.cpp:243
tinygettext::Dictionary * dictionary
Dictionary that contains the translations for the current locale and the matching English strings...
Definition: L10n.h:494
A simple dictionary class that mimics gettext() behaviour.
Definition: dictionary.hpp:34
std::string FormatMillisecondsIntoDateString(const UDate milliseconds, const std::string &formatString, bool useLocalTimezone) const
Returns the specified date using the specified date format.
Definition: L10n.cpp:378
Singleton for internationalization and localization.
Definition: L10n.h:42
std::string GetLocaleCountry(const std::string &locale) const
Returns the ISO-3166 country code of the specified locale code.
Definition: L10n.cpp:284
std::string FormatDecimalNumberIntoString(double number) const
Returns the specified floating-point number as a string, with the number formatted as a decimal numbe...
Definition: L10n.cpp:404
Definition: Singleton.h:34
VfsPath LocalizePath(const VfsPath &sourcePath) const
Returns the localized version of the specified path if there is one for the current locale...
Definition: L10n.cpp:418
void ReevaluateCurrentLocaleAndReload()
Determines the best, supported locale for the current user, makes it the current game locale and relo...
Definition: L10n.cpp:193
std::string GetLocaleLanguage(const std::string &locale) const
Returns the ISO-639 language code of the specified locale code.
Definition: L10n.cpp:272
std::string GetDictionaryLocale(const std::string &configLocaleString) const
Returns the code of the recommended locale for the current user that the game supports.
Definition: L10n.cpp:163
std::string TranslateWithContext(const std::string &context, const std::string &sourceString) const
Returns the translation of the specified string to the current locale in the specified context...
Definition: L10n.cpp:304
std::string LocalizeDateTime(const UDate dateTime, const DateTimeType &type, const DateFormat::EStyle &style) const
Returns the specified date using the specified date format.
Definition: L10n.cpp:363
std::string TranslatePluralWithContext(const std::string &context, const std::string &singularSourceString, const std::string &pluralSourceString, int number) const
Returns the translation of the specified string to the current locale in the specified context...
Definition: L10n.cpp:323