0

All views created by cake bake which call 'format' => __() return the following error:

vsprintf(): Too few arguments [CORE/Cake/basics.php, line 565]

I looked at basics.php, line 565. It is part of the function __(). The code documentation states that the purpose of this function is to "Returns a translated string if one is found; Otherwise, the submitted message."

The line in question is:

return vsprintf($translated, $args);

I looked up vsprintf in the php docs. vsprintf accepts 2 arguments. The first being the format, and the next being an array of values. ' The function call in the view is:

'format' => __('Some Text',true);

I debugged $translated and $args.

I get $translated = 'Some Text' and $args = array((int)0=>true).

From what I see cakephp is passing the correct number of arguments to vsprintf.

How can I fix this error, or is this a bug?

What I have tried that causes the error to go away: Change the function call to 'format' => __('Some Text') - omitting the true. Which causes the function to just return $translated skipping the vsprintf() call.

thaJeztah
  • 27,738
  • 9
  • 73
  • 92
Jose
  • 1
  • I just noticed that the call to __() that is not working is part of the pagination code created by cake bake and looks like 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true). Calls to __() that do work would be more like what I used as an example above __('some text',true) works just fine whereas the call to __() from the pagination code fails. – Jose May 18 '13 at 05:54
  • 1
    Why didnt you mention the cakephp version you are working with? This is a crucial piece of information for every cake related question. – mark May 18 '13 at 08:52
  • I am using Cake 2.3.5 – Jose May 20 '13 at 00:17

1 Answers1

3

Why are you using a 1.x method in 2.x? Where did you read that? The documenation states, that you do not need true anymore as second argument to return the string:

'format' => __('Some Text', true)

should be

'format' => __('Some Text')

PS: It is this way for a long time - since 2.0 (and you are using 2.3).

mark
  • 21,691
  • 3
  • 49
  • 71
  • The baked code is what is putting the true argument in the function call. Sounds like an issue with Cake. I'm having to go back and correct the baked code. – Jose May 20 '13 at 12:39
  • Your own custom bake templates? I am pretty sure the current cake core templates are fine. Otherwise please show me the code in the template where it is inserting those true values. – mark May 20 '13 at 13:26
  • Paginator->counter(array( 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true) )); – Jose May 21 '13 at 13:02
  • That is from /cake/console/templates/default/views/index.ctp – Jose May 21 '13 at 13:03
  • I checked the version of cakephp that bake is using, I found it is 1.3.7. Based on what I read here: http://stackoverflow.com/questions/11967312/right-way-to-install-cakephp-scripts-for-v2-2-1 I need to use a different version of bake. – Jose May 21 '13 at 13:15
  • Yes, you sure do. Always call your cake core / bake shell relevantly from your app dir (`./Console/cake bake ...`or `../lib/Cake/Console/cake bake ...` for example). Then this cannot happen. – mark May 21 '13 at 13:21