TranslationServer

继承: Object

The server responsible for language translations.

描述

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

Translations are stored in TranslationDomain s, 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.

属性

方法


属性说明

bool pseudolocalization_enabled = false

  • void set_pseudolocalization_enabled ( value: bool )
  • bool is_pseudolocalization_enabled ( )

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


方法说明

void add_translation ( translation: Translation )

Adds a translation to the main translation domain.


void clear ( )

Removes all translations from the main translation domain.


int compare_locales ( locale_a: String, locale_b: String ) const1

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


PackedStringArray get_all_countries ( ) const1

Returns an array of known country codes.


PackedStringArray get_all_languages ( ) const1

Returns array of known language codes.


PackedStringArray get_all_scripts ( ) const1

Returns an array of known script codes.


String get_country_name ( country: String ) const1

Returns a readable country name for the country code.


String get_language_name ( language: String ) const1

Returns a readable language name for the language code.


PackedStringArray get_loaded_locales ( ) const1

Returns an array of all loaded locales of the project.


String get_locale ( ) const1

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.


String get_locale_name ( locale: String ) const1

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


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.


String get_script_name ( script: String ) const1

Returns a readable script name for the script code.


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.


Translation get_translation_object ( locale: String )

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


bool has_domain ( domain: StringName ) const1

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


StringName pseudolocalize ( message: StringName ) const1

Returns the pseudolocalized string based on the message passed in.

Note: This method always uses the main translation domain.


void reload_pseudolocalization ( )

Reparses the pseudolocalization options and reloads the translation for the main translation 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.


void remove_translation ( translation: Translation )

Removes the given translation from the main translation domain.


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.


String standardize_locale ( locale: String ) const1

Returns a locale string standardized to match known locales (e.g. en-US would be matched to en_US).


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

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

Note: This method always uses the main translation domain.


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

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.

2

本方法通常需要用户覆盖才能生效。

1

本方法无副作用,不会修改该实例的任何成员变量。

3

本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。

4

本方法用于构造某个类型。

5

调用本方法无需实例,可直接使用类名进行调用。

6

本方法描述的是使用本类型作为左操作数的有效运算符。

7

这个值是由下列位标志构成位掩码的整数。

8

无返回值。