I18n with dynamic content in CakePHP

Posted by Jad on September 28, 2007

Here’s a quick one I just happened to need. When you are a nitpick like me, you sure don’t like to see code like this:

__('Logged in with', true) . $username . __('on', true) . date('Y-m-d h:i:s');
For several reasons. First, it doesn’t look slick - and yes, for you that are reading and going to annoy me for the next week, when you read code all day for a living, it matters. But most importantly, how can you then change the place of words in your sentence?

Replace that with:

sprintf(__("Logged in with '%s on %s", true), $username, date('Y-m-d h:i:s');
Another gem found by reading the source code. Which reminds me that I should maybe make a post with all the little techniques I am learning from reading the code. I know not everyone enjoys reading the API, let alone the code itself. N’est-ce pas?

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Aditya Thu, 25 Oct 2007 10:13:03 EDT

    Good One Script to read and implement for cake developers.

Comments