write() public static méthode

Usage: $data = array( 'color' => '色' ); Catalog::write('runtime', 'message', 'ja', $data);
public static write ( string $name, string $category, string $locale, mixed $data, array $options = [] ) : boolean
$name string Provide a configuration name to use for writing.
$category string A (dot-delimited) category.
$locale string A locale identifier.
$data mixed If method is used without specifying an id must be an array.
$options array Valid options are: - `'scope'`: The scope to use.
Résultat boolean Success.
	public function testTransliteration() {
		$data = array(
			'transliteration' => array(
				'\$' => 'dollar',
				'&' => 'and'
			)
		);
		Catalog::write('runtime', 'inflection', 'en', $data);

		Inflector::rules(
			'transliteration', Catalog::read('runtime', 'inflection.transliteration', 'en')
		);

		$result = Inflector::slug('this & that');
		$expected = 'this-and-that';
		$this->assertEqual($expected, $result);

		$data = array(
			'transliteration' => array(
				't' => 'd',
				'&' => 'und'
			)
		);
		Catalog::write('runtime', 'inflection', 'de', $data);

		Inflector::rules(
			'transliteration', Catalog::read('runtime', 'inflection.transliteration', 'de')
		);

		$result = Inflector::slug('this & that');
		$expected = 'dhis-und-dhad';
		$this->assertEqual($expected, $result);
	}
 /**
  * 1. Extract all translated strings from the codebase
  *    If you modify any text in the site, please follow Extract, Create and Compile
  */
 public function extract()
 {
     $command = 'echo Y|del "F:\\Apache\\www\\TBG\\xgcwallet.org\\app\\resources\\tmp\\cache\\templates\\*.*"';
     passthru($command);
     $data = Catalog::read('code', 'messageTemplate', 'root', array('lossy' => false));
     $scope = 'default';
     return Catalog::write('default', 'messageTemplate', 'root', $data, compact('scope'));
 }
 public function testMultipleLocales()
 {
     $data = '/phone en_US/';
     Catalog::write('runtime', 'validation.phone', 'en_US', $data);
     $data = '/phone en_GB/';
     Catalog::write('runtime', 'validation.phone', 'en_GB', $data);
     Validator::add('phone', array('en_US' => Catalog::read('runtime', 'validation.phone', 'en_US'), 'en_GB' => Catalog::read('runtime', 'validation.phone', 'en_GB')));
     $result = Validator::isPhone('phone en_US', 'en_US');
     $this->assertTrue($result);
     $result = Validator::isPhone('phone en_GB', 'en_GB');
     $this->assertTrue($result);
 }
 /**
  * Prompts for data source and writes template.
  *
  * @param array $data Data to save.
  * @return void
  */
 protected function _writeTemplate($data)
 {
     $message[] = 'In order to proceed you need to choose a `Catalog` configuration';
     $message[] = 'which is used for writing the template. The adapter for the configuration';
     $message[] = 'should be capable of handling write requests for the `messageTemplate`';
     $message[] = 'category.';
     $this->out($message);
     $this->out();
     $name = $this->_configuration(array('adapter' => 'Gettext', 'path' => $this->destination, 'scope' => $this->scope));
     if ($name != 'temporary') {
         $scope = $this->in('Scope:', array('default' => $this->scope));
     }
     $message = array();
     $message[] = 'The template is now ready to be saved.';
     $message[] = 'Please note that an existing template will be overwritten.';
     $this->out($message);
     $this->out();
     if ($this->in('Save?', array('choices' => array('y', 'n'), 'default' => 'y')) != 'y') {
         $this->out('Aborting upon user request.');
         $this->stop(1);
     }
     try {
         return Catalog::write($name, 'messageTemplate', 'root', $data, compact('scope'));
     } catch (Exception $e) {
         return false;
     }
 }
Exemple #5
0
 /**
  * Prompts for data source and writes template.
  *
  * @param array $data Data to save.
  * @return void
  */
 protected function _writeTemplate($data)
 {
     $message[] = 'In order to proceed you need to choose a `Catalog` configuration';
     $message[] = 'which is used for writing the template. The adapter for the configuration';
     $message[] = 'should be capable of handling write requests for the `messageTemplate`';
     $message[] = 'category.';
     $this->out($message);
     $this->out();
     $configs = (array) Catalog::config();
     $this->out('Available `Catalog` Configurations:');
     foreach ($configs as $name => $config) {
         $this->out(" - {$name}");
     }
     $this->out();
     $name = $this->in('Please choose a configuration or hit [enter] to add one:', array('choices' => array_keys($configs)));
     if (!$name) {
         $adapter = $this->in('Adapter:', array('default' => 'Gettext'));
         $path = $this->in('Path:', array('default' => $this->destination));
         $scope = $this->in('Scope:', array('default' => $this->scope));
         $name = 'runtime' . uniqid();
         $configs[$name] = compact('adapter', 'path', 'scope');
         Catalog::config($configs);
     } else {
         $scope = $this->in('Scope:', array('default' => $this->scope));
     }
     $message = array();
     $message[] = 'The template is now ready to be saved.';
     $message[] = 'Please note that an existing template will be overwritten.';
     $this->out($message);
     $this->out();
     if ($this->in('Save?', array('choices' => array('y', 'n'), 'default' => 'y')) != 'y') {
         $this->out('Aborting upon user request.');
         $this->stop(1);
     }
     try {
         return Catalog::write($name, 'messageTemplate', 'root', $data, compact('scope'));
     } catch (Exception $e) {
         return false;
     }
 }
 *   - `'path'` All adapters with the exception of the _memory_ adapter require a directory
 *     which holds the data.
 *
 *   - `'scope'` If you plan on using scoping i.e. for accessing plugin data separately you
 *     need to specify a scope for each configuration, except for those using the _memory_,
 *     _php_ or _gettext_ adapter which handle this internally.
 */
