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

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -