website logo
Auteur
avatar
Nicolas2

Forum » » Road map développement » » traduction


Posté : 5 mars 2021 à 19:10 icone du post

function d'appel des translation plus courte pour le front l'admin et module
[code php]
// return les translations du front
function __($phrase, $args = null)
{
  if (! $phrase) return '';

  return translate($phrase, $args);
}

// return les translations admin
function __a($phrase, $args = null)
{
  if (! $phrase) return '';

  return adm_translate($phrase, $args);
}

// return les translation d'un module
function __m($module, $phrase, $args = null)
{
  if (! $phrase) return '';
  
  $func = $module.'_translate';
  
  return call_user_func_array($func, [$phrase, $args]);
}
[/code]
exemple pour le module geoloc : le fichier geoloc lang
[code php]
function geoloc_translate($phrase, $args) {
    //
    $params = (func_num_args() === 2) ? (array)$args : array_slice(func_get_args(), 1);

    if (is_array($params)) {
        $locale = language_iso(1,0,0);
        $phrase = \MessageFormatter::formatMessage($locale, $phrase, $params);
    }
    
    return (htmlentities($phrase,ENT_QUOTES|ENT_SUBSTITUTE|ENT_HTML401,cur_charset));
}
[/code]
l'utilisation :
[code php]
echo __m('geoloc', 'test du module geoloc pour voir, {0}', 'good');
[/code]
le rendue : test du module geoloc pour voir, good

Cet article provient de Labo NPDS 2015-2024
https://labo.infocapagde.com/viewtopic.php?topic=1480&forum=21