clifford.duke
clifford.duke

Reputation: 4040

Using the I18n functionality in Kohana 3.3

I'm having trouble with the I18n functionality in Kohana 3.3

My I18n folder structure is as follows

i18n/

The problem I'm getting is that everywhere I read it should be possible to load the language like so i18n::lang('en-us'); because the api states that it explodes the string on the “-” character, so the default target language “en-us” results in a search for the following files:

/application/i18n/en.php
/application/i18n/en/us.php

It only seems to load the correct language files when I use i18n::lang('en/us'); instead of i18n::lang('en-us');

Upvotes: 0

Views: 1766

Answers (1)

biakaveron
biakaveron

Reputation: 5483

Works for me. These calls are equals for Kohana:

I18n::lang('en-us'); 
I18n::lang('en us');
I18n::lang('en_us');

When you use 'en/us' value, I18n will not load i18n/en.php file, only i18n/en/us.php.

I can suggest only one reason for your problems:

You are using __() function, which ignores translations for default language ('en-us' is hardcoded). So, when you call I18n::lang('en/us'), default language is still english, but it differs from 'en-us'. Little hack :)

You can extend I18n class with APPPATH/classes/I18n.php file (standard Kohana way), and add your own version for that function:

// translate always!
function __($string, array $values = NULL, $lang = 'en-us')
{
    $string = I18n::get($string);

    return empty($values) ? $string : strtr($string, $values);
}

Upvotes: 1

Related Questions