Catalog::config(array('runtime' => array('adapter' => 'Memory'), 'lithium' => array('adapter' => 'Php', 'path' => LITHIUM_LIBRARY_PATH . '/lithium/g11n/resources/php')));
/**
 * Globalization runtime data.  You can add globalized data during runtime utilizing a
 * configuration set up to use the _memory_ adapter.
 */
$data = function ($n) {
    return $n != 1 ? 1 : 0;
};
Catalog::write('message.plural', 'root', $data, array('name' => 'runtime'));
/**
 * Integration with `Inflector`.
 */
// Inflector::rules('transliteration', Catalog::read('inflection.transliteration', 'en'));
/*
 * Inflector configuration examples.  If your application has custom singular or plural rules, or
 * extra non-ASCII characters to transliterate, you can configure that by uncommenting the lines
 * below.
 */
// Inflector::rules('singular', array('rules' => array('/rata/' => '\1ratus')));
// Inflector::rules('singular', array('irregular' => array('foo' => 'bar')));
//
// Inflector::rules('plural', array('rules' => array('/rata/' => '\1ratum')));
// Inflector::rules('plural', array('irregular' => array('bar' => 'foo')));
//
 public function testShortHandsSymmetry()
 {
     $data = array('house' => array('Haus', 'Häuser'));
     Catalog::write('message', 'de', $data, array('name' => 'runtime'));
     $filters = Message::shortHands();
     $t = $filters['t'];
     $tn = $filters['tn'];
     $expected = Message::translate('house', array('locale' => 'de'));
     $result = $t('house', array('locale' => 'de'));
     $this->assertEqual($expected, $result);
     $expected = Message::translate('house', array('locale' => 'de', 'count' => 1));
     $result = $tn('house', 'houses', 1, array('locale' => 'de'));
     $this->assertEqual($expected, $result);
     $expected = Message::translate('house', array('locale' => 'de', 'count' => 3));
     $result = $tn('house', 'houses', 3, array('locale' => 'de'));
     $this->assertEqual($expected, $result);
 }
 public function testOutputLosslessFormat()
 {
     $data = array('house' => array('id' => 'house', 'ids' => array('singular' => 'house'), 'translated' => 'Haus', 'flags' => array(), 'comments' => array(), 'occurrences' => array()));
     Catalog::write('message', 'de', $data, array('name' => 'runtime'));
     $result = Catalog::read('message', 'de', array('lossy' => false));
     $expected = array('house' => array('id' => 'house', 'ids' => array('singular' => 'house'), 'translated' => 'Haus', 'flags' => array(), 'comments' => array(), 'occurrences' => array()));
     $this->assertEqual($expected, $result);
 }
Exemple #9
0
 public function testCaching()
 {
     $data = array('catalog' => 'Katalog');
     Catalog::write('runtime', 'message', 'de', $data, array('scope' => 'foo'));
     $this->assertFalse(Message::cache());
     $result = Message::translate('catalog', array('locale' => 'de', 'scope' => 'foo'));
     $this->assertEqual('Katalog', $result);
     $cache = Message::cache();
     $this->assertEqual('Katalog', $cache['foo']['de']['catalog']);
     Message::cache(false);
     $this->assertFalse(Message::cache());
     Message::cache(array('foo' => array('de' => array('catalog' => '<Katalog>'))));
     $result = Message::translate('catalog', array('locale' => 'de', 'scope' => 'foo'));
     $this->assertEqual('<Katalog>', $result);
     $options = array('locale' => 'de', 'scope' => 'foo', 'count' => 2);
     $this->assertEqual('<Katalog>', Message::translate('catalog', $options));
     Message::cache(false);
     Message::cache(array('foo' => array('de' => array('catalog' => array('<Katalog>')))));
     $this->assertNull(Message::translate('catalog', $options));
 }
Exemple #10
0
 public function testInvalidWrite()
 {
     Catalog::reset();
     $this->assertException("Configuration `runtime` has not been defined.", function () {
         $data = array('house' => array('id' => 'house'));
         Catalog::write('runtime', 'message', 'de', $data);
     });
 }
Exemple #11
0
 public function testInvalidWrite()
 {
     Catalog::reset();
     $data = array('house' => array('id' => 'house'));
     $this->expectException("Configuration 'runtime' has not been defined.");
     $this->assertFalse(Catalog::write('runtime', 'message', 'de', $data));
 }