Jet\Translator

This class (and especially its alias Jet\Tr) is the main facade of the translator system. Thus, it is the class that you will primarily use in your application. More specifically, its static methods.

Overview of methods

Method Meaning of
public static setBackend(
Translator_Backend $backend
): void
Sets the backend instance to the compiler. You only need to use this method if you decide to implement your own backend and not use the default one, and it will not be sufficient to change the class name of the default backend via the factory.
In this case, you would need to give the compiler an instance of your backend in the application initialization before the compiler starts: Translator::setBackend( new MySuperCoolTranslatorBackend() );
public static getBackend(
): Translator_Backend
Returns an instance of backend. If you have not inserted an instance of your own backend, it will create an instance of the default backend at the first opportunity.
public static setCurrentDictionary(
string $current_dictionary
): void
Sets the current translator dictionary.
public static setCurrentDictionaryTemporary(
string $current_dictionary,
callable $action
): mixed
Sets the current translator dictionary only to perform a specific action. Returns the dictionary to its original settings after the action is performed. Returns the eventual return value of the action.
public static getCurrentDictionary(
): string
Returns the name of the current compiler dictionary.
public static setCurrentLocale(
Locale $current_locale
): void
It sets the current localization of the compiler.

The question arises why the compiler has its own localization settings and does not rely on the general localization of the Locale class.
The reason is simple. Theoretically, there may be a situation where you need to format dates and numbers, for example, in a different locale than the one that is supposed to translate the text. It's unlikely, but it's possible, and avoiding it could be a bug. This is why the translator has its settings for the current localization.
public static getCurrentLocale(
): Locale
Returns the current localization of the compiler. See the setCurrentLocale method.
public static getTranslation(
string $phrase,
array $data = [],
string|null $dictionary = null,
Locale|null $locale = null
): string
Returns the translation of the phrase and adds the data ($data parameter) to the positions according to the keys in the resulting text. See general information about the translator.

If the phrase is not translated, it will return the original form of the phrase (also padded with data).

The $dictionary and $locale parameters can be used to translate according to a specific dictionary and locale regardless of the current settings.
public static _(
string $text,
array $data = [],
string|null $dictionary = null,
Locale|null $locale = null
) : string
Alias of the getTranslation method used for short notation of a frequently used call.
public static saveUpdatedDictionaries(
): void
This method is not commonly used from the application space ( although it is possible ).

It is used to store the updated dictionary (supplemented with newly used phrases) and is registered as a shutdown function. So it only runs when the application completely stops running.

And of course, it only saves really changed dictionaries - so it does practically nothing on a debugged, tested and localized application.

It is only registered when saving new phrases is enabled by setting SysConf_Jet_Translator::getAutoAppendUnknownPhrase() - which should be disabled on a production environment!
public static loadDictionary(
string $dictionary,
Locale $locale,
bool $force_load = false
): Translator_Dictionary
Loads the given dictionary in the given locale. If the dictionary does not exist yet, then it will create it.

If $force_load = true, then it will reload the dictionary even if it has already been loaded once.
public static installApplicationModuleDictionaries(
Application_Module_Manifest $module
): void
This method installs the dictionaries that the application module carries in its installation directory.
public static collectApplicationModuleDictionaries(
Application_Module_Manifest $module
): void
This method collect the current dictionaries belonging to the application module from the system and copies them to its installation directory.
public static uninstallApplicationModuleDictionaries(
Application_Module_Manifest $module
): void
This method uninstalls (deletes) dictionaries belonging to application module from the system.
Previous chapter
Translator
Next chapter
Jet\Translator_Backend