From 66f51f3c17e7d44eec399f427dd210a48391ba63 Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Wed, 26 Nov 2008 11:46:56 +0000 Subject: Initial commit of the translation class, I18n_Core and some tests. - Port of Ruby's I18n gem (http://rails-i18n.org/) - Added proper plural handling on top of that. - Using CLDR 1.6's plural form data - See I18n_Test for example usage. - Not integrated into G3 templates yet. Probably adding __() as alias for I18n::instance->translate(). - No specific plan yet where localization files should live. --- core/tests/I18n_Test.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 core/tests/I18n_Test.php (limited to 'core/tests') diff --git a/core/tests/I18n_Test.php b/core/tests/I18n_Test.php new file mode 100644 index 00000000..fab3cf43 --- /dev/null +++ b/core/tests/I18n_Test.php @@ -0,0 +1,80 @@ + 'en', + 'default_locale' => 'de_DE', + 'locale_dir' => VARPATH . 'locale/'); + $this->i18n = I18n::instance($config); + + $locale_file_contents = << 'Hallo Welt', + 'One item has been added' => + array('one' => 'Ein Element wurde hinzugefuegt.', + 'other' => '{{count}} Elemente wurden hinzugefuegt.'), + 'Hello {{name}}, how are you today?' => 'Hallo {{name}}, wie geht es Dir heute?' +); +EOT; + + @mkdir(VARPATH . 'locale'); + $fp = file_put_contents(VARPATH . 'locale/de_DE.php', $locale_file_contents); + } + + public function translate_simple_test() { + $result = $this->i18n->translate('Hello world'); + $this->assert_equal('Hallo Welt', $result); + } + + public function translate_simple_root_fallback_test() { + $result = $this->i18n->translate('Hello world zzz'); + $this->assert_equal('Hello world zzz', $result); + } + + public function translate_plural_other_test() { + $result = $this->i18n->translate(array('one' => 'One item has been added', + 'other' => '{{count}} items have been added.'), + array('count' => 5)); + $this->assert_equal('5 Elemente wurden hinzugefuegt.', $result); + } + + public function translate_plural_one_test() { + $result = $this->i18n->translate(array('one' => 'One item has been added', + 'other' => '{{count}} items have been added.'), + array('count' => 1)); + $this->assert_equal('Ein Element wurde hinzugefuegt.', $result); + } + + public function translate_interpolate_test() { + $result = $this->i18n->translate('Hello {{name}}, how are you today?', array('name' => 'John')); + $this->assert_equal('Hallo John, wie geht es Dir heute?', $result); + } + + public function translate_interpolate_missing_value_test() { + $result = $this->i18n->translate('Hello {{name}}, how are you today?', array('foo' => 'bar')); + $this->assert_equal('Hallo {{name}}, wie geht es Dir heute?', $result); + } +} \ No newline at end of file -- cgit v1.2.3