Table of Contents

Class TranslationServer

The server responsible for language translations.

Inheritance
TranslationServer

Remarks

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 godot. are reserved for engine internals.

See Also

Properties

pseudolocalization_enabled

If true, enables the use of pseudolocalization on the main translation domain. See internationalization/pseudolocalization/use_pseudolocalization for details.

var pseudolocalization_enabled : bool = false

Property Value

bool

Remarks

  • void set_pseudolocalization_enabled(bool value)
  • bool is_pseudolocalization_enabled

Methods

add_translation(Translation)

Adds a translation to the main translation domain.

void add_translation(Translation translation)

Parameters

translation Translation

clear

Removes all translations from the main translation domain.

void clear

compare_locales(String, String)

Qualifiers: const

Compares two locales and returns a similarity score between 0 (no match) and 10 (full match).

int compare_locales(String locale_a, String locale_b)

Parameters

locale_a String
locale_b String

get_all_countries

Qualifiers: const

Returns an array of known country codes.

PackedStringArray get_all_countries

get_all_languages

Qualifiers: const

Returns array of known language codes.

PackedStringArray get_all_languages

get_all_scripts

Qualifiers: const

Returns an array of known script codes.

PackedStringArray get_all_scripts

get_country_name(String)

Qualifiers: const

Returns a readable country name for the country code.

String get_country_name(String country)

Parameters

country String

get_language_name(String)

Qualifiers: const

Returns a readable language name for the language code.

String get_language_name(String language)

Parameters

language String

get_loaded_locales

Qualifiers: const

Returns an array of all loaded locales of the project.

PackedStringArray get_loaded_locales

get_locale

Qualifiers: const

Returns the current locale of the project.

See also get_locale and get_locale_language to query the locale of the user system.

String get_locale

get_locale_name(String)

Qualifiers: const

Returns a locale's language and its variant (e.g. "en_US" would return "English (United States)").

String get_locale_name(String locale)

Parameters

locale String

get_or_add_domain(StringName)

Returns the translation domain with the specified name. An empty translation domain will be created and added if it does not exist.

TranslationDomain get_or_add_domain(StringName domain)

Parameters

domain StringName

get_script_name(String)

Qualifiers: const

Returns a readable script name for the script code.

String get_script_name(String script)

Parameters

script 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.

String get_tool_locale

get_translation_object(String)

Returns the Translation instance that best matches locale in the main translation domain. Returns null if there are no matches.

Translation get_translation_object(String locale)

Parameters

locale String

has_domain(StringName)

Qualifiers: const

Returns true if a translation domain with the specified name exists.

bool has_domain(StringName domain)

Parameters

domain StringName

pseudolocalize(StringName)

Qualifiers: const

Returns the pseudolocalized string based on the message passed in.

Note: This method always uses the main translation domain.

StringName pseudolocalize(StringName message)

Parameters

message StringName

reload_pseudolocalization

Reparses the pseudolocalization options and reloads the translation for the main translation domain.

void reload_pseudolocalization

remove_domain(StringName)

Removes the translation domain with the specified name.

Note: Trying to remove the main translation domain is an error.

void remove_domain(StringName domain)

Parameters

domain StringName

remove_translation(Translation)

Removes the given translation from the main translation domain.

void remove_translation(Translation translation)

Parameters

translation Translation

set_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.

void set_locale(String locale)

Parameters

locale String

standardize_locale(String, bool)

Qualifiers: 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.

String standardize_locale(String locale, bool add_defaults)

Parameters

locale String
add_defaults bool

translate(StringName, StringName)

Qualifiers: const

Returns the current locale's translation for the given message and context.

Note: This method always uses the main translation domain.

StringName translate(StringName message, StringName context)

Parameters

message StringName
context StringName

translate_plural(StringName, StringName, int, StringName)

Qualifiers: 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.

StringName translate_plural(StringName message, StringName plural_message, int n, StringName context)

Parameters

message StringName
plural_message StringName
n int
context StringName