andres-ml / cakephp-i18n
I18n plugin for CakePHP
Installs: 983
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=7.2
- cakephp/cakephp: ^5.0
Requires (Dev)
- phpunit/phpunit: ^10.1
This package is auto-updated.
Last update: 2024-10-22 09:05:21 UTC
README
Allows setting a default domain for translations.
Before:
__('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:
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.
composer require andres-ml/cakephp-i18n
Usage
Automatically load the plugin by running bin/cake plugin load Aml/I18n
Manually load the plugin in src/Application.php
bootstrap()
function by adding the following line
$this->addPlugin('Aml/I18n');
Wherever you would use __()
,
you can now use __t()
.
Wherever you would use __n()
,
you can now use __tn()
.
Wherever you would use __x()
,
you can now use __tx()
.
Wherever you would use __xn()
,
you can now use __txn()
.
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)
To automatically generate the default.pot base file:
bin/cake aml/I18n.i18n extract