Returns a new instance of GobstonesTranslator (a translator, for short) with the given set of options configured.
GobstonesTranslatorOptions for learning more about all the available options you can pass to the constructor.
NonExistentLocaleGiven if a name that is not a built-in supported locale, nor a user defined locale is given to any of from or to. This error also arises when a user attempts to define a locale in the locales option, that extends another locale, which itself is not defined.
LocaleNameCollision if a user provides a user defined locale in the locales option that has a name already defined (as a built-in supported locale or a user-defined locale previously defined)
The options to use to configure the translator.
Private
fromPrivate
namesA set of additional names for this translator used to translate additional words besides the built-in commands, expressions and keywords of the Gobstones Language.
names for more info.
Private
registeredA set of registered locales for this translator. This is automatically populated with the built-in supported locales, and expanded with the user defined locales given as argument to the constructor.
locales for more info on adding custom locales.
Private
toThe locale which this translator will assume as output locale when given Gobstones Abstract code. This is the destination locale used in fromTokens and as the destination locale in translate.
Private
tokenThis is the prefix attached or expected to every abstract token when reading or
writing to Gobstones Abstract code. This prefix defaults to '$'
if
none is given, as this symbol is not a valid token of the Gobstones Localized code, and
avoids unexpected collisions.
the "Caveats" section in the README for more information about collisions.
Private
tokenThis is the suffix attached or expected to every abstract token when reading or
writing to Abstract Gobstones Language code. This suffix is defaulted to '$'
, if
none is given, as this symbol is not a valid token of the Gobstones Language, and
avoids unexpected collisions.
the "Caveats" section in the README for more information about collisions.
Convert a given code containing abstract tokens to a Gobstones Language code in the to language. The input code should be a string containing Gobstones Code with abstract tokens instead of language specific code (Abstract Gobstones Code).
A string containing Gobstones Code in to.
if the translator was configured without a to option.
if the option includeNames was given, but no names option was used when creating this translator.
The Gobstones Code to translate. Assumed to be Abstract Gobstones Code.
Optional
options: TranslationOptionsA set of additional options for the conversion.
Private
fullThe map to use when performing a translation. The map to use depends on whether or not the registered names are to be included.
A new map containing all translations that are to be used.
Whether or not to include the registered names in the final map.
The base map with translations from tokens to localized Gobstones Code or vice versa to use in the translation.
Optional
namesMap: Map<string, string>Private
getRetrieve the set of entries constructed from the extension of the given language definition with the given extended language.
if a locale name that is not a built-in supported language, nor a user defined language is given to as the LocaleDefinition.extends option of the language definition.
The language definition that extends another.
The extended language name.
Private
registerRegister the given languages in this translator instance.
if a locale name that is not a built-in supported language, nor a user defined language is given to as the LocaleDefinition.extends option in any of the language definitions.
if any of the given languages has a name that has been previously defined.
An object containing language names as keys, and language definitions as their values.
Private
registerRegister a language to this instance existing languages.
if a locale name that is not a built-in supported language, nor a user defined language is given to as the LocaleDefinition.extends option of the language definition.
LocaleNameCollision if the given name has been used in a previously registered language.
The name of the language to register.
The language definition to register.
Convert a given code to a string containing abstract tokens for built-in commands and expressions and language keywords. The input code should be in the language this translator has configured as from.
A string containing Abstract Gobstones Code.
if the translator was configured without a from option.
if the option includeNames was given, but no names option was used when creating this translator.
The Gobstones Language code to translate. Assumed to be in from.
Optional
options: TranslationOptionsA set of additional options for the conversion.
Translate a given code from the source language to the destination language. The source language is the one used as from when constructing the translator, and the destination language is that used as to. The input should be Gobstones Language code in the source language.
A string containing Gobstones Code in to.
if the translator was configured without a from option.
if the translator was configured without a to option.
if the option includeNames was given, but no names option was used when creating this translator.
The Gobstones Language code to translate. Assumed to be in from.
Optional
options: TranslationOptionsA set of additional options for the conversion.
Private
translateTranslate a code string using a given set of word transformations to perform. The translation can be perform between language specific localized Gobstones Language code to Abstract Gobstones Code, the other way around, or between any to languages. The code is generic enough to just consider the elements on the given map.
The translated code using the rules in the map.
The code to translate, may be Abstract Gobstones Code or localized Gobstones Code.
The replacement map, where each key corresponds to a word to translate, and the value the corresponding translation for such a word.
The GobstonesTranslator class is in charge of translating all keywords and built-in commands and expressions from a source locale to a destination locale, as well as providing an abstract 'Tokens' intermediate output that is locale agnostic.
You can construct an instance of this class (called a translator, for short) by providing a set of GobstonesTranslatorOptions to the constructor, which are then stored in the newly created instance as it's configuration.
The configuration of a translator is private and cannot be changed once constructed.
You can the ask the translator to perform different operations, such as translating from a locale specific Gobstones Localized code to Gobstones Abstract code (see toTokens), or go the other way around (see fromTokens), or event translate between locales (see translate). The actions the translator is allowed to perform depend on the configuration given at construction time to the translator, so for example, a translator that was created without a destination language is not able to translate from one language to another (See constructor and the aforementioned operations for more information)