gettext, how to handle homonyms?

后端 未结 4 1137
悲&欢浪女
悲&欢浪女 2021-02-20 11:36

Using gettext

Single value

echo gettext( \"Hello, world!\\n\" );

Plurals

printf(ngett         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-02-20 12:06

    For the ones using Poedit like me you need to following. First create the function. I'm using one named _x like the one WordPress use:

    if (!function_exists('_x')) {
    
    function _x($string, $context)
    {
      $contextString = "{$context}\004{$string}";
      $translation = _($contextString);
      if ($translation == $contextString)  
         return $string;
      return $translation;
    }
    }
    

    Then on poedit you need to enter the following on Sources Keywords tab:

    _x:1,2c
    _
    

    So when you need to use context translation you use _x function. Eg:

    I took all the info from these links:

    • Gettext to work with context (pgettext)
    • http://www.cssigniter.com/ignite/wordpress-poedit-translation-secrets/

提交回复
热议问题