| 19 |
19 |
*/
|
| 20 |
20 |
function __($string, $args = NULL)
|
| 21 |
21 |
{
|
| 22 |
|
if (I18n::get_locale() != Kohana::config('locale.language.0'))
|
|
22 |
// en_US is the default locale, in which all of Kohana's __() calls are written in
|
|
23 |
if (I18n::get_locale() != 'en_US')
|
| 23 |
24 |
{
|
| 24 |
25 |
$string = I18n::get_text($string);
|
| 25 |
26 |
}
|
| ... | ... | |
| 32 |
33 |
|
| 33 |
34 |
class I18n_Core
|
| 34 |
35 |
{
|
| 35 |
|
protected static $locale = 'en_US';
|
|
36 |
protected static $locale;
|
|
37 |
// All the translations will be cached in here, after the first call of get_text()
|
| 36 |
38 |
protected static $translations = array();
|
| 37 |
|
|
|
39 |
|
| 38 |
40 |
public static function set_locale($locale)
|
| 39 |
41 |
{
|
| 40 |
42 |
// Reset the translations array
|
| ... | ... | |
| 47 |
49 |
{
|
| 48 |
50 |
return I18n::$locale;
|
| 49 |
51 |
}
|
| 50 |
|
|
|
52 |
|
|
53 |
|
|
54 |
/**
|
|
55 |
*
|
|
56 |
* Translates $string into language I18n::$locale and caches all found translations on the first call
|
|
57 |
*
|
|
58 |
* @return The translated String
|
|
59 |
* @param string $string The String to translate
|
|
60 |
*/
|
| 51 |
61 |
public static function get_text($string)
|
| 52 |
62 |
{
|
| 53 |
|
$locale = explode('_', I18n::$locale);
|
| 54 |
63 |
if ( ! I18n::$translations)
|
| 55 |
64 |
{
|
| 56 |
|
if (I18n::$translations = Kohana::find_file('i18n', $locale[0]) AND isset(I18n::$translation[$string]))
|
|
65 |
$locale = explode('_', I18n::$locale);
|
|
66 |
|
|
67 |
// Get the translation files
|
|
68 |
$translation_files = Kohana::find_file('i18n', $locale[0]);
|
|
69 |
|
|
70 |
if($local_translation_files = Kohana::find_file('i18n', $locale[0].'/'.$locale[1]))
|
|
71 |
$translation_files = array_merge($translation_files, $local_translation_files);
|
|
72 |
|
|
73 |
if ($translation_files)
|
| 57 |
74 |
{
|
| 58 |
|
// Merge the locale translations with the main language translation
|
| 59 |
|
if ($locale = Kohana::find_file('i18n', $locale[0].'/'.$locale[1]))
|
| 60 |
|
I18n::$translations = array_merge(I18n::$translations, $locale);
|
| 61 |
|
|
| 62 |
|
return I18n::$translations[$string];
|
|
75 |
// Merge the translations
|
|
76 |
foreach ($translation_files as $file)
|
|
77 |
{
|
|
78 |
include $file;
|
|
79 |
I18n::$translations = array_merge(I18n::$translations, $translations);
|
|
80 |
}
|
| 63 |
81 |
}
|
| 64 |
|
else
|
| 65 |
|
return $string;
|
| 66 |
82 |
}
|
|
83 |
|
|
84 |
if (isset(I18n::$translations[$string]))
|
|
85 |
return I18n::$translations[$string];
|
| 67 |
86 |
else
|
| 68 |
|
{
|
| 69 |
|
if (isset(I18n::$translations[$string]))
|
| 70 |
|
return I18n::$translations[$string];
|
| 71 |
|
else
|
| 72 |
|
return $string;
|
| 73 |
|
}
|
|
87 |
return $string;
|
| 74 |
88 |
}
|
| 75 |
89 |
|
| 76 |
90 |
}
|