Class MessagesFileLoader

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.

Namespace: Cake\I18n
Location: I18n/MessagesFileLoader.php

Properties summary

  • $_extension protected
    string
    The extension name.
  • $_locale protected
    string
    The locale to load for the given package.
  • $_name protected
    string
    The package (domain) name.

Method Summary

  • __construct() public

    Creates a translation file loader. The file to be loaded corresponds to the following rules:

  • __invoke() public

    Loads the translation file and parses it. Returns an instance of a translations package containing the messages loaded from the file.

  • Returns the folders where the file should be looked for according to the locale and package name.

Method Detail

__construct()source public

__construct( string $name , string $locale , string $extension 'po' )

Creates a translation file loader. The file to be loaded corresponds to the following rules:

  • 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 src/Locale/fr/validation.po

$loader = new MessagesFileLoader('validation', 'fr_FR', 'po');
$package = $loader();

Load and parse src/Locale/fr_FR/validation.mo

$loader = new MessagesFileLoader('validation', 'fr_FR', 'mo');
$package = $loader();

Load the plugins/MyPlugin/src/Locale/fr/my_plugin.po file:

$loader = new MessagesFileLoader('my_plugin', 'fr_FR', 'mo');
$package = $loader();

Parameters

string $name
The name (domain) of the translations package.
string $locale

The locale to load, this will be mapped to a folder in the system.

string $extension optional 'po'

The file extension to use. This will also be mapped to a messages parser class.

__invoke()source public

__invoke( )

Loads the translation file and parses it. Returns an instance of a translations package containing the messages loaded from the file.

Returns

Aura\Intl\Package|false

Throws

RuntimeException

if no file parser class could be found for the specified file extension.


translationsFolders()source public

translationsFolders( )

Returns the folders where the file should be looked for according to the locale and package name.

Returns

array
The list of folders where the translation file should be looked for

Properties detail

$_extensionsource

protected string

The extension name.

$_localesource

protected string

The locale to load for the given package.

$_namesource

protected string

The package (domain) name.

© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.4/class-Cake.I18n.MessagesFileLoader.html