Language class
Framework\Language\Language
Class Language.
Defined in libraries/language/src/Language.php
Properties #
- $currentLocale
- The current locale.
- $defaultLocale
- The default locale.
- $directories
- List of directories to find for files.
- $fallbackLevel
- The locale fallback level.
- $findedLocales
- List with locales of already scanned directories.
- $languages
- Language lines.
- $supportedLocales
- Supported locales. Any other will be ignored.
- $debugCollector
- -
$currentLocale
The current locale.
$defaultLocale
The default locale.
$directories
List of directories to find for files.
$fallbackLevel
The locale fallback level.
$findedLocales
List with locales of already scanned directories.
$languages
Language lines.
$supportedLocales
Supported locales. Any other will be ignored.
$debugCollector
Methods #
- __construct()
- Language constructor.
- addDirectory()
- -
- addLines()
- Adds custom lines for a specific locale.
- currency()
- Gets a currency value formatted in a given locale.
- date()
- Gets a formatted date in a given locale.
- formatMessage()
- -
- getCurrentLocale()
- Gets the current locale.
- getCurrentLocaleDirection()
- Gets the current locale directionality.
- getDefaultLocale()
- Gets the default locale.
- getDirectories()
- Gets the list of directories where language files can be finded.
- getFallbackLevel()
- Gets the Fallback Level.
- getLines()
- Gets the list of available locales, lines and texts.
- getLocaleDirection()
- Gets text directionality based on locale.
- getSupportedLocales()
- Gets the list of Supported Locales.
- hasLine()
- Checks if Language has a line.
- lang()
- Renders a language file line with dot notation format.
- ordinal()
- Gets an ordinal number in a given locale.
- render()
- Renders a language file line.
- resetLines()
- -
- setCurrentLocale()
- Sets the current locale.
- setDebugCollector()
- -
- setDefaultLocale()
- Sets the default locale.
- setDirectories()
- Sets a list of directories where language files can be found.
- setFallbackLevel()
- Sets the Fallback Level.
- setSupportedLocales()
- Sets a list of Supported Locales.
- addFindedLocale()
- Adds a locale to the list of already scanned directories.
- findFilenames()
- Find for absolute file paths from where language lines can be loaded.
- findLines()
- Find and add lines.
- getFallbackLine()
- Gets a text line and locale according the Fallback Level.
- getFileLines()
- -
- getLine()
- Gets a language line text.
- getRenderedLine()
- -
- isFindedLocale()
- Tells if a locale already was found in the directories.
- reindex()
- -
__construct()
Language constructor.
- string $locale - The default (and current) locale code
- array $directories - List of directory paths to find for language files
addDirectory()
- string $directory
addLines()
Adds custom lines for a specific locale.
Useful to set lines from a database or any parsed file.
NOTE: This function will always replace the old lines, as given from files.
- string $locale - The locale code
- string $file - The file name
- array $lines - An array of "line" => "text"
currency()
Gets a currency value formatted in a given locale.
- float $value - The money value
- string $currency - The Currency code. i.e. USD, BRL, JPY
- ?string $locale - A custom locale or null to use the current
date()
Gets a formatted date in a given locale.
- int $time - An Unix timestamp
- ?string $style - One of: short, medium, long or full. Leave null to use short
- ?string $locale - A custom locale or null to use the current
formatMessage()
- string $text
- array $args
- ?string $locale
getCurrentLocale()
Gets the current locale.
getCurrentLocaleDirection()
Gets the current locale directionality.
getDefaultLocale()
Gets the default locale.
getDirectories()
Gets the list of directories where language files can be finded.
getFallbackLevel()
Gets the Fallback Level.
getLines()
Gets the list of available locales, lines and texts.
getLocaleDirection()
Gets text directionality based on locale.
- string $locale - The locale code
getSupportedLocales()
Gets the list of Supported Locales.
hasLine()
Checks if Language has a line.
- string $file - The file
- string $line - The file line
- ?string $locale - A custom locale or null to use the current
lang()
Renders a language file line with dot notation format.
E.g. home.hello matches home for file and hello for line.
- string $line - The dot notation file line
- array $args - The arguments to be used in the formatted text
- ?string $locale - A custom locale or null to use the current
ordinal()
Gets an ordinal number in a given locale.
- int $number - The number to be converted to ordinal
- ?string $locale - A custom locale or null to use the current
render()
Renders a language file line.
- string $file - The file
- string $line - The file line
- array $args - The arguments to be used in the formatted text
- ?string $locale - A custom locale or null to use the current
resetLines()
setCurrentLocale()
Sets the current locale.
- string $locale - The current locale. This automatically is set as one of Supported Locales.
setDebugCollector()
- \Framework\Language\Debug\LanguageCollector $debugCollector
setDefaultLocale()
Sets the default locale.
- string $locale - The default locale. This automatically is set as one of Supported Locales.
setDirectories()
Sets a list of directories where language files can be found.
- array $directories - a list of valid directory paths
setFallbackLevel()
Sets the Fallback Level.
- \Framework\Language\FallbackLevel|int $level
setSupportedLocales()
Sets a list of Supported Locales.
NOTE: the default locale always is supported. But the current can be exclude
if this function is called after {@see Language::setCurrentLocale()}.
- array $locales - the supported locales
addFindedLocale()
Adds a locale to the list of already scanned directories.
- string $locale
findFilenames()
Find for absolute file paths from where language lines can be loaded.
- string $locale - The required locale
- string $file - The required file
findLines()
Find and add lines.
This method can be overridden to find lines in custom storage, such as
in a database table.
- string $locale
- string $file
getFallbackLine()
Gets a text line and locale according the Fallback Level.
- string $locale - The locale to get his fallback line
- string $file - The file
- string $line - The line
getFileLines()
- string $filename
getLine()
Gets a language line text.
- string $locale - The required locale
- string $file - The required file
- string $line - The required line
getRenderedLine()
- string $file
- string $line
- array $args
- ?string $locale
isFindedLocale()
Tells if a locale already was found in the directories.
- string $locale - The locale