Localization
Inherits: Object
The server responsible for language translations.
Description
Section titled “Description”The translation server is the API backend that manages all language translations.
Translations are stored in TranslationDomains, which can be accessed by name. The most commonly used translation domain is the main translation domain. It always exists and can be accessed using an empty StringName. The translation server provides wrapper methods for accessing the main translation domain directly, without having to fetch the translation domain first. Custom translation domains are mainly for advanced usages like editor plugins. Names starting with gobu. are reserved for engine internals.
Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| bool | pseudolocalization_enabled | false |
Methods
Section titled “Methods”Property descriptions
Section titled “Property descriptions”pseudolocalization_enabled
Section titled “pseudolocalization_enabled”bool pseudolocalization_enabled = false
Setter/getter: set_pseudolocalization_enabled(), is_pseudolocalization_enabled()
If true, enables the use of pseudolocalization on the main translation domain. See ProjectSettings.internationalization/pseudolocalization/use_pseudolocalization for details.
Method descriptions
Section titled “Method descriptions”add_translation
Section titled “add_translation”void add_translation(translation: Translation)
Adds a translation to the main translation domain.
void clear()
Removes all translations from the main translation domain.
compare_locales
Section titled “compare_locales”int compare_locales(locale_a: String, locale_b: String) const
Compares two locales and returns a similarity score between 0 (no match) and 10 (full match).
find_translations
Section titled “find_translations”[]Translation find_translations(locale: String, exact: bool) const
Returns the Translation instances in the main translation domain that match locale (see compare_locales()). If exact is true, only instances whose locale exactly equals locale will be returned.
format_number
Section titled “format_number”String format_number(number: String, locale: String) const
Converts a number from Western Arabic (0..9) to the numeral system used in the given locale.
get_all_countries
Section titled “get_all_countries”[]String get_all_countries() const
Returns an array of known country codes.
get_all_languages
Section titled “get_all_languages”[]String get_all_languages() const
Returns array of known language codes.
get_all_scripts
Section titled “get_all_scripts”[]String get_all_scripts() const
Returns an array of known script codes.
get_country_name
Section titled “get_country_name”String get_country_name(country: String) const
Returns a readable country name for the country code.
get_language_name
Section titled “get_language_name”String get_language_name(language: String) const
Returns a readable language name for the language code.
get_loaded_locales
Section titled “get_loaded_locales”[]String get_loaded_locales() const
Returns an array of all loaded locales of the project.
get_locale
Section titled “get_locale”String get_locale() const
Returns the current locale of the project.
See also OS.get_locale() and OS.get_locale_language() to query the locale of the user system.
get_locale_name
Section titled “get_locale_name”String get_locale_name(locale: String) const
Returns a locale’s language and its variant (e.g. "en_US" would return "English (United States)").
get_or_add_domain
Section titled “get_or_add_domain”TranslationDomain get_or_add_domain(domain: StringName)
Returns the translation domain with the specified name. An empty translation domain will be created and added if it does not exist.
get_percent_sign
Section titled “get_percent_sign”String get_percent_sign(locale: String) const
Returns the percent sign used in the given locale.
get_plural_rules
Section titled “get_plural_rules”String get_plural_rules(locale: String) const
Returns the default plural rules for the locale.
get_script_name
Section titled “get_script_name”String get_script_name(script: String) const
Returns a readable script name for the script code.
get_tool_locale
Section titled “get_tool_locale”String get_tool_locale()
Returns the current locale of the editor.
Note: When called from an exported project returns the same value as get_locale().
get_translations
Section titled “get_translations”[]Translation get_translations() const
Returns all available Translation instances in the main translation domain as added by add_translation().
has_domain
Section titled “has_domain”bool has_domain(domain: StringName) const
Returns true if a translation domain with the specified name exists.
has_translation
Section titled “has_translation”bool has_translation(translation: Translation) const
Returns true if the main translation domain contains the given translation.
has_translation_for_locale
Section titled “has_translation_for_locale”bool has_translation_for_locale(locale: String, exact: bool) const
Returns true if there are any Translation instances in the main translation domain that match locale (see compare_locales()). If exact is true, only instances whose locale exactly equals locale are considered.
parse_number
Section titled “parse_number”String parse_number(number: String, locale: String) const
Converts number from the numeral system used in the given locale to Western Arabic (0..9).
pseudolocalize
Section titled “pseudolocalize”StringName pseudolocalize(message: StringName) const
Returns the pseudolocalized string based on the message passed in.
Note: This method always uses the main translation domain.
reload_pseudolocalization
Section titled “reload_pseudolocalization”void reload_pseudolocalization()
Reparses the pseudolocalization options and reloads the translation for the main translation domain.
remove_domain
Section titled “remove_domain”void remove_domain(domain: StringName)
Removes the translation domain with the specified name.
Note: Trying to remove the main translation domain is an error.
remove_translation
Section titled “remove_translation”void remove_translation(translation: Translation)
Removes the given translation from the main translation domain.
set_locale
Section titled “set_locale”void set_locale(locale: String)
Sets the locale of the project. The locale string will be standardized to match known locales (e.g. en-US would be matched to en_US).
If translations have been loaded beforehand for the new locale, they will be applied.
standardize_locale
Section titled “standardize_locale”String standardize_locale(locale: String, add_defaults: bool = false) const
Returns a locale string standardized to match known locales (e.g. en-US would be matched to en_US). If add_defaults is true, the locale may have a default script or country added.
translate
Section titled “translate”StringName translate(message: StringName, context: StringName = &"") const
Returns the current locale’s translation for the given message and context.
Note: This method always uses the main translation domain.
translate_plural
Section titled “translate_plural”StringName translate_plural(message: StringName, plural_message: StringName, n: int, context: StringName = &"") const
Returns the current locale’s translation for the given message, plural message and context.
The number n is the number or quantity of the plural object. It will be used to guide the translation system to fetch the correct plural form for the selected language.
Note: This method always uses the main translation domain.