2010-12-03 26 views
0

我正在使用Kohana Framework 3.x.它支持的I18n,你可以通過定義每一個給定的語言這樣一個數組本地化你的web應用:Kohana 3.x中的I18n:翻譯包含日期/時間等附加值的字符串

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

在我的PHP代碼,我可以得到適當的翻譯,像這樣:

// 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 

但什麼如果我需要翻譯含有日期或時間的句子。例如:「2天前」需要翻譯成德語「vor 2 Tagen」。我在運行時得到數字「2」(它可以是任何給定的數字),所以我不能在我的轉換數組中指定它。 Kohana是否支持某種可以在運行時添加值的本地化?

回答

4

使用來自SYSPATH/base.php__()功能:

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