lithium\g11n\Catalog::write PHP Method

write() public static method

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.
return boolean Success.
    public static function write($name, $category, $locale, $data, array $options = array())
    {
        $defaults = array('scope' => null);
        $options += $defaults;
        $category = strtok($category, '.');
        $id = strtok('.');
        if ($id) {
            $data = array($id => $data);
        }
        array_walk($data, function (&$value, $key) {
            if (!is_array($value) || !array_key_exists('translated', $value)) {
                $value = array('id' => $key, 'translated' => $value);
            }
        });
        $adapter = static::adapter($name);
        return $adapter->write($category, $locale, $options['scope'], $data);
    }

Usage Example

Beispiel #1
0
	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);
	}
All Usage Examples Of lithium\g11n\Catalog::write