TranslationServer

package
v0.0.0-...-535787f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

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

Translations are stored in [graphics.gd/classdb/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 string. 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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTranslation

func AddTranslation(translation Translation.Instance)

Adds a translation to the main translation domain.

func Advanced

func Advanced() class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

func Clear

func Clear()

Removes all translations from the main translation domain.

func CompareLocales

func CompareLocales(locale_a string, locale_b string) int

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

func GetAllCountries

func GetAllCountries() []string

Returns an array of known country codes.

func GetAllLanguages

func GetAllLanguages() []string

Returns array of known language codes.

func GetAllScripts

func GetAllScripts() []string

Returns an array of known script codes.

func GetCountryName

func GetCountryName(country string) string

Returns a readable country name for the 'country' code.

func GetLanguageName

func GetLanguageName(language string) string

Returns a readable language name for the 'language' code.

func GetLoadedLocales

func GetLoadedLocales() []string

Returns an array of all loaded locales of the project.

func GetLocale

func GetLocale() string

Returns the current locale of the project.

See also graphics.gd/classdb/OS.GetLocale and graphics.gd/classdb/OS.GetLocaleLanguage to query the locale of the user system.

func GetLocaleName

func GetLocaleName(locale string) string

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

func GetOrAddDomain

func GetOrAddDomain(domain string) TranslationDomain.Instance

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

func GetScriptName

func GetScriptName(script string) string

Returns a readable script name for the 'script' code.

func GetToolLocale

func GetToolLocale() string

Returns the current locale of the editor.

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

func GetTranslationObject

func GetTranslationObject(locale string) Translation.Instance

Returns the graphics.gd/classdb/Translation instance that best matches 'locale' in the main translation domain. Returns null if there are no matches.

func HasDomain

func HasDomain(domain string) bool

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

func PseudolocalizationEnabled

func PseudolocalizationEnabled() bool

func Pseudolocalize

func Pseudolocalize(message string) string

Returns the pseudolocalized string based on the 'message' passed in.

Note: This method always uses the main translation domain.

func ReloadPseudolocalization

func ReloadPseudolocalization()

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

func RemoveDomain

func RemoveDomain(domain string)

Removes the translation domain with the specified name.

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

func RemoveTranslation

func RemoveTranslation(translation Translation.Instance)

Removes the given translation from the main translation domain.

func SetLocale

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

func SetPseudolocalizationEnabled

func SetPseudolocalizationEnabled(value bool)

func StandardizeLocale

func StandardizeLocale(locale string, add_defaults bool) 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 StandardizeLocaleOptions

func StandardizeLocaleOptions(locale string, add_defaults bool) 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

func Translate(message string, context string) string

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

Note: This method always uses the main translation domain.

func TranslateOptions

func TranslateOptions(message string, context string) string

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

Note: This method always uses the main translation domain.

func TranslatePlural

func TranslatePlural(message string, plural_message string, n int, context string) string

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.

func TranslatePluralOptions

func TranslatePluralOptions(message string, plural_message string, n int, context string) string

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.

Types

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.TranslationServer

Instance of the class with convieniently typed arguments and results.

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL