CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.6 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.6
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
      • Exception
      • Formatter
      • Middleware
      • Parser
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

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

Property 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.

  • $_plugin protected
    string|null

    The package (domain) plugin

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.

  • translationsFolders() public

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

Method Detail

__construct() ¶ 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 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
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

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

__invoke() ¶ public

__invoke(): Cake\I18n\Package|false

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

Returns
Cake\I18n\Package|false
Throws
RuntimeException
if no file parser class could be found for the specified file extension.

translationsFolders() ¶ public

translationsFolders(): array<string>

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

Returns
array<string>

Property Detail

$_extension ¶ protected

The extension name.

Type
string

$_locale ¶ protected

The locale to load for the given package.

Type
string

$_name ¶ protected

The package (domain) name.

Type
string

$_plugin ¶ protected

The package (domain) plugin

Type
string|null
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs