Part of the EllisLab Network
This thread is a discussion for the wiki article: CodeIgniter 2.1 internationalization i18n
   
1 of 7
1
CodeIgniter 2.1 internationalization i18n
Posted: 23 January 2011 07:42 PM   [ Ignore ]  
Summer Student
Total Posts:  7
Joined  01-23-2011

I was not able to change the code due to unsufficient rights to post links.
So now I will do an atempt to post it as an attachment.

I had trouble to get this code to work in the latest Codeingiter 2.0 + HMVC.
I took all the wrong advise that I gathered from the board , only to get stuck even more.

I did some clean-up and bugfixing and finally ended up with something that does work.


Hope this helps.

Yeb Reitsma

File Attachments
CodeIgniter 2.0 i18n library v1.4.zip  (File Size: 4KB - Downloads: 993)
Profile
 
 
Posted: 27 January 2011 01:54 AM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  20
Joined  12-10-2010

Nice to hear that things have worked…

Profile
 
 
Posted: 01 February 2011 11:48 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  5
Joined  12-14-2010

Hello.


First of all, thank you for this update.

I’ve notice a small bug:
i’m using this version or internationalization with HMVC and ci2 and the $special seem to be broken.

private $special = array (
        
"admin"
        
    
);

// -> going on mysite.com/admin redirect to mysite.com/en/admin 
Profile
 
 
Posted: 01 February 2011 03:08 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  7
Joined  01-23-2011

Thanks for your feedback. You were right . The special function didn’t work.
As I don’t use it I didn’t notice it.

I just updated the code and updated the upload in the first post. Hope this fixes the issue.

Good luck.

Profile
 
 
Posted: 01 February 2011 03:13 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  5
Joined  12-14-2010

thank you.

Profile
 
 
Posted: 02 February 2011 07:19 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  7
Joined  01-23-2011

Sorry to say that with v1.2 I introduced a new bug that caused the lang_swich not to work anymore.
The upload of the first post has been updated to V1.3 which includes the fixed code.

Regards

Profile
 
 
Posted: 02 February 2011 08:13 AM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  7
Joined  01-23-2011

I goes on and on.

V.14 is uploaded. Hope all bugs are fixed now!

Profile
 
 
Posted: 03 February 2011 01:07 PM   [ Ignore ]   [ # 7 ]  
Summer Student
Avatar
Total Posts:  2
Joined  02-03-2011

After copying the files as described in the article I get the following error:
Fatal error: Call to undefined method CI_Lang::CI_Lang() in /www/websites/audio-machinery/application/core/MY_Lang.php on line 32.

Any suggestions? Thanks smile

Profile
 
 
Posted: 03 February 2011 02:23 PM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  7
Joined  01-23-2011

Yep, the code in that article is full of bugs.
Try your luck with the code I attached in the first post.  That should take care of it.

Profile
 
 
Posted: 03 February 2011 02:47 PM   [ Ignore ]   [ # 9 ]  
Summer Student
Avatar
Total Posts:  2
Joined  02-03-2011

That’s it! And finally after reading through tones of posts it works. Thanks a lot!

Profile
 
 
Posted: 04 February 2011 01:22 PM   [ Ignore ]   [ # 10 ]  
Summer Student
Total Posts:  2
Joined  02-04-2011

Webwerken,

Thanks for fixing bugs. Your version works fine!

I have one question, though.

Let’s assume we have:
- default language set to english
- default controller set to home
- other languages, e.g. german and french

Then we open our site: base_url and this call is redirected to:

base_url/default_language/default_controller 

Which is:

base_url/en/home 

Is it possible to avoid aforementioned redirection and have following structure (produced by e.g. switch_uri()):
- base_url - it is silently redirected to en/home, but the address remains the same
- base_url/de/home
- base_url/fr/home

Thanks.

Profile
 
 
Posted: 04 February 2011 08:21 PM   [ Ignore ]   [ # 11 ]  
Summer Student
Total Posts:  2
Joined  02-04-2011

One more thing:

default_lang() 

is described in comment above declaration as following:

// default language: first element of $this->languages 

It is not true - in some cases it might not return the first element of $this->languages array and we cannot rely on this method.

Profile
 
 
Posted: 08 February 2011 04:02 AM   [ Ignore ]   [ # 12 ]  
Summer Student
Total Posts:  7
Joined  01-23-2011
laszchamachla - 04 February 2011 06:22 PM

Is it possible to avoid aforementioned redirection and have following structure (produced by e.g. switch_uri()):
- base_url - it is silently redirected to en/home, but the address remains the same
- base_url/de/home
- base_url/fr/home

Thanks.

1) Using switch_uri in the constructer of the language class could cause a infinite loop. As it is modified to use “localization”, Which is a method of that same class.

2) That’s an old comment. That was how this method used to work. The current default_lang() method will pick the preferred language according to the browser preferences of the visitor.
I should have updated that. You can ignore that.

Cheers

Profile
 
 
Posted: 08 February 2011 10:41 AM   [ Ignore ]   [ # 13 ]  
Summer Student
Total Posts:  25
Joined  05-29-2007

I had a small problem with the base_url redirect because I put my controllers in subdirectorys so I had my ‘front end’ controllers in a directory called ‘controllers/client’. Therefore my route.php file looked like this:

$route['default_controller'"client/home";
$route['404_override''';

$route['admin'"admin/dashboard";

// had to add 'client' here otherwise wouldn't route properly.
$route['^(en|es|fr|it|de)/(.+)$'"client/$2";

$route['^(en|es|fr|it|de)$'$route['default_controller']

With this scenario when making a request to base url it would redirect to http://mysite.local/en/client/home which didn’t work. it needed to be http://mysite.local/en/home for it to work so in MY_lang.php changed the line:

$this->default_uri $RTR->default_controller

to

$this->default_uri 'home'

I’m sure there could have been a more elegant way to do it but it works.

Profile
 
 
Posted: 02 March 2011 04:29 PM   [ Ignore ]   [ # 14 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  159
Joined  11-16-2010

thanks for updating this library webwerken. 

For those use rely on uri->segment() , don’t forget for special routing all you do is use uri->rsegment().

uri->segment(1) should return the language (if any), while uri->rsegment(1) will return the first segment AFTER the custom routers (if any).

 Signature 

“Hate to salt your game.”

Profile
 
 
Posted: 02 March 2011 05:50 PM   [ Ignore ]   [ # 15 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  159
Joined  11-16-2010

using the .zipped files and making necessary changes, default language reverts back to English.

For example, when i change url to site.com/tr/controller
in the My_Lang file, when I echo the following line out in the __construct:

echo  $CFG->set_item('language'$language);;
// outputs 'turkish' which is correct. 

but then in my controller when i check

echo  $this->config->item('language');
// displays 'en' or english 

why is it changing the default?

[FIXED]

I was autoloading my default config file… so after the language was set to turkish, the config file was reloaded, replacing the settings. Side note, using autoload there should be some sort of check if the library/model/helper/file has already been loaded.

 Signature 

“Hate to salt your game.”

Profile
 
 
   
1 of 7
1
 
‹‹ Paypal Lib issue      OB Session ››