diff --git a/lib/Cake/Test/Case/BasicsTest.php b/lib/Cake/Test/Case/BasicsTest.php index a1e3d7324..eb4edee82 100644 --- a/lib/Cake/Test/Case/BasicsTest.php +++ b/lib/Cake/Test/Case/BasicsTest.php @@ -432,6 +432,146 @@ class BasicsTest extends CakeTestCase { $this->assertEquals($expected, $result, 'significant-digit placeholder should not be misinterpreted'); } +/** + * testTranslateWithFormatSpecifiers + * + * @return void + */ + public function testTranslateWithFormatSpecifiers() { + $expected = 'Check, one, two, three'; + $result = __('Check, %+10s, three', 'one, two'); + $this->assertEquals($expected, $result); + + $expected = 'Check, +1, two, three'; + $result = __('Check, %+5d, two, three', 1); + $this->assertEquals($expected, $result); + + $expected = 'Check, @@one, two, three'; + $result = __('Check, %\'@+10s, three', 'one, two'); + $this->assertEquals($expected, $result); + + $expected = 'Check, one, two , three'; + $result = __('Check, %-10s, three', 'one, two'); + $this->assertEquals($expected, $result); + + $expected = 'Check, one, two##, three'; + $result = __('Check, %\'#-10s, three', 'one, two'); + $this->assertEquals($expected, $result); + + $expected = 'Check, one, two, three'; + $result = __d('default', 'Check, %+10s, three', 'one, two'); + $this->assertEquals($expected, $result); + + $expected = 'Check, @@one, two, three'; + $result = __d('default', 'Check, %\'@+10s, three', 'one, two'); + $this->assertEquals($expected, $result); + + $expected = 'Check, one, two , three'; + $result = __d('default', 'Check, %-10s, three', 'one, two'); + $this->assertEquals($expected, $result); + + $expected = 'Check, one, two##, three'; + $result = __d('default', 'Check, %\'#-10s, three', 'one, two'); + $this->assertEquals($expected, $result); + } + +/** + * testTranslateDomainPluralWithFormatSpecifiers + * + * @return void + */ + public function testTranslateDomainPluralWithFormatSpecifiers() { + $result = __dn('core', '%+5d item.', '%+5d items.', 1, 1); + $expected = ' +1 item.'; + $this->assertEquals($expected, $result); + + $result = __dn('core', '%-5d item.', '%-5d items.', 10, 10); + $expected = '10 items.'; + $this->assertEquals($expected, $result); + + $result = __dn('core', '%\'#+5d item.', '%\'*+5d items.', 1, 1); + $expected = '###+1 item.'; + $this->assertEquals($expected, $result); + + $result = __dn('core', '%\'#+5d item.', '%\'*+5d items.', 90, 90); + $expected = '**+90 items.'; + $this->assertEquals($expected, $result); + + $result = __dn('core', '%\'#+5d item.', '%\'*+5d items.', 9000, 9000); + $expected = '+9000 items.'; + $this->assertEquals($expected, $result); + } + +/** + * test testTranslatePluralWithFormatSpecifiers + * + * @return void + */ + public function testTranslatePluralWithFormatSpecifiers() { + Configure::write('Config.language', 'rule_1_po'); + + $result = __n('%-5d = 1', '%-5d = 0 or > 1', 10); + $expected = '%-5d = 0 or > 1 (translated)'; + $this->assertEquals($expected, $result); + } + +/** + * test testTranslateDomainCategoryWithFormatSpecifiers + * + * @return void + */ + public function testTranslateDomainCategoryWithFormatSpecifiers() { + Configure::write('Config.language', 'rule_1_po'); + + $result = __dc('default', '%+10s world', 6, 'hello'); + $expected = ' hello world'; + $this->assertEquals($expected, $result); + + $result = __dc('default', '%-10s world', 6, 'hello'); + $expected = 'hello world'; + $this->assertEquals($expected, $result); + + $result = __dc('default', '%\'@-10s world', 6, 'hello'); + $expected = 'hello@@@@@ world'; + $this->assertEquals($expected, $result); + } + +/** + * test testTranslateDomainCategoryPluralWithFormatSpecifiers + * + * @return void + */ + public function testTranslateDomainCategoryPluralWithFormatSpecifiers() { + Configure::write('Config.language', 'rule_1_po'); + + $result = __dcn('default', '%-5d = 1', '%-5d = 0 or > 1', 0, 6); + $expected = '%-5d = 0 or > 1 (translated)'; + $this->assertEquals($expected, $result); + + $result = __dcn('default', '%-5d = 1', '%-5d = 0 or > 1', 1, 6); + $expected = '%-5d = 1 (translated)'; + $this->assertEquals($expected, $result); + } + +/** + * test testTranslateCategoryWithFormatSpecifiers + * + * @return void + */ + public function testTranslateCategoryWithFormatSpecifiers() { + $result = __c('Some string with %+10s', 6, 'arguments'); + $expected = 'Some string with arguments'; + $this->assertEquals($expected, $result); + + $result = __c('Some string with %-10s: args', 6, 'arguments'); + $expected = 'Some string with arguments : args'; + $this->assertEquals($expected, $result); + + $result = __c('Some string with %\'*-10s: args', 6, 'arguments'); + $expected = 'Some string with arguments*: args'; + $this->assertEquals($expected, $result); + } + /** * test __n() * diff --git a/lib/Cake/Test/test_app/Locale/rule_13_po/LC_MESSAGES/core.po b/lib/Cake/Test/test_app/Locale/rule_13_po/LC_MESSAGES/core.po index fde299591..5b55045ef 100644 --- a/lib/Cake/Test/test_app/Locale/rule_13_po/LC_MESSAGES/core.po +++ b/lib/Cake/Test/test_app/Locale/rule_13_po/LC_MESSAGES/core.po @@ -22,3 +22,5 @@ msgstr[1] "%d is 0 or ends in 01-10 (from core translated)" msgstr[2] "%d ends in 11-20 (from core translated)" msgstr[3] "%d everything else (from core translated)" +msgid "%+5d = 1 (from core)" +msgid_plural "%+5d = 0 or > 1 (from core)" diff --git a/lib/Cake/Test/test_app/Locale/rule_1_po/LC_MESSAGES/default.po b/lib/Cake/Test/test_app/Locale/rule_1_po/LC_MESSAGES/default.po index 6667c960c..d0198fcb9 100644 --- a/lib/Cake/Test/test_app/Locale/rule_1_po/LC_MESSAGES/default.po +++ b/lib/Cake/Test/test_app/Locale/rule_1_po/LC_MESSAGES/default.po @@ -20,6 +20,11 @@ msgid_plural "%d = 0 or > 1" msgstr[0] "%d = 1 (translated)" msgstr[1] "%d = 0 or > 1 (translated)" +msgid "%-5d = 1" +msgid_plural "%-5d = 0 or > 1" +msgstr[0] "%-5d = 1 (translated)" +msgstr[1] "%-5d = 0 or > 1 (translated)" + #~ msgid "Plural-Forms 1" #~ msgstr "Plural-Forms 1 (translated)" diff --git a/lib/Cake/basics.php b/lib/Cake/basics.php index 9d05a2abc..9e483ad35 100644 --- a/lib/Cake/basics.php +++ b/lib/Cake/basics.php @@ -560,7 +560,7 @@ if (!function_exists('__')) { $args = array_slice(func_get_args(), 1); } - $translated = preg_replace('/(?