Example #1
0
File: page.php Project: rizzel/dns
 function pgettext($context, $msgId)
 {
     $contextString = "{$context}{$msgId}";
     $translation = dcgettext(textdomain(NULL), $contextString, LC_MESSAGES);
     if ($translation == $contextString) {
         return $msgId;
     } else {
         return $translation;
     }
 }
Example #2
0
 /**
  * Context-aware dgettext wrapper; use when messages in different contexts
  * won't be distinguished from the English source but need different translations.
  * The context string will appear as msgctxt in the .po files.
  *
  * Not currently exposed in PHP's gettext module; implemented to be compat
  * with gettext.h's macros.
  *
  * @param string $domain domain identifier, or null for default domain
  * @param string $context context identifier, should be some key like "menu|file"
  * @param string $msgid English source text
  * @return string original or translated message
  */
 function dpgettext($domain, $context, $msg)
 {
     $msgid = $context . "" . $msg;
     $out = dcgettext($domain, $msgid, LC_MESSAGES);
     if ($out == $msgid) {
         return $msg;
     } else {
         return $out;
     }
 }
Example #3
0
function dcpgettext($domain, $msg_ctxt, $msgid, $category)
{
    $msg_ctxt_id = "{$msg_ctxt}{$msgid}";
    $translation = dcgettext($domain, $msg_ctxt_id, $category);
    if ($translation == $msg_ctxt_id) {
        return $msgid;
    } else {
        return $translation;
    }
}
Example #4
0
 /**
  * Return a translated string.
  *
  * @param String $identifier Identifier for the requested string
  * @param String $context    Context information fot the requested string
  *
  * @return String $string Translated string, identifier by default
  */
 public function lang($identifier, $context = '')
 {
     if (strlen($identifier) + strlen($context) + 1 > self::GETTEXT_MAX_MSGID_LENGTH) {
         $this->logger->warning('Identifier too long: ' . $identifier);
         return $identifier;
     }
     $this->init($this->language);
     if ($context == '') {
         return gettext($identifier);
     }
     // Glue msgctxt and msgid together, with ASCII character 4
     // (EOT, End Of Text)
     $composed = "{$context}{$identifier}";
     $output = dcgettext($this->domain, $composed, LC_MESSAGES);
     if ($output == $composed && $this->language != $this->default_language) {
         return $identifier;
     } else {
         return $output;
     }
 }
Example #5
0
 public function search($domain = '', $message = '', $category = 0)
 {
     if (!is_string($domain) || !is_string($message)) {
         return Error::set(lang('Error', 'stringParameter', '1.(domain) & 2.(message)'));
     }
     return dcgettext($domain, $message, $category);
 }
Example #6
0
 /**
  * {@inheritdoc}
  *
  * @param  string                    $msgid
  * @param  string                    $msgctxt      Optional. If ommitted or NULL, this method behaves as query().
  * @param  array                     $placeholders Optional.
  * @param  string                    $category     Optional. Specify the locale category. Defaults to LC_MESSAGES
  * @return string
  * @throws \InvalidArgumentException
  */
 public function cquery($msgid, $msgctxt = null, $placeholders = null, $category = LC_MESSAGES, $domain = null)
 {
     if ($domain !== null && !in_array($domain, $this->domains)) {
         throw new \InvalidArgumentException($domain . ' is invalid translation domain');
     }
     if ($msgctxt === null) {
         return $this->query($msgid, $placeholders, $domain);
     }
     if ($domain === null) {
         $domain = textdomain(null);
     }
     $contextString = "{$msgctxt}{$msgid}";
     $translation = dcgettext($domain, $contextString, $category);
     if ($translation == $contextString) {
         $translation = $msgid;
     }
     if (is_array($placeholders)) {
         foreach ($placeholders as $key => $value) {
             $translation = str_replace('%' . $key . '%', $value, $translation);
         }
     }
     return $translation;
 }
function T_dcgettext($domain, $msgid, $category)
{
    if (_check_locale_and_function()) {
        return dcgettext($domain, $msgid, $category);
    } else {
        return _dcgettext($domain, $msgid, $category);
    }
}
Example #8
0
 /**
  * Emulated pgettext()
  *
  * @link http://php.net/manual/de/book.gettext.php#89975
  *
  * @param $text
  * @param $domain
  * @param $context
  *
  * @return string
  */
 public static function pgettext($text, $domain, $context)
 {
     $contextString = "{$context}{$text}";
     $translation = dcgettext($domain, $contextString, defined('LC_MESSAGES') ? LC_MESSAGES : LC_ALL);
     if ($translation == $contextString) {
         return $text;
     } else {
         return $translation;
     }
 }
