TranslationServer

Inherits:Object

The server responsible for language translations.

Description

The translation server is the API backend that manages all language translations.

Translations are stored inTranslationDomains, 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 emptyStringName. 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 withgodot. are reserved for engine internals.

Tutorials

Properties

bool

pseudolocalization_enabled

false

Methods

void

add_translation(translation:Translation)

void

clear()

int

compare_locales(locale_a:String, locale_b:String)const

PackedStringArray

get_all_countries()const

PackedStringArray

get_all_languages()const

PackedStringArray

get_all_scripts()const

String

get_country_name(country:String)const

String

get_language_name(language:String)const

PackedStringArray

get_loaded_locales()const

String

get_locale()const

String

get_locale_name(locale:String)const

TranslationDomain

get_or_add_domain(domain:StringName)

String

get_script_name(script:String)const

String

get_tool_locale()

Translation

get_translation_object(locale:String)

bool

has_domain(domain:StringName)const

StringName

pseudolocalize(message:StringName)const

void

reload_pseudolocalization()

void

remove_domain(domain:StringName)

void

remove_translation(translation:Translation)

void

set_locale(locale:String)

String

standardize_locale(locale:String, add_defaults:bool = false)const

StringName

translate(message:StringName, context:StringName = &"")const

StringName

translate_plural(message:StringName, plural_message:StringName, n:int, context:StringName = &"")const


Property Descriptions

boolpseudolocalization_enabled =false🔗

Iftrue, enables the use of pseudolocalization on the main translation domain. SeeProjectSettings.internationalization/pseudolocalization/use_pseudolocalization for details.


Method Descriptions

voidadd_translation(translation:Translation)🔗

Adds a translation to the main translation domain.


voidclear()🔗

Removes all translations from the main translation domain.


intcompare_locales(locale_a:String, locale_b:String)const🔗

Compares two locales and returns a similarity score between0 (no match) and10 (full match).


PackedStringArrayget_all_countries()const🔗

Returns an array of known country codes.


PackedStringArrayget_all_languages()const🔗

Returns array of known language codes.


PackedStringArrayget_all_scripts()const🔗

Returns an array of known script codes.


Stringget_country_name(country:String)const🔗

Returns a readable country name for thecountry code.


Stringget_language_name(language:String)const🔗

Returns a readable language name for thelanguage code.


PackedStringArrayget_loaded_locales()const🔗

Returns an array of all loaded locales of the project.


Stringget_locale()const🔗

Returns the current locale of the project.

See alsoOS.get_locale() andOS.get_locale_language() to query the locale of the user system.


Stringget_locale_name(locale:String)const🔗

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


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


Stringget_script_name(script:String)const🔗

Returns a readable script name for thescript code.


Stringget_tool_locale()🔗

Returns the current locale of the editor.

Note: When called from an exported project returns the same value asget_locale().


Translationget_translation_object(locale:String)🔗

Returns theTranslation instance that best matcheslocale in the main translation domain. Returnsnull if there are no matches.


boolhas_domain(domain:StringName)const🔗

Returnstrue if a translation domain with the specified name exists.


StringNamepseudolocalize(message:StringName)const🔗

Returns the pseudolocalized string based on themessage passed in.

Note: This method always uses the main translation domain.


voidreload_pseudolocalization()🔗

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


voidremove_domain(domain:StringName)🔗

Removes the translation domain with the specified name.

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


voidremove_translation(translation:Translation)🔗

Removes the given translation from the main translation domain.


voidset_locale(locale:String)🔗

Sets the locale of the project. Thelocale string will be standardized to match known locales (e.g.en-US would be matched toen_US).

If translations have been loaded beforehand for the new locale, they will be applied.


Stringstandardize_locale(locale:String, add_defaults:bool = false)const🔗

Returns alocale string standardized to match known locales (e.g.en-US would be matched toen_US). Ifadd_defaults istrue, the locale may have a default script or country added.


StringNametranslate(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.


StringNametranslate_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 numbern 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.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.