Translator
class Translator
Class Lang, give support to internationalization.
Traits
Constants
FALLBACK_LANG |
Default language to use if language file not exists. |
LANG_FOLDER |
Base folder where languages files are stored. |
LANG |
Default language to use. |
EXT |
Extension of language file. |
FORMAT |
Format of language file. |
Properties
static protected bool | $singletonArray | Set to true if you want use more that one singleton using and index param in getInstance | from Singleton |
static protected string | $basePath | The base path where config files are placed. | from Singleton |
static private string | $className | Name of the class | from Singleton |
static private array | $instances | Hold the classes on instance. | from Singleton |
protected bool | $separateConfigFile | Set to true if you want to save configuration in a separate file | from Singleton |
static private Translator | $translator | The Symfony translator. | |
static private array | $usedStrings | List of used strings. | |
static private array | $missingStrings | List of strings without translation. | |
static private string | $languageFolder | Main language folder. | |
static private array | $languageFolders | Array of all language folders. |
Methods
Return this instance.
Save config to file.
Return default values
Initialization, equivalent to __construct and must be called from main class.
Lang constructor.
Load the translation files following the priorities.
Return the lang folders.
Returns the base lang folder.
Add additional language folders.
Sets the language code in use.
Returns an array with the languages with available translations.
Translate the text into the default language.
Stores if translation is used and if is missing.
Returns the language code in use.
Returns the missing strings.
Returns the strings used.
Returns the original translator.
Details
at line 159
static
Translator
getInstance()
Return this instance.
in
Singleton
at line 88
static private string
getClassName()
Returns the class name.
in
Singleton
at line 103
bool
setConfig(array $params, bool $merge = true, string $index = 'main')
Save config to file.
in
Singleton
at line 130
private array
getYamlContent()
Returns the content of the Yaml file.
in
Singleton
at line 152
string
getFilePath()
Return the full file config path.
in
Singleton
at line 162
string
getFileName()
Return the file name.
in
Singleton
at line 172
static string
yamlName()
Return the classname for yaml file.
in
Singleton
at line 184
protected bool
fileExists(string $filename)
Returns if file exists.
in
Singleton
at line 196
array
getConfig(string $index = 'main')
Returns the yaml config params.
at line 169
static array
getDefaultValues()
Return default values
in
Singleton
at line 215
string
getBasePath()
Return the base path.
in
Singleton
at line 223
protected
initSingleton()
Initialization, equivalent to __construct and must be called from main class.
at line 90
__construct()
Lang constructor.
at line 112
void
loadLangFiles()
Load the translation files following the priorities.
In this case, the translator must be provided with the routes in reverse order.
at line 136
array
getLangFolders()
Return the lang folders.
at line 149
string
getBaseLangFolder()
Returns the base lang folder.
at line 179
addDirs(array $folders = [])
Add additional language folders.
at line 197
void
setlocale(string $lang)
Sets the language code in use.
at line 207
array
getAvailableLanguages()
Returns an array with the languages with available translations.
at line 235
string
trans(null|string $txt, array $parameters = [], $domain = null, $locale =
null)
Translate the text into the default language.
at line 249
private
verifyMissing(string $translated, null|string $txt, null|string $domain =
null)
Stores if translation is used and if is missing.
at line 277
string
getLocale()
Returns the language code in use.
at line 287
array
getMissingStrings()
Returns the missing strings.
at line 297
array
getUsedStrings()
Returns the strings used.
at line 307
Translator
getTranslator()
Returns the original translator.