Re: Cause for l10n/i18n not working?
App::import('Core', 'i18n'); $i18n = I18n::getInstance(); $i18n-l10n-get($lang); I had not used this method myself, guess I should have mentioned that. But checking it now it does the same for me as resetting Configure in my beforeFilter... it works. However changing it later in the processing using this method may not be possible. I have tried to use this code in a view without any results. Also this seemed to trick the caching of the locale so I ended up with some strange things happening. A few things that may cause a change in beforeFilter not to work is that you have to set it to eng, fra or swe... not en_us, se_sv or something similar (just checking). You should try this with all caching off for a start (see above). Also remember, you have to set it before using i18n. example code in AppController::beforeFilter Configure::write('Config.language', 'swe'); // this changes the language. __('hello'); // first time this is called a new i18n instance is created and the locale is set. Configure::write('Config.language', 'eng'); // this will not have any effect since the locale is already loaded Yes, this will output a string before headers are sent so it is just an example. I wanted is as clean as possible. $aVar = __('hello', true); // this would be more correct but also less readable IMHO. The main problem with changing the language is that i18n loads the locale once and looking at the code now I am not sure there is a simple way to change it once it has been loaded. You would have to make i18n drop its current instance and create a new one. There is no public method for doing this. /Martin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Cause for l10n/i18n not working?
On 22 Apr 2008, at 16:28, [EMAIL PROTECTED] wrote: A few things that may cause a change in beforeFilter not to work is that you have to set it to eng, fra or swe... not en_us, se_sv or something similar (just checking). You should try this with all caching off for a start (see above). Also remember, you have to set it before using i18n. I'm setting it to jpn, the default was eng. What's the correct one to use anyway? I've seen different codes used throughout the i18n/l10n modules. Sometimes it seems to use 'ja', sometimes 'jpn'. It's pretty confusing/inconsistent. The main problem with changing the language is that i18n loads the locale once and looking at the code now I am not sure there is a simple way to change it once it has been loaded. You would have to make i18n drop its current instance and create a new one. There is no public method for doing this. Okay, that fixed the problem. There was a call to __() in my beforeFilter before the language was switched. Sorry, my fault then. Another question though: the manual states that: Any Controller that uses localized content should include the use of the L10n CakePHP utility class. uses('L10n'); This doesn't seem to be necessary. Additionally, isn't var $uses = array('L10n') the preferred method? Chrs, Dav --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Cause for l10n/i18n not working?
I'm setting it to jpn, the default was eng. What's the correct one to use anyway? I've seen different codes used throughout the i18n/l10n modules. Sometimes it seems to use 'ja', sometimes 'jpn'. It's pretty confusing/inconsistent. I know, I think that it is the docs that are a bit fuzzy on this subject. From my own attempts It looks like you can either use the keys from the first lookup-table in l10n.php. Japanese should then be set to jpn. Alternatively you can use ja since it will not be found in the first table and the class will look for it in the second one and find ja there. first lookup: /* Japanese */ 'jpn' = 'ja', second lookup 'ja' = array('language' = 'Japanese', 'locale' = 'jpn', 'localeFallback' = 'jpn', 'charset' = 'utf-8'), It causes me the least amount of headache to set the language to the same value as the folder-name where the translation is located. This works for most languages I make use of even though the folder is actually chosen from the locale key in the second lookup... I think. Glossery: first lookup = var $__l10nMap @ lines 95-172 second lookup = var $__l10nCatalog @ lines 181-320 Another question though: the manual states that: Any Controller that uses localized content should include the use of the L10n CakePHP utility class. uses('L10n'); This doesn't seem to be necessary. Additionally, isn't var $uses = array('L10n') the preferred method? I agree. I think this is a leftover from v 1.1 or something. So far I have only had to use the Configure directive to set the language. uses() would in 1.2 be called App::import() in this context. $uses and uses() were two different things in earlier versions or Cake. I guess we will soon have sorted this out enough to update some documentation. :) /Martin --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Cause for l10n/i18n not working?
I use the l10n/i18n to set language, my method is close to yours except that I set the language using : $l10n = new L10n(); $l10n-__setLanguage($lang) hth On Apr 21, 8:51 am, David Christopher Zentgraf [EMAIL PROTECTED] wrote: This seems to be the cause of a lot of complaints about l10n/i18n not working. I set up two languages in my app: 'eng' and 'jpn'. In core.php I added: define('DEFAULT_LANGUAGE', 'eng'); Configure::write('Config.language', 'en'); In my app_controller beforeFilter: $lang = $this-Auth-user('pref_lang'); // user pref saved in the DB $this-L10n-get($lang); // Config.language gets set to 'ja' here I put a debug on line 124 of i18n.php: Debugger::log('l10n instance: '.$_this-l10n-locale.', Configure: '.Configure::read('Config.language')); 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: en 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja ... The very first instance of l10n seems to get the default language from core.php, but afterwards my beforeFilter is changing it. i18n holds on to just one instance of l10n though, which causes it to continue to use the default value. I opened a ticket for it:https://trac.cakephp.org/ticket/4509 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Cause for l10n/i18n not working?
I hope we are all talking about Cake 1.2 here? I am not sure that you should mess with l10n directly at all. When you do, you are effectively setting the language at different levels in the locale classes. This is what I believe is causing your problems. If you set the language in l10n, then i18n will not pick this up. define('DEFAULT_LANGUAGE', 'eng'); - deprecated, use Configure::write() Configure::write('Config.language', 'eng'); - sets the language. This value is used by i18n. I can switch languages in my app by resetting this value in beforeFilter. No need to call up an instance of l10n. If you want to switch it on the fly during rendering (don't know why really, but)... then it is another matter since i18n does not recheck the config once it has been setup. Then you need to get the current instance of i18n and set the language there: App::import('Core', 'i18n'); $i18n = I18n::getInstance(); $i18n-l10n-get($lang); hope this helps. /Martin On Apr 21, 12:28 pm, francky06l [EMAIL PROTECTED] wrote: I use the l10n/i18n to set language, my method is close to yours except that I set the language using : $l10n = new L10n(); $l10n-__setLanguage($lang) hth On Apr 21, 8:51 am, David Christopher Zentgraf [EMAIL PROTECTED] wrote: This seems to be the cause of a lot of complaints about l10n/i18n not working. I set up two languages in my app: 'eng' and 'jpn'. In core.php I added: define('DEFAULT_LANGUAGE', 'eng'); Configure::write('Config.language', 'en'); In my app_controller beforeFilter: $lang = $this-Auth-user('pref_lang'); // user pref saved in the DB $this-L10n-get($lang); // Config.language gets set to 'ja' here I put a debug on line 124 of i18n.php: Debugger::log('l10n instance: '.$_this-l10n-locale.', Configure: '.Configure::read('Config.language')); 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: en 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja ... The very first instance of l10n seems to get the default language from core.php, but afterwards my beforeFilter is changing it. i18n holds on to just one instance of l10n though, which causes it to continue to use the default value. I opened a ticket for it:https://trac.cakephp.org/ticket/4509 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Cause for l10n/i18n not working?
Thanks. If this is the case, the documentation seriously needs an update, because it's all over the place on how to actually switch languages. I can only try your advise tomorrow though... Chrs, Dav On 21 Apr 2008, at 21:20, [EMAIL PROTECTED] wrote: I hope we are all talking about Cake 1.2 here? I am not sure that you should mess with l10n directly at all. When you do, you are effectively setting the language at different levels in the locale classes. This is what I believe is causing your problems. If you set the language in l10n, then i18n will not pick this up. define('DEFAULT_LANGUAGE', 'eng'); - deprecated, use Configure::write() Configure::write('Config.language', 'eng'); - sets the language. This value is used by i18n. I can switch languages in my app by resetting this value in beforeFilter. No need to call up an instance of l10n. If you want to switch it on the fly during rendering (don't know why really, but)... then it is another matter since i18n does not recheck the config once it has been setup. Then you need to get the current instance of i18n and set the language there: App::import('Core', 'i18n'); $i18n = I18n::getInstance(); $i18n-l10n-get($lang); hope this helps. /Martin On Apr 21, 12:28 pm, francky06l [EMAIL PROTECTED] wrote: I use the l10n/i18n to set language, my method is close to yours except that I set the language using : $l10n = new L10n(); $l10n-__setLanguage($lang) hth On Apr 21, 8:51 am, David Christopher Zentgraf [EMAIL PROTECTED] wrote: This seems to be the cause of a lot of complaints about l10n/i18n not working. I set up two languages in my app: 'eng' and 'jpn'. In core.php I added: define('DEFAULT_LANGUAGE', 'eng'); Configure::write('Config.language', 'en'); In my app_controller beforeFilter: $lang = $this-Auth-user('pref_lang'); // user pref saved in the DB $this-L10n-get($lang); // Config.language gets set to 'ja' here I put a debug on line 124 of i18n.php: Debugger::log('l10n instance: '.$_this-l10n-locale.', Configure: '.Configure::read('Config.language')); 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: en 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja ... The very first instance of l10n seems to get the default language from core.php, but afterwards my beforeFilter is changing it. i18n holds on to just one instance of l10n though, which causes it to continue to use the default value. I opened a ticket for it:https://trac.cakephp.org/ticket/4509 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Cause for l10n/i18n not working?
That sure seems to explain A LOT. Thanks so very much for posting that. On Mon, Apr 21, 2008 at 8:20 AM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I hope we are all talking about Cake 1.2 here? I am not sure that you should mess with l10n directly at all. When you do, you are effectively setting the language at different levels in the locale classes. This is what I believe is causing your problems. If you set the language in l10n, then i18n will not pick this up. define('DEFAULT_LANGUAGE', 'eng'); - deprecated, use Configure::write() Configure::write('Config.language', 'eng'); - sets the language. This value is used by i18n. I can switch languages in my app by resetting this value in beforeFilter. No need to call up an instance of l10n. If you want to switch it on the fly during rendering (don't know why really, but)... then it is another matter since i18n does not recheck the config once it has been setup. Then you need to get the current instance of i18n and set the language there: App::import('Core', 'i18n'); $i18n = I18n::getInstance(); $i18n-l10n-get($lang); hope this helps. /Martin On Apr 21, 12:28 pm, francky06l [EMAIL PROTECTED] wrote: I use the l10n/i18n to set language, my method is close to yours except that I set the language using : $l10n = new L10n(); $l10n-__setLanguage($lang) hth On Apr 21, 8:51 am, David Christopher Zentgraf [EMAIL PROTECTED] wrote: This seems to be the cause of a lot of complaints about l10n/i18n not working. I set up two languages in my app: 'eng' and 'jpn'. In core.php I added: define('DEFAULT_LANGUAGE', 'eng'); Configure::write('Config.language', 'en'); In my app_controller beforeFilter: $lang = $this-Auth-user('pref_lang'); // user pref saved in the DB $this-L10n-get($lang); // Config.language gets set to 'ja' here I put a debug on line 124 of i18n.php: Debugger::log('l10n instance: '.$_this-l10n-locale.', Configure: '.Configure::read('Config.language')); 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: en 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja ... The very first instance of l10n seems to get the default language from core.php, but afterwards my beforeFilter is changing it. i18n holds on to just one instance of l10n though, which causes it to continue to use the default value. I opened a ticket for it:https://trac.cakephp.org/ticket/4509 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Cause for l10n/i18n not working?
Unfortunately, this doesn't seem to work. Configure::write('Config.language', 'eng'); - sets the language. This value is used by i18n. I've tried this in my app_controller's beforeFilter, but it doesn't change anything. The problem persists as described before, i18n only seems to pick up the initial setting in core.php, any subsequent changes don't register. App::import('Core', 'i18n'); $i18n = I18n::getInstance(); $i18n-l10n-get($lang); This didn't work either. My debugging log showed that the locale actually did change in the i18n/l10n instance, it still output the language initially set in core.php though. I hope we are all talking about Cake 1.2 here? Sorry, yes, we are, a very recent SVN checkout even. I double checked that I have the latest version of both i18n.php and l10n.php available. Chrs, Dav On 21 Apr 2008, at 21:20, [EMAIL PROTECTED] wrote: I hope we are all talking about Cake 1.2 here? I am not sure that you should mess with l10n directly at all. When you do, you are effectively setting the language at different levels in the locale classes. This is what I believe is causing your problems. If you set the language in l10n, then i18n will not pick this up. define('DEFAULT_LANGUAGE', 'eng'); - deprecated, use Configure::write() Configure::write('Config.language', 'eng'); - sets the language. This value is used by i18n. I can switch languages in my app by resetting this value in beforeFilter. No need to call up an instance of l10n. If you want to switch it on the fly during rendering (don't know why really, but)... then it is another matter since i18n does not recheck the config once it has been setup. Then you need to get the current instance of i18n and set the language there: App::import('Core', 'i18n'); $i18n = I18n::getInstance(); $i18n-l10n-get($lang); hope this helps. /Martin On Apr 21, 12:28 pm, francky06l [EMAIL PROTECTED] wrote: I use the l10n/i18n to set language, my method is close to yours except that I set the language using : $l10n = new L10n(); $l10n-__setLanguage($lang) hth On Apr 21, 8:51 am, David Christopher Zentgraf [EMAIL PROTECTED] wrote: This seems to be the cause of a lot of complaints about l10n/i18n not working. I set up two languages in my app: 'eng' and 'jpn'. In core.php I added: define('DEFAULT_LANGUAGE', 'eng'); Configure::write('Config.language', 'en'); In my app_controller beforeFilter: $lang = $this-Auth-user('pref_lang'); // user pref saved in the DB $this-L10n-get($lang); // Config.language gets set to 'ja' here I put a debug on line 124 of i18n.php: Debugger::log('l10n instance: '.$_this-l10n-locale.', Configure: '.Configure::read('Config.language')); 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: en 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja 2008-04-21 15:34:44 Debug: l10n instance: eng, Configure: ja ... The very first instance of l10n seems to get the default language from core.php, but afterwards my beforeFilter is changing it. i18n holds on to just one instance of l10n though, which causes it to continue to use the default value. I opened a ticket for it:https://trac.cakephp.org/ticket/4509 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---