Pascal Klein
Pascal Klein

Reputation: 24903

I18n in Kohana 3.x: Translating strings that contain additional values like date / time

I'm using the Kohana Framework 3.x. It supports I18n and you can localize your Webapplication by defining an array for every given language like so:

// application/i18n/de.php adds support for the german language like so
return array
(
    'language' => 'Sprache',
    'house' => 'Haus'
    //more key-value pairs
);

Within my php-code I can get the appropriate translation like so:

// define current language somewhere, for example german
i18n::lang("de");

// get the translation for a given key
echo I18n::get('house'); // the key "house" obviously has to be the same for all languages

But what if I need to translate sentences that contain a date or time. For example: "2 days ago" needs to be translated to "vor 2 Tagen" in german. I get the number "2" at runtime (it could be any given number), so I cant specifiy it within my translation array. Does Kohana support some kind of localization where I can add values at runtime?

Upvotes: 0

Views: 1965

Answers (1)

biakaveron
biakaveron

Reputation: 5483

Use __() function from SYSPATH/base.php:

echo __('house'); // just translate 'house' 
echo __(':count days ago', array(':count' => 2)); // translate with values replacement

Upvotes: 4

Related Questions