I18n plugin for CakePHP
Allows setting a default domain for translations., (*1)
Before:, (*2)
__('members'); // outputs members
__d('hospitals', 'members'); // outputs patients
__n('Record', 'Records', 2); // outputs Record or Records
__dn('hospitals', 'Record', 'Records', 2); // outputs Visit or Visits
__x('written communication', 'He read the first letter'); // Adds additional context for use during translation
__dx('hospitals', 'eye chart viewing', 'He read the first letter'); // Adds additional context for use during translation
__xn('character', 'Spy', 'Spies', 2); // Adds additional context for use during translation
__dxn('hospitals', 'to see', 'Spy', 'Spies', 2); // Adds additional context for use during translation
With plugin:, (*3)
use Aml\I18n\I18n;
__('members'); // outputs members
__t('members'); // outputs members
__n('Record', 'Records', 2); // outputs Records
__tn('Record', 'Records', 1); // outputs Record
I18n::domain('hospitals');
__('members'); // still outputs members
__t('members'); // outputs patients
__n('Record', 'Records', 2); // outputs Visits
__tn('Record', 'Records', 1); // outputs Visit
Installation
You can install this plugin into your CakePHP application using composer., (*4)
composer require andres-ml/cakephp-i18n
Usage
Automatically load the plugin by running bin/cake plugin load Aml/I18n
, (*5)
Manually load the plugin in src/Application.php
bootstrap()
function by adding the following line, (*6)
$this->addPlugin('Aml/I18n');
Wherever you would use __()
,
you can now use __t()
., (*7)
Wherever you would use __n()
,
you can now use __tn()
., (*8)
Wherever you would use __x()
,
you can now use __tx()
., (*9)
Wherever you would use __xn()
,
you can now use __txn()
., (*10)
Remember to create a domain.po file next to each default.po file for each domain you want to support. (https://book.cakephp.org/4.0/en/core-libraries/internationalization-and-localization.html#language-files), (*11)
To automatically generate the default.pot base file:, (*12)
bin/cake aml/I18n.i18n extract