问题
This is a part of my src/Locale/en_US/default.po file
msgid "Acg_id"
msgstr "access control group identifier"
msgid "acg_id"
msgstr "access control group identifier"
msgid "Acg_Id"
msgstr "access control group identifier"
my default.po file is too long. And I think it is impossible to write like this.
msgid "Acg_id"
msgid "acg_id"
msgid "Acg_Id"
msgstr "access control group identifier"
How can I implement function below in cakephp core
function __($token){
$translation = translation(strtolower($token));//translation returns translation of token if exists else returns null
return $translation ? $translation : $token;
}
Then my default.po file will become too shorter :) like this
msgid "acg_id"
msgstr "access control group identifier"
回答1:
While I think that case insensitive translations are kinda bad practice (why not simply use the proper message IDs?), you can easily pre-declare any of the shorthand translation functions in your apps config/bootstrap.php
, before including the autoloader.
// [...]
use Cake\I18n\I18n;
// https://github.com/cakephp/cakephp/blob/3.0.0/src/I18n/functions.php#L26
function __($token, $args = null)
{
if (!$token) {
return null;
}
$arguments = func_num_args() === 2 ? (array)$args : array_slice(func_get_args(), 1);
// side note: you may want to use mb_strtolower instead
return I18n::translator()->translate(strtolower($token), $arguments);
}
// Use composer to load the autoloader.
require ROOT . DS . 'vendor' . DS . 'autoload.php';
// [...]
来源:https://stackoverflow.com/questions/29316489/how-can-i-manipulate-translation-methods-of-cakephp-3-to-become-case-insensitive