Skip to content

Commit

Permalink
Fixes #2707
Browse files Browse the repository at this point in the history
When the first variable argument = null, but there are more arguments given.
Added testcases to show the change (to fail before the fix)
  • Loading branch information
hmic committed Aug 24, 2014
1 parent 8f420d7 commit b4620b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions lib/Cake/Test/Case/BasicsTest.php
Expand Up @@ -380,6 +380,14 @@ public function testTranslate() {
$expected = 'Some string with multiple arguments';
$this->assertEquals($expected, $result);

$result = __('Some string with %s and a null argument', null);
$expected = 'Some string with %s and a null argument';
$this->assertEquals($expected, $result);

$result = __('Some string with multiple %s%s, first beeing null', null, 'arguments');
$expected = 'Some string with multiple arguments, first beeing null';
$this->assertEquals($expected, $result);

$result = __('Some string with %s %s', array('multiple', 'arguments'));
$expected = 'Some string with multiple arguments';
$this->assertEquals($expected, $result);
Expand Down
14 changes: 7 additions & 7 deletions lib/Cake/basics.php
Expand Up @@ -554,7 +554,7 @@ function __($singular, $args = null) {

App::uses('I18n', 'I18n');
$translated = I18n::translate($singular);
if ($args === null) {
if ($args === null && func_num_args() < 3) {
return $translated;
} elseif (!is_array($args)) {
$args = array_slice(func_get_args(), 1);
Expand Down Expand Up @@ -586,7 +586,7 @@ function __n($singular, $plural, $count, $args = null) {

App::uses('I18n', 'I18n');
$translated = I18n::translate($singular, $plural, null, I18n::LC_MESSAGES, $count);
if ($args === null) {
if ($args === null && func_num_args() < 5) {
return $translated;
} elseif (!is_array($args)) {
$args = array_slice(func_get_args(), 3);
Expand Down Expand Up @@ -615,7 +615,7 @@ function __d($domain, $msg, $args = null) {
}
App::uses('I18n', 'I18n');
$translated = I18n::translate($msg, null, $domain);
if ($args === null) {
if ($args === null && func_num_args() < 4) {
return $translated;
} elseif (!is_array($args)) {
$args = array_slice(func_get_args(), 2);
Expand Down Expand Up @@ -648,7 +648,7 @@ function __dn($domain, $singular, $plural, $count, $args = null) {
}
App::uses('I18n', 'I18n');
$translated = I18n::translate($singular, $plural, $domain, I18n::LC_MESSAGES, $count);
if ($args === null) {
if ($args === null && func_num_args() < 6) {
return $translated;
} elseif (!is_array($args)) {
$args = array_slice(func_get_args(), 4);
Expand Down Expand Up @@ -692,7 +692,7 @@ function __dc($domain, $msg, $category, $args = null) {
}
App::uses('I18n', 'I18n');
$translated = I18n::translate($msg, null, $domain, $category);
if ($args === null) {
if ($args === null && func_num_args() < 5) {
return $translated;
} elseif (!is_array($args)) {
$args = array_slice(func_get_args(), 3);
Expand Down Expand Up @@ -740,7 +740,7 @@ function __dcn($domain, $singular, $plural, $count, $category, $args = null) {
}
App::uses('I18n', 'I18n');
$translated = I18n::translate($singular, $plural, $domain, $category, $count);
if ($args === null) {
if ($args === null && func_num_args() < 7) {
return $translated;
} elseif (!is_array($args)) {
$args = array_slice(func_get_args(), 5);
Expand Down Expand Up @@ -780,7 +780,7 @@ function __c($msg, $category, $args = null) {
}
App::uses('I18n', 'I18n');
$translated = I18n::translate($msg, null, null, $category);
if ($args === null) {
if ($args === null && func_num_args() < 4) {
return $translated;
} elseif (!is_array($args)) {
$args = array_slice(func_get_args(), 2);
Expand Down

0 comments on commit b4620b4

Please sign in to comment.