Skip to content
This repository
Browse code

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
authored July 03, 2009
22  cake/basics.php
@@ -624,9 +624,9 @@ function __n($singular, $plural, $count, $return = false) {
624 624
 		}
625 625
 
626 626
 		if ($return === false) {
627  
-			echo I18n::translate($singular, $plural, null, 5, $count);
  627
+			echo I18n::translate($singular, $plural, null, LC_MESSAGES, $count);
628 628
 		} else {
629  
-			return I18n::translate($singular, $plural, null, 5, $count);
  629
+			return I18n::translate($singular, $plural, null, LC_MESSAGES, $count);
630 630
 		}
631 631
 	}
632 632
 /**
@@ -672,9 +672,9 @@ function __dn($domain, $singular, $plural, $count, $return = false) {
672 672
 		}
673 673
 
674 674
 		if ($return === false) {
675  
-			echo I18n::translate($singular, $plural, $domain, 5, $count);
  675
+			echo I18n::translate($singular, $plural, $domain, LC_MESSAGES, $count);
676 676
 		} else {
677  
-			return I18n::translate($singular, $plural, $domain, 5, $count);
  677
+			return I18n::translate($singular, $plural, $domain, LC_MESSAGES, $count);
678 678
 		}
679 679
 	}
680 680
 /**
@@ -723,13 +723,13 @@ function __dc($domain, $msg, $category, $return = false) {
723 723
  * Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
724 724
  *
725 725
  * Note that the category must be specified with a numeric value, instead of the constant name.  The values are:
726  
- * LC_CTYPE     0
727  
- * LC_NUMERIC   1
728  
- * LC_TIME      2
729  
- * LC_COLLATE   3
730  
- * LC_MONETARY  4
731  
- * LC_MESSAGES  5
732  
- * LC_ALL       6
  726
+ * LC_ALL       0
  727
+ * LC_COLLATE   1
  728
+ * LC_CTYPE     2
  729
+ * LC_MONETARY  3
  730
+ * LC_NUMERIC   4
  731
+ * LC_TIME      5
  732
+ * LC_MESSAGES  6
733 733
  *
734 734
  * @param string $domain Domain
735 735
  * @param string $singular Singular string to translate
10  cake/libs/i18n.php
@@ -62,7 +62,7 @@ class I18n extends Object {
62 62
  * Current language used for translations
63 63
  *
64 64
  * @var string
65  
- * @access private;
  65
+ * @access private
66 66
  */
67 67
 	var $__lang = null;
68 68
 /**
@@ -94,7 +94,9 @@ class I18n extends Object {
94 94
  * @var array
95 95
  * @access private
96 96
  */
97  
-	var $__categories = array('LC_CTYPE', 'LC_NUMERIC', 'LC_TIME', 'LC_COLLATE', 'LC_MONETARY', 'LC_MESSAGES', 'LC_ALL');
  97
+	var $__categories = array(
  98
+		 'LC_ALL', 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME', 'LC_MESSAGES'
  99
+	);
98 100
 /**
99 101
  * Return a static instance of the I18n class
100 102
  *
@@ -111,7 +113,7 @@ function &getInstance() {
111 113
 	}
112 114
 /**
113 115
  * Used by the translation functions in basics.php
114  
- * Can also be used like I18n::translate(); but only if the uses('i18n'); has been used to load the class.
  116
+ * Can also be used like I18n::translate(); but only if the App::import('I18n'); has been used to load the class.
115 117
  *
116 118
  * @param string $singular String to translate
117 119
  * @param string $plural Plural string (if any)
@@ -121,7 +123,7 @@ function &getInstance() {
121 123
  * @return string translated strings.
122 124
  * @access public
123 125
  */
