Exemplo n.º 1
0
 /**
  * Get a translated message
  * (access point of the helper)
  *
  * @param   string  $key        The message key
  * @param   array   $parameters The message parameters
  * @return  string              The translated message
  */
 public function main($key, $parameters = [])
 {
     if ($this->i18n instanceof I18n === false) {
         return $key;
     }
     // Return the message
     return $this->i18n->getMessage($key, $parameters);
 }
Exemplo n.º 2
0
 protected function set_localeString($value)
 {
     // Create the locale if necessary
     if (!$this->_i18n->hasLocale($value)) {
         // Get the directory path
         $localeDirectory = $this->_localesPath . '/' . $value;
         if (!is_dir($localeDirectory)) {
             return;
         }
         // Create the locale instance
         $locale = new Locale($value);
         // Add the messages
         $messagesPath = $localeDirectory . '/messages.json';
         if (is_file($messagesPath)) {
             if (!is_readable($messagesPath)) {
                 throw new \Exception("{$messagesPath} is not readable");
             }
             $messages = file_get_contents($messagesPath);
             $messages = Json::removeComments($messages);
             $locale->addMessagesJson($messages);
         }
         // Add the locale
         $this->_i18n->addLocale($locale);
     }
     // Select the locale
     $this->_i18n->localeString = $value;
 }
Exemplo n.º 3
0
 /**
  * Get a translated message
  * (access point of the view helper)
  *
  * @param   string  $key        The message key
  * @return  string              The translated message
  */
 public function main($key)
 {
     if ($this->i18n instanceof I18n === false) {
         return $key;
     }
     // Get the key
     $array = explode(',', $key);
     $key = array_shift($array);
     // Build parameters
     // @todo Handle errors
     $parameters = [];
     foreach ($array as $parameter) {
         list($name, $value) = explode(':', $parameter);
         $name = trim($name);
         $value = trim($value);
         $parameters[$name] = $value;
     }
     // Return the message
     return $this->i18n->getMessage($key, $parameters);
 }