MessagesFileLoader
in package
A generic translations package factory that will load translations files based on the file extension and the package name.
This class is a callable, so it can be used as a package loader argument.
Table of Contents
Properties
- $_extension : string
- The extension name.
- $_locale : string
- The locale to load for the given package.
- $_name : string
- The package (domain) name.
Methods
- __construct() : mixed
- Creates a translation file loader. The file to be loaded corresponds to the following rules:
- __invoke() : Package|false
- Loads the translation file and parses it. Returns an instance of a translations package containing the messages loaded from the file.
- translationsFolders() : array<string|int, string>
- Returns the folders where the file should be looked for according to the locale and package name.
Properties
$_extension
The extension name.
protected
string
$_extension
$_locale
The locale to load for the given package.
protected
string
$_locale
$_name
The package (domain) name.
protected
string
$_name
Methods
__construct()
Creates a translation file loader. The file to be loaded corresponds to the following rules:
public
__construct(string $name, string $locale[, string $extension = 'po' ]) : mixed
- The locale is a folder under the
Locale
directory, a fallback will be used if the folder is not found. - The $name corresponds to the file name to load
- If there is a loaded plugin with the underscored version of $name, the translation file will be loaded from such plugin.
Examples:
Load and parse resources/locales/fr/validation.po
$loader = new MessagesFileLoader('validation', 'fr_FR', 'po');
$package = $loader();
Load and parse resources/locales/fr_FR/validation.mo
$loader = new MessagesFileLoader('validation', 'fr_FR', 'mo');
$package = $loader();
Load the plugins/MyPlugin/resources/locales/fr/my_plugin.po file:
$loader = new MessagesFileLoader('my_plugin', 'fr_FR', 'mo');
$package = $loader();
Parameters
- $name : string
-
The name (domain) of the translations package.
- $locale : string
-
The locale to load, this will be mapped to a folder in the system.
- $extension : string = 'po'
-
The file extension to use. This will also be mapped to a messages parser class.
__invoke()
Loads the translation file and parses it. Returns an instance of a translations package containing the messages loaded from the file.
public
__invoke() : Package|false
Tags
Return values
Package|falsetranslationsFolders()
Returns the folders where the file should be looked for according to the locale and package name.
public
translationsFolders() : array<string|int, string>
Return values
array<string|int, string> —The list of folders where the translation file should be looked for