Example #9
0
File: i18n.php Project: Jamp/sgas
 /**
  * Obtiene una traduccion por categoria, cuando se pasan argumentos adicionales se remplaza con sprintf
  *
  * @param string $sentence
  * @param int $category categoria del mensaje (LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_ALL)
  * @return string
  * */
 public static function cget($sentence, $category)
 {
     /**
      * Obtengo la traduccion
      * */
     $sentence = dcgettext(textdomain(null), $sentence, $category);
     /**
      * Si se pasan multiples parametros
      * */
     if (func_num_args() > 2) {
         $sentence = $sentence = self::sprintf($sentence, func_get_args(), 2);
     }
     return $sentence;
 }
Example #10
0
 /**
  * {@inheritdoc}
  *
  * @param  string $msgid
  * @param  string $msgctxt     Optional. If ommitted or NULL,
  *                             this method behaves as query().
  * @param  array $placeholders Optional.
  * @param  string $category    Optional. Specify the locale category.
  *                             Defaults to LC_MESSAGES
  *
  * @return string
  * @throws \InvalidArgumentException
  */
 public function cquery($msgid, $msgctxt = null, $placeholders = null, $category = LC_MESSAGES, $domain = null)
 {
     if ($msgctxt === null) {
         return $this->query($msgid, $placeholders, $domain);
     }
     $this->setDomain($domain);
     $contextString = "{$msgctxt}{$msgid}";
     $translation = dcgettext($domain, $contextString, $category);
     if ($translation == $contextString) {
         $translation = $msgid;
     }
     return self::setPlaceholders($translation, $placeholders);
 }
Example #11
0
 function gettext($sContents)
 {
     $this->_generateLanguage();
     $this->_generateFilePath();
     if (empty($this->sFilename)) {
         return $sContents;
     }
     return KTUtil::arrayGet($this->aStrings, $sContents, $sContents);
     return dcgettext($this->sDomain, $sContents, LC_MESSAGES);
 }
Example #12
0
<?php

$overflown = str_repeat('C', 8476509);
$msgid = "msgid";
$domain = "domain";
$category = "cat";
var_dump(bindtextdomain($overflown, 'path'));
var_dump(dngettext($overflown, $msgid, $msgid, 1));
var_dump(dngettext($domain, $overflown, $msgid, 1));
var_dump(dngettext($domain, $msgid, $overflown, 1));
var_dump(gettext($overflown));
var_dump(ngettext($overflown, $msgid, -1));
var_dump(ngettext($msgid, $overflown, -1));
var_dump(dcgettext($overflown, $msgid, -1));
var_dump(dcgettext($domain, $overflown, -1));
var_dump(dcngettext($overflown, $msgid, $msgid, -1, -1));
var_dump(dcngettext($domain, $overflown, $msgid, -1, -1));
var_dump(dcngettext($domain, $msgid, $overflown, -1, -1));
var_dump(dgettext($overflown, $msgid));
var_dump(dgettext($domain, $overflown));
var_dump(textdomain($overflown));
?>
==DONE==
Example #13
0
 public function search(string $domain, string $message, int $category = 0) : string
 {
     return dcgettext($domain, $message, $category);
 }
Example #14
0
 public function dcpgettext($context, $domain, $message, $category)
 {
     return dcgettext($domain, $context . "" . $message, constant($category));
 }
Example #15
0
 /**
  * Obtiene una traduccion por categoria, cuando se pasan argumentos adicionales se remplaza con sprintf
  *
  * @param string $sentence
  * @param int $category categoria del mensaje (LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_ALL)
  * @return string
  * */
 public static function cget($sentence, $category)
 {
     /**
      * Obtengo la traduccion
      * */
     $sentence = dcgettext(textdomain(null), $sentence, $category);
     /**
      * Si se pasan multiples parametros
      * */
     if (func_num_args() > 2) {
         $args = func_get_args();
         /**
          * Se remplaza con vsprintf
          * */
         unset($args[0], $args[1]);
         $sentence = vsprintf($sentence, $args);
     }
     return $sentence;
 }
Example #16
0
 /**
  * Override the domain and category for a single context-based lookup.
  *
  * @param  string $domain
  * @param  string $context
  * @param  string $msgid
  * @param  int    $category
  * @return string
  */
 public function dCPGetText($domain, $context, $msgid, $category)
 {
     if ($this->driver->hasLocaleAndFunction('dcgettext')) {
         $context_id = "{$context}{$msgid}";
         $translation = dcgettext($domain, $context_id, $category);
         if ($translation == $context_id) {
             return $msgid;
         }
         return $translation;
     }
     return $this->driver->dCPGetText($domain, $context, $msgid, $category);
 }
<?php

var_dump(dcgettext('a', 'b'));