Esempio n. 1
0
 function _NL($msgid, $plural, $n, $locale)
 {
     return TextDomain::lookup()->getTranslation($locale)->ngettext($msgid, $plural, is_numeric($n) ? $n : 1);
 }
Esempio n. 2
0
 /**
  * Function: translate
  *
  * Convenience function to setup translation functions for other
  * domains. This is of greatest benefit for plugins. This will return
  * two functions to perform the translations. The first will translate a
  * single string, the second will translate a plural string.
  *
  * Parameters:
  * $domain - (string) text domain. The location of the MO.php file
  *      will be (path)/LC_MESSAGES/(locale)/(domain).mo.php. The (path)
  *      can be set via the $options parameter
  * $options - (array<string:mixed>) Extra options for the setup
  *      "path" - (string) path to the folder containing the LC_MESSAGES
  *          folder. The (locale) setting is set externally respective to
  *          the user. If this is not set, the directory of the caller is
  *          assumed, plus '/i18n'.  This is geared for plugins to be
  *          built with i18n content inside the '/i18n/' folder.
  *
  * Returns:
  * Translation utility functions which mimic the __() and _N()
  * functions. Note that two functions are returned. Capture them with a
  * PHP list() construct.
  *
  * Caveats:
  * When desiging plugins which might be installed in versions of
  * osTicket which don't provide this function, use this compatibility
  * interface:
  *
  * // Provide compatibility function for versions of osTicket prior to
  * // translation support (v1.9.4)
  * function translate($domain) {
  *     if (!method_exists('Plugin', 'translate')) {
  *         return array(
  *             function($x) { return $x; },
  *             function($x, $y, $n) { return $n != 1 ? $y : $x; },
  *         );
  *     }
  *     return Plugin::translate($domain);
  * }
  */
 static function translate($domain, $options = array())
 {
     // Configure the path for the domain. If no
     $path = @$options['path'];
     if (!$path) {
         # Fetch the working path of the caller
         $bt = debug_backtrace(false);
         $path = dirname($bt[0]["file"]) . '/i18n';
     }
     $path = rtrim($path, '/') . '/';
     $D = TextDomain::lookup($domain);
     $D->setPath($path);
     $trans = $D->getTranslation();
     return array(function ($msgid) use($trans) {
         return $trans->translate($msgid);
     }, function ($singular, $plural, $n) use($trans) {
         return $trans->ngettext($singular, $plural, $n);
     });
 }
Esempio n. 3
0
function _dcnpgettext($domain, $context, $singular, $plural, $category, $n)
{
    return TextDomain::lookup($domain)->getTranslation($category)->npgettext($context, $singular, $plural, $n);
}