Table of Contents

Class TranslationServerInstance

Namespace
Godot
Assembly
GodotSharp.dll

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.

[GodotClassName("TranslationServer")]
public class TranslationServerInstance : GodotObject, IDisposable
Inheritance
TranslationServerInstance
Implements
Inherited Members

Properties

PseudolocalizationEnabled

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

public bool PseudolocalizationEnabled { get; set; }

Property Value

bool

Methods

AddTranslation(Translation)

Adds a translation to the main translation domain.

public void AddTranslation(Translation translation)

Parameters

translation Translation

Clear()

Removes all translations from the main translation domain.

public void Clear()

CompareLocales(string, string)

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

public int CompareLocales(string localeA, string localeB)

Parameters

localeA string
localeB string

Returns

int

GetAllCountries()

Returns an array of known country codes.

public string[] GetAllCountries()

Returns

string[]

GetAllLanguages()

Returns array of known language codes.

public string[] GetAllLanguages()

Returns

string[]

GetAllScripts()

Returns an array of known script codes.

public string[] GetAllScripts()

Returns

string[]

GetCountryName(string)

Returns a readable country name for the country code.

public string GetCountryName(string country)

Parameters

country string

Returns

string

GetLanguageName(string)

Returns a readable language name for the language code.

public string GetLanguageName(string language)

Parameters

language string

Returns

string

GetLoadedLocales()

Returns an array of all loaded locales of the project.

public string[] GetLoadedLocales()

Returns

string[]

GetLocale()

Returns the current locale of the project.

See also GetLocale() and GetLocaleLanguage() to query the locale of the user system.

public string GetLocale()

Returns

string

GetLocaleName(string)

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

public string GetLocaleName(string locale)

Parameters

locale string

Returns

string

GetOrAddDomain(StringName)

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

public TranslationDomain GetOrAddDomain(StringName domain)

Parameters

domain StringName

Returns

TranslationDomain

GetScriptName(string)

Returns a readable script name for the script code.

public string GetScriptName(string script)

Parameters

script string

Returns

string

GetToolLocale()

Returns the current locale of the editor.

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

public string GetToolLocale()

Returns

string

GetTranslationObject(string)

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

public Translation GetTranslationObject(string locale)

Parameters

locale string

Returns

Translation

HasDomain(StringName)

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

public bool HasDomain(StringName domain)

Parameters

domain StringName

Returns

bool

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

Pseudolocalize(StringName)

Returns the pseudolocalized string based on the message passed in.

Note: This method always uses the main translation domain.

public StringName Pseudolocalize(StringName message)

Parameters

message StringName

Returns

StringName

ReloadPseudolocalization()

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

public void ReloadPseudolocalization()

RemoveDomain(StringName)

Removes the translation domain with the specified name.

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

public void RemoveDomain(StringName domain)

Parameters

domain StringName

RemoveTranslation(Translation)

Removes the given translation from the main translation domain.

public void RemoveTranslation(Translation translation)

Parameters

translation Translation

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

public void SetLocale(string locale)

Parameters

locale string

StandardizeLocale(string, bool)

Returns a locale string standardized to match known locales (e.g. en-US would be matched to en_US). If addDefaults is true, the locale may have a default script or country added.

public string StandardizeLocale(string locale, bool addDefaults = false)

Parameters

locale string
addDefaults bool

Returns

string

Translate(StringName, StringName)

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

Note: This method always uses the main translation domain.

public StringName Translate(StringName message, StringName context = null)

Parameters

message StringName
context StringName

Returns

StringName

TranslatePlural(StringName, StringName, int, 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.

public StringName TranslatePlural(StringName message, StringName pluralMessage, int n, StringName context = null)

Parameters

message StringName
pluralMessage StringName
n int
context StringName

Returns

StringName