Index · Object → TranslationServer

TranslationServer

The server responsible for language translations.

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

Properties

var pseudolocalization_enabled: bool = false

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

Methods

func add_translation(translation: Translation) -> void

Adds a translation to the main translation domain.

func clear() -> void

Removes all translations from the main translation domain.

func compare_locales(locale_a: String, locale_b: String) -> int

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

func find_translations(locale: String, exact: bool) -> Translation[]

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.

func format_number(number: String, locale: String) -> String

Converts a number from Western Arabic (0..9) to the numeral system used in the given locale.

func get_all_countries() -> PackedStringArray

Returns an array of known country codes.

func get_all_languages() -> PackedStringArray

Returns array of known language codes.

func get_all_scripts() -> PackedStringArray

Returns an array of known script codes.

func get_country_name(country: String) -> String

Returns a readable country name for the country code.

func get_language_name(language: String) -> String

Returns a readable language name for the language code.

func get_loaded_locales() -> PackedStringArray

Returns an array of all loaded locales of the project.

func get_locale() -> String

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.

func get_locale_name(locale: String) -> String

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

func get_or_add_domain(domain: StringName) -> TranslationDomain

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

func get_percent_sign(locale: String) -> String

Returns the percent sign used in the given locale.

func get_plural_rules(locale: String) -> String

Returns the default plural rules for the locale.

func get_script_name(script: String) -> String

Returns a readable script name for the script code.

func get_tool_locale() -> String

Returns the current locale of the editor.

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

func get_translation_object(locale: String) -> Translation

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

func get_translations() -> Translation[]

Returns all available Translation instances in the main translation domain as added by add_translation().

func has_domain(domain: StringName) -> bool

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

func has_translation(translation: Translation) -> bool

Returns true if the main translation domain contains the given translation.

func has_translation_for_locale(locale: String, exact: bool) -> bool

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.

func parse_number(number: String, locale: String) -> String

Converts number from the numeral system used in the given locale to Western Arabic (0..9).

func pseudolocalize(message: StringName) -> StringName

Returns the pseudolocalized string based on the message passed in.

Note: This method always uses the main translation domain.

func reload_pseudolocalization() -> void

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

func remove_domain(domain: StringName) -> void

Removes the translation domain with the specified name.

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

func remove_translation(translation: Translation) -> void

Removes the given translation from the main translation domain.

func set_locale(locale: String) -> void

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.

func standardize_locale(locale: String, add_defaults: bool = false) -> String

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.

func translate(message: StringName, context: StringName = &"") -> StringName

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

Note: This method always uses the main translation domain.

func translate_plural(message: StringName, plural_message: StringName, n: int, context: StringName = &"") -> StringName

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.

Inherited from Object (62)
func _get(property: StringName) -> Variant
func _get_property_list() -> Dictionary[]
func _init() -> void
func _iter_get(iter: Variant) -> Variant
func _iter_init(iter: Array) -> bool
func _iter_next(iter: Array) -> bool
func _notification(what: int) -> void
func _set(property: StringName, value: Variant) -> bool
func _to_string() -> String
func _validate_property(property: Dictionary) -> void
func add_user_signal(signal: String, arguments: Array = []) -> void
func call(method: StringName) -> Variant
func callv(method: StringName, arg_array: Array) -> Variant
func cancel_free() -> void
func connect(signal: StringName, callable: Callable, flags: int = 0) -> Error
func disconnect(signal: StringName, callable: Callable) -> void
func emit_signal(signal: StringName) -> Error
func free() -> void
func get(property: StringName) -> Variant
func get_class() -> String
func get_incoming_connections() -> Dictionary[]
func get_indexed(property_path: NodePath) -> Variant
func get_meta(name: StringName, default: Variant = null) -> Variant
func get_meta_list() -> StringName[]
func get_method_list() -> Dictionary[]
func get_property_list() -> Dictionary[]
func get_signal_connection_list(signal: StringName) -> Dictionary[]
func get_signal_list() -> Dictionary[]
func has_meta(name: StringName) -> bool
func has_method(method: StringName) -> bool
func has_signal(signal: StringName) -> bool
func is_class(class: StringName) -> bool
func is_connected(signal: StringName, callable: Callable) -> bool
func notification(what: int, reversed: bool = false) -> void
func remove_meta(name: StringName) -> void
func remove_user_signal(signal: StringName) -> void
func set(property: StringName, value: Variant) -> void
func set_block_signals(enable: bool) -> void
func set_deferred(property: StringName, value: Variant) -> void
func set_indexed(property_path: NodePath, value: Variant) -> void
func set_message_translation(enable: bool) -> void
func set_meta(name: StringName, value: Variant) -> void
func set_script(script: Variant) -> void
func set_translation_domain(domain: StringName) -> void
func to_string() -> String
func tr(message: StringName, context: StringName = &"") -> String
func tr_n(message: StringName, plural_message: StringName, n: int, context: StringName = &"") -> String

Signals

Inherited from Object (2)