How can I manipulate translation methods of cakephp 3 to become case insensitive? -
this part of 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 long. , think impossible write this.
msgid "acg_id" msgid "acg_id" msgid "acg_id" msgstr "access control group identifier"
how can 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 default.po file become shorter :) this
msgid "acg_id" msgstr "access control group identifier"
while think case insensitive translations kinda bad practice (why not use proper message ids?), can pre-declare of shorthand translation functions in apps config/bootstrap.php
, before including 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: may want use mb_strtolower instead return i18n::translator()->translate(strtolower($token), $arguments); } // use composer load autoloader. require root . ds . 'vendor' . ds . 'autoload.php'; // [...]
Comments
Post a Comment