124  
-	function translate($singular, $plural = null, $domain = null, $category = null, $count = null) {
  126
+	function translate($singular, $plural = null, $domain = null, $category = LC_MESSAGES, $count = null) {
125 127
 		$_this =& I18n::getInstance();
126 128
 
127 129
 		if (strpos($singular, "\r\n") !== false) {
95  cake/tests/cases/libs/i18n.test.php
@@ -39,8 +39,15 @@ class I18nTest extends CakeTestCase {
39 39
  * @return void
40 40
  */
41 41
 	function setUp() {
  42
+		$this->_objects = Configure::read('__objects');
  43
+		Configure::write('__objects', array());
  44
+
42 45
 		$this->_localePaths = Configure::read('localePaths');
43 46
 		Configure::write('localePaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'locale'));
  47
+
  48
+		$this->_pluginPaths = Configure::read('pluginPaths');
  49
+		Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins'));
  50
+
44 51
 	}
45 52
 /**
46 53
  * tearDown method
@@ -50,6 +57,9 @@ function setUp() {
50 57
  */
51 58
 	function tearDown() {
52 59
 		Configure::write('localePaths', $this->_localePaths);
  60
+		Configure::write('pluginPaths', $this->_pluginPaths);
  61
+		Configure::write('__objects', $this->_objects);
  62
+
53 63
 	}
54 64
 /**
55 65
  * testDefaultStrings method
@@ -2353,9 +2363,6 @@ function testNoCoreTranslation () {
2353 2363
  * @return void
2354 2364
  */
2355 2365
 	function testPluginTranslation() {
2356  
-		$pluginPaths = Configure::read('pluginPaths');
2357  
-		Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins'));
2358  
-
2359 2366
 		Configure::write('Config.language', 'po');
2360 2367
 		$singular = $this->__domainSingular();
2361 2368
 		$this->assertEqual('Plural Rule 1 (from plugin)', $singular);
@@ -2387,8 +2394,6 @@ function testPluginTranslation() {
2387 2394
 		$this->assertTrue(in_array('23 = 0 or > 1 (from plugin)', $plurals));
2388 2395
 		$this->assertTrue(in_array('24 = 0 or > 1 (from plugin)', $plurals));
2389 2396
 		$this->assertTrue(in_array('25 = 0 or > 1 (from plugin)', $plurals));
2390  
-
2391  
-		Configure::write('pluginPaths', $pluginPaths);
2392 2397
 	}
2393 2398
 /**
2394 2399
  * testPoMultipleLineTranslation method
@@ -2484,6 +2489,12 @@ function testPoQuotedString () {
2484 2489
 		$expected = 'this is a "quoted string" (translated)';
2485 2490
 		$this->assertEqual(__('this is a "quoted string"', true), $expected);
2486 2491
 	}
  2492
+/**
  2493
+ * testFloatValue method
  2494
+ *
  2495
+ * @access public
  2496
+ * @return void
  2497
+ */
2487 2498
 	function testFloatValue() {
2488 2499
 		Configure::write('Config.language', 'rule_9_po');
2489 2500
 
@@ -2500,6 +2511,70 @@ function testFloatValue() {
2500 2511
 		$this->assertEqual($result, $expected);
2501 2512
 	}
2502 2513
 /**
  2514
+ * testCategory method
  2515
+ *
  2516
+ * @access public
  2517
+ * @return void
  2518
+ */
  2519
+	function testCategory() {
  2520
+		Configure::write('Config.language', 'po');
  2521
+		$category = $this->__category();
  2522
+		$this->assertEqual('Monetary Po (translated)', $category);
  2523
+	}
  2524
+/**
  2525
+ * testPluginCategory method
  2526
+ *
  2527
+ * @access public
  2528
+ * @return void
  2529
+ */
  2530
+	function testPluginCategory() {
  2531
+		Configure::write('Config.language', 'po');
  2532
+
  2533
+		$singular = $this->__domainCategorySingular();
  2534
+		$this->assertEqual('Monetary Plural Rule 1 (from plugin)', $singular);
  2535
+
  2536
+		$plurals = $this->__domainCategoryPlural();
  2537
+		$this->assertTrue(in_array('Monetary 0 = 0 or > 1 (from plugin)', $plurals));
  2538
+		$this->assertTrue(in_array('Monetary 1 = 1 (from plugin)', $plurals));
  2539
+	}
  2540
+/**
  2541
+ * testCategoryThenSingular method
  2542
+ *
  2543
+ * @access public
  2544
+ * @return void
  2545
+ */
  2546
+	function testCategoryThenSingular() {
  2547
+		Configure::write('Config.language', 'po');
  2548
+		$category = $this->__category();
  2549
+		$this->assertEqual('Monetary Po (translated)', $category);
  2550
+
  2551
+		$singular = $this->__singular();
  2552
+		$this->assertEqual('Po (translated)', $singular);
  2553
+	}
  2554
+/**
  2555
+ * Singular method
  2556
+ *
  2557
+ * @access private
  2558
+ * @return void
  2559
+ */
  2560
+	function __domainCategorySingular($domain = 'test_plugin', $category = LC_MONETARY) {
  2561
+		$singular = __dc($domain, 'Plural Rule 1', $category, true);
  2562
+		return $singular;
  2563
+	}
  2564
+/**
  2565
+ * Plural method
  2566
+ *
  2567
+ * @access private
  2568
+ * @return void
  2569
+ */
  2570
+	function __domainCategoryPlural($domain = 'test_plugin', $category = LC_MONETARY) {
  2571
+		$plurals = array();
  2572
+		for ($number = 0; $number <= 25; $number++) {
  2573
+			$plurals[] =  sprintf(__dcn($domain, '%d = 1', '%d = 0 or > 1', (float)$number, $category, true), (float)$number);
  2574
+		}
  2575
+		return $plurals;
  2576
+	}
  2577
+/**
2503 2578
  * Singular method
2504 2579
  *
2505 2580
  * @access private
@@ -2523,6 +2598,16 @@ function __domainPlural($domain = 'test_plugin') {
2523 2598
 		return $plurals;
2524 2599
 	}
2525 2600
 /**
  2601
+ * category method
  2602
+ *
  2603
+ * @access private
  2604
+ * @return void
  2605
+ */
  2606
+	function __category($category = LC_MONETARY) {
  2607
+		$singular = __c('Plural Rule 1', $category, true);
  2608
+		return $singular;
  2609
+	}
  2610
+/**
2526 2611
  * Singular method
2527 2612
  *
2528 2613
  * @access private
18  cake/tests/test_app/locale/po/LC_MONETARY/default.po
... ...
@@ -0,0 +1,18 @@
  1
+msgid ""
  2
+msgstr ""
  3
+"Project-Id-Version: CakePHP Testsuite\n"
  4
+"POT-Creation-Date: 2008-05-15 02:51-0700\n"
  5
+"PO-Revision-Date: \n"
  6
+"Last-Translator: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
  7
+"Language-Team: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
  8
+"MIME-Version: 1.0\n"
  9
+"Content-Type: text/plain; charset=UTF-8\n"
  10
+"Content-Transfer-Encoding: 8bit\n"
  11
+"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
  12
+"X-Poedit-Language: Three Forms of Plurals\n"
  13
+"X-Poedit-SourceCharset: utf-8\n"
  14
+msgid ""
  15
+msgstr "header"
  16
+
  17
+msgid "Plural Rule 1"
  18
+msgstr "Monetary Po (translated)"
22  cake/tests/test_app/plugins/test_plugin/locale/po/LC_MONETARY/test_plugin.po
... ...
@@ -0,0 +1,22 @@
  1
+msgid ""
  2
+msgstr ""
  3
+"Project-Id-Version: CakePHP Testsuite\n"
  4
+"POT-Creation-Date: 2008-05-15 02:51-0700\n"
  5
+"PO-Revision-Date: \n"
  6
+"Last-Translator: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
  7
+"Language-Team: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\n"
  8
+"MIME-Version: 1.0\n"
  9
+"Content-Type: text/plain; charset=UTF-8\n"
  10
+"Content-Transfer-Encoding: 8bit\n"
  11
+"Plural-Forms: nplurals=2; plural=n != 1;\n"
  12
+"X-Poedit-Language: Two Forms of Plurals\n"
  13
+"X-Poedit-SourceCharset: utf-8\n"
  14
+
  15
+msgid "Plural Rule 1"
  16
+msgstr "Monetary Plural Rule 1 (from plugin)"
  17
+
  18
+msgid "%d = 1"
  19
+msgid_plural "%d = 0 or > 1"
  20
+msgstr[0] "Monetary %d = 1 (from plugin)"
  21
+msgstr[1] "Monetary %d = 0 or > 1 (from plugin)"
  22
+

0 notes on commit 7818eae

Please sign in to comment.
Something went wrong with that request. Please try again.