Example #1
0
 /**
  * Test storage structure
  */
 public function testStorage()
 {
     $storage = new Storage();
     $result = $storage->asArray();
     $this->assertEquals(array(), $result);
     $expected = 'dummy';
     $storage->insert(0, $expected);
     $result = $storage->get(0);
     $this->assertEquals($expected, $result);
 }
Example #2
0
 /**
  * Returns translated string
  * 
  * @param string $key    The key to translate
  * @param array  $params The string values to passe in
  * @param string $target The target locale string if diferent than current
  * 
  * @return string The resulting string
  */
 public function translate($key, $params = array(), $target = null)
 {
     // Load defauts
     $current = $this->current;
     $directory = $this->directory . DIRECTORY_SEPARATOR . $current;
     $params = (array) $params;
     // Validate and load different $target
     if (!empty($target) && $target != $current) {
         $current = $target;
         $directory = $this->directory . DIRECTORY_SEPARATOR . $current;
         // Validate locale and translations directory
         if (\Locale::canonicalize($current) === null || !is_dir($this->directory . DIRECTORY_SEPARATOR . $current)) {
             throw new DualityException("Error Locale: target code ", DualityException::E_LOCALE_NOTFOUND);
         }
     }
     // Finally, return result
     $storage = new Storage();
     $storage->importArray(include $directory . DIRECTORY_SEPARATOR . 'messages.php');
     return \MessageFormatter::formatMessage($current, $storage->get($key), $params);
 }