To translate a string, call the trans function passing either the app native language, or tokens.
String starting with a period are assumed to be a token string ie '.welcome', '.welcome.footer', '.welcome.body' Other strings are assumed the base language
Tokened translations can be more effectively chunked, cached and managed directly in PHP Base language translations are stored in one big array, meaning everything is loaded into memory
Translator supports pluralization similar with Laravel, but with the count being passed in the variable array with an index of 'count'
Methods |
public static clearCache() : void Resets the cache, used by unit testing, as normally the app will not change languages for a single script, where as unit testing will. |
public static getBaseLocale() : string The base local is the native language of the app where some of the translation is stored as actual language fragments. |
public static getInstalledLanguages() : array Returns an plain array of languages that have been installed by the user.
|
public static getTranslationDirectory() : string Returns the current translation directory that should contain generated files with user strings |
public static load(string $directory, string $file) : array Loads a translation chuck from the file system for the specified directory and file.
|
public static setBaseLocale(string $baseLocale = '') : void Set the base locale. Normally called once in the primary include file for a script. |
public static setLocale(string $locale = '') : void Set the locale for the translations to return
|
public static setTranslationDirectory(string $directory = '.') : void Set the translation directory. Normally called once in the primary include file for a script. |
public static setTranslationMissing(?PHPFUI If a translation string is not found, the "missing" method will be called on this object. Great for saving missing translations for later translation. |
public static setTranslationService(?PHPFUI Sets a translation service that is passsed the string to translate and a local. The service should not provide any pluralization. |
public static trans(string $text, array $variables = []) : string Translates a string based on the current locale
|
Properties |
protected static string $baseLocale = '' |
protected static string $directory = '.' |
protected static ?PHPFUI |
protected static string $locale = '' |
protected static ?PHPFUI |
protected static ?array $nativeTranslations = NULL
|
protected static ?PHPFUI |
Methods |
protected static getKeys(array $variables) : array
|
protected static getTranslation(string $text) : string Get the correct translation, but don't pluralize or substitute |
protected static pluralize(string $text, int $count) : string Pluralize the text. Different sections are divided by the vertical bar (|) character. If you need '|' in your text use the HTML entity | $count of 0 or less will select the first section. $count higher than the last section will return the last section. Other counts will select the number section, so 1 would return the 'one' section in the string 'zero|one|two' You can use the [first,last] notation at the start of a section to specify a matching range for the section.
|
protected static processVariables(string $text, array $variables) : string Replace variables and perform pluralization if the 'count' index is defined in $variables array, then pluralization will be invoked.
|
Properties |
protected static string $baseLocale = '' |
protected static string $directory = '.' |
protected static ?PHPFUI |
protected static string $locale = '' |
protected static ?PHPFUI |
protected static ?array $nativeTranslations = NULL
|
protected static ?PHPFUI |
Methods |
public static clearCache() : void Resets the cache, used by unit testing, as normally the app will not change languages for a single script, where as unit testing will. |
public static getBaseLocale() : string The base local is the native language of the app where some of the translation is stored as actual language fragments. |
public static getInstalledLanguages() : array Returns an plain array of languages that have been installed by the user.
|
protected static getKeys(array $variables) : array
|
protected static getTranslation(string $text) : string Get the correct translation, but don't pluralize or substitute |
public static getTranslationDirectory() : string Returns the current translation directory that should contain generated files with user strings |
public static load(string $directory, string $file) : array Loads a translation chuck from the file system for the specified directory and file.
|
protected static pluralize(string $text, int $count) : string Pluralize the text. Different sections are divided by the vertical bar (|) character. If you need '|' in your text use the HTML entity | $count of 0 or less will select the first section. $count higher than the last section will return the last section. Other counts will select the number section, so 1 would return the 'one' section in the string 'zero|one|two' You can use the [first,last] notation at the start of a section to specify a matching range for the section.
|
protected static processVariables(string $text, array $variables) : string Replace variables and perform pluralization if the 'count' index is defined in $variables array, then pluralization will be invoked.
|
public static setBaseLocale(string $baseLocale = '') : void Set the base locale. Normally called once in the primary include file for a script. |
public static setLocale(string $locale = '') : void Set the locale for the translations to return
|
public static setTranslationDirectory(string $directory = '.') : void Set the translation directory. Normally called once in the primary include file for a script. |
public static setTranslationMissing(?PHPFUI If a translation string is not found, the "missing" method will be called on this object. Great for saving missing translations for later translation. |
public static setTranslationService(?PHPFUI Sets a translation service that is passsed the string to translate and a local. The service should not provide any pluralization. |
public static trans(string $text, array $variables = []) : string Translates a string based on the current locale
|