Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixes #6455, i18n locale message category bug

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8218 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
commit 7818eae206143db5948068a610d678333e099136 1 parent f2b7a26
gwoo authored
22 cake/basics.php
View
@@ -624,9 +624,9 @@ function __n($singular, $plural, $count, $return = false) {
}
if ($return === false) {
- echo I18n::translate($singular, $plural, null, 5, $count);
+ echo I18n::translate($singular, $plural, null, LC_MESSAGES, $count);
} else {
- return I18n::translate($singular, $plural, null, 5, $count);
+ return I18n::translate($singular, $plural, null, LC_MESSAGES, $count);
}
}
/**
@@ -672,9 +672,9 @@ function __dn($domain, $singular, $plural, $count, $return = false) {
}
if ($return === false) {
- echo I18n::translate($singular, $plural, $domain, 5, $count);
+ echo I18n::translate($singular, $plural, $domain, LC_MESSAGES, $count);
} else {
- return I18n::translate($singular, $plural, $domain, 5, $count);
+ return I18n::translate($singular, $plural, $domain, LC_MESSAGES, $count);
}
}
/**
@@ -723,13 +723,13 @@ function __dc($domain, $msg, $category, $return = false) {
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
*
* Note that the category must be specified with a numeric value, instead of the constant name. The values are:
- * LC_CTYPE 0
- * LC_NUMERIC 1
- * LC_TIME 2
- * LC_COLLATE 3
- * LC_MONETARY 4
- * LC_MESSAGES 5
- * LC_ALL 6
+ * LC_ALL 0
+ * LC_COLLATE 1
+ * LC_CTYPE 2
+ * LC_MONETARY 3
+ * LC_NUMERIC 4
+ * LC_TIME 5
+ * LC_MESSAGES 6
*
* @param string $domain Domain
* @param string $singular Singular string to translate
10 cake/libs/i18n.php
View
@@ -62,7 +62,7 @@ class I18n extends Object {
* Current language used for translations
*
* @var string
- * @access private;
+ * @access private
*/
var $__lang = null;
/**
@@ -94,7 +94,9 @@ class I18n extends Object {
* @var array
* @access private
*/
- var $__categories = array('LC_CTYPE', 'LC_NUMERIC', 'LC_TIME', 'LC_COLLATE', 'LC_MONETARY', 'LC_MESSAGES', 'LC_ALL');
+ var $__categories = array(
+ 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', 'LC_MESSAGES'
+ );
/**
* Return a static instance of the I18n class
*
@@ -111,7 +113,7 @@ function &getInstance() {
}
/**
* Used by the translation functions in basics.php
- * Can also be used like I18n::translate(); but only if the uses('i18n'); has been used to load the class.
+ * Can also be used like I18n::translate(); but only if the App::import('I18n'); has been used to load the class.
*
* @param string $singular String to translate
* @param string $plural Plural string (if any)
@@ -121,7 +123,7 @@ function &getInstance() {
* @return string translated strings.
* @access public
*/
- function translate($singular, $plural = null, $domain = null, $category = null, $count = null) {
+ function translate($singular, $plural = null, $domain = null, $category = LC_MESSAGES, $count = null) {
$_this =& I18n::getInstance();
if (strpos($singular, "\r\n") !== false) {
95 cake/tests/cases/libs/i18n.test.php
View
@@ -39,8 +39,15 @@ class I18nTest extends CakeTestCase {
* @return void
*/
function setUp() {
+ $this->_objects = Configure::read('__objects');
+ Configure::write('__objects', array());
+
$this->_localePaths = Configure::read('localePaths');
Configure::write('localePaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale'));
+
+ $this->_pluginPaths = Configure::read('pluginPaths');
+ Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins'));
+
}
/**
* tearDown method
@@ -50,6 +57,9 @@ function setUp() {
*/
function tearDown() {
Configure::write('localePaths', $this->_localePaths);
+ Configure::write('pluginPaths', $this->_pluginPaths);
+ Configure::write('__objects', $this->_objects);
+
}
/**
* testDefaultStrings method
@@ -2353,9 +2363,6 @@ function testNoCoreTranslation () {
* @return void
*/
function testPluginTranslation() {
- $pluginPaths = Configure::read('pluginPaths');
- Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins'));
-
Configure::write('Config.language', 'po');
$singular = $this->__domainSingular();
$this->assertEqual('Plural Rule 1 (from plugin)', $singular);
@@ -2387,8 +2394,6 @@ function testPluginTranslation() {
$this->assertTrue(in_array('23 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('24 = 0 or > 1 (from plugin)', $plurals));
$this->assertTrue(in_array('25 = 0 or > 1 (from plugin)', $plurals));
-
- Configure::write('pluginPaths', $pluginPaths);
}
/**
* testPoMultipleLineTranslation method
@@ -2484,6 +2489,12 @@ function testPoQuotedString () {
$expected = 'this is a "quoted string" (translated)';
$this->assertEqual(__('this is a "quoted string"', true), $expected);
}
+/**
+ * testFloatValue method
+ *
+ * @access public
+ * @return void
+ */
function testFloatValue() {
Configure::write('Config.language', 'rule_9_po');
@@ -2500,6 +2511,70 @@ function testFloatValue() {
$this->assertEqual($result, $expected);
}
/**
+ * testCategory method
+ *
+ * @access public
+ * @return void
+ */
+ function testCategory() {
+ Configure::write('Config.language', 'po');
+ $category = $this->__category();
+ $this->assertEqual('Monetary Po (translated)', $category);
+ }
+/**
+ * testPluginCategory method
+ *
+ * @access public
+ * @return void
+ */
+ function testPluginCategory() {
+ Configure::write('Config.language', 'po');
+
+ $singular = $this->__domainCategorySingular();
+ $this->assertEqual('Monetary Plural Rule 1 (from plugin)', $singular);
+
+ $plurals = $this->__domainCategoryPlural();
+ $this->assertTrue(in_array('Monetary 0 = 0 or > 1 (from plugin)', $plurals));
+ $this->assertTrue(in_array('Monetary 1 = 1 (from plugin)', $plurals));
+ }
+/**
+ * testCategoryThenSingular method
+ *
+ * @access public
+ * @return void
+ */
+ function testCategoryThenSingular() {
+ Configure::write('Config.language', 'po');
+ $category = $this->__category();
+ $this->assertEqual('Monetary Po (translated)', $category);
+
+ $singular = $this->__singular();
+ $this->assertEqual('Po (translated)', $singular);
+ }
+/**
+ * Singular method
+ *
+ * @access private
+ * @return void
+ */
+ function __domainCategorySingular($domain = 'test_plugin', $category = LC_MONETARY) {
+ $singular = __dc($domain, 'Plural Rule 1', $category, true);
+ return $singular;
+ }
+/**
+ * Plural method
+ *
+ * @access private
+ * @return void
+ */
+ function __domainCategoryPlural($domain = 'test_plugin', $category = LC_MONETARY) {
+ $plurals = array();
+ for ($number = 0; $number <= 25; $number++) {
+ $plurals[] = sprintf(__dcn($domain, '%d = 1', '%d = 0 or > 1', (float)$number, $category, true), (float)$number);
+ }
+ return $plurals;
+ }
+/**
* Singular method
*
* @access private
@@ -2523,6 +2598,16 @@ function __domainPlural($domain = 'test_plugin') {
return $plurals;
}
/**
+ * category method
+ *
+ * @access private
+ * @return void
+ */
+ function __category($category = LC_MONETARY) {
+ $singular = __c('Plural Rule 1', $category, true);
+ return $singular;
+ }
+/**
* Singular method
*
* @access private
18 cake/tests/test_app/locale/po/LC_MONETARY/default.po
View
@@ -0,0 +1,18 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: CakePHP Testsuite\n"
+"POT-Creation-Date: 2008-05-15 02:51-0700\n"
+"PO-Revision-Date: \n"
+"Last-Translator: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
+"Language-Team: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
+"X-Poedit-Language: Three Forms of Plurals\n"
+"X-Poedit-SourceCharset: utf-8\n"
+msgid ""
+msgstr "header"
+
+msgid "Plural Rule 1"
+msgstr "Monetary Po (translated)"
22 cake/tests/test_app/plugins/test_plugin/locale/po/LC_MONETARY/test_plugin.po
View
@@ -0,0 +1,22 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: CakePHP Testsuite\n"
+"POT-Creation-Date: 2008-05-15 02:51-0700\n"
+"PO-Revision-Date: \n"
+"Last-Translator: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
+"Language-Team: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=n != 1;\n"
+"X-Poedit-Language: Two Forms of Plurals\n"
+"X-Poedit-SourceCharset: utf-8\n"
+
+msgid "Plural Rule 1"
+msgstr "Monetary Plural Rule 1 (from plugin)"
+
+msgid "%d = 1"
+msgid_plural "%d = 0 or > 1"
+msgstr[0] "Monetary %d = 1 (from plugin)"
+msgstr[1] "Monetary %d = 0 or > 1 (from plugin)"
+
Please sign in to comment.
Something went wrong with that request. Please try again.