silverstripe-framework/thirdparty/zend_translate_railsyaml
2012-04-15 17:17:15 +02:00
..
library/Translate/Adapter API CHANGE Using Zend_Translate with YAML translation files, replacing the $lang global and PHP files in the /lang folders. 2012-04-15 17:17:15 +02:00
tests MINOR Added zend_translate_railsyaml dependency 2012-04-15 17:17:14 +02:00
.piston.yml MINOR Added zend_translate_railsyaml dependency 2012-04-15 17:17:14 +02:00
LICENSE MINOR Added zend_translate_railsyaml dependency 2012-04-15 17:17:14 +02:00
README.md MINOR Added zend_translate_railsyaml dependency 2012-04-15 17:17:14 +02:00

Zend_Translate Adapter for Rails-style YAML files

Overview

Adds support for translations in YAML to Zend_Translate. As Yaml is a very flexible format, the translation files need some conventions. These conventions are adopted from Ruby on Rails (see Rails' i18n docs). Note: You don't need Ruby or Rails to run this code, its just PHP with the same YAML conventions.

Requirements

  • Zend Framework (tested with 1.11.6)
  • PHP 5.2

Installation and Usage

Assumes a working include_path setup for Zend (see tutorial).

Copy the files into your Zend directory (replace <zend_path> below):

cp -r library/Translate/Adapter/* <zend_path>/Zend/Translate/Adapter
cp -r tests/Translate/Adapter/* <zend_path>/Zend/tests/Translate/Adapter

Usage:

require_once 'Zend/Translate/Adapater/RailsYaml.php';
$adapter = new Zend_Translate_Adapter_RailsYaml('en.yml', 'en');
$adapter->addTranslation('de.yml', 'de');

Does not support namespace "fallbacks", as Zend_Translate doesn't have built-in support for them - it just flattens nested keys. Does not support multiple locales per translation file.

Sample translation files

en.yml

en:
  Message1: Message 1 (en)
  Message2: Message 2 (en)
  Namespace1:
    Message1: Namespace 1 Message 2 (en)
    Namespace1Message1: Namespace 1 Message 2 (en)

de.yml

de:
  Message1: Message 1 (de)
  Namespace1:
    Message1: Namespace 1 Message 2 (de)
    Namespace1Message1: Namespace 1 Message 2 (de)

Running the unit tests

The tests assume the Zend Framework in a very specific location. See tests/TestHelper.php for details. Its recommended that you copy the relevant files directly into the Zend directory structure.