Re: Localization Help! (was Localizer Default vs. Browser)
Re: Localization Help! (was Localizer Default vs. Browser)
- Subject: Re: Localization Help! (was Localizer Default vs. Browser)
- From: Rams <email@hidden>
- Date: Sun, 20 Jul 2008 19:34:41 -0400
Hi yllan!
Without seeing your code, it's sorta hard for me to say what is wrong,
so I apologize if I am covering basic things you already know... :-)
I'll try to answer your question the best I can though!
On Jul 19, 2008, at 11:16 PM, Yung-Luen Lan wrote:
Hi Rams,
I'm quite confused about this code. I copied this to my DirectAction
class but it didn't work.
Keep in mind, this only works if you've defaulted to the direct action
handler and you have not created a session in your code. David LeBer
has a great series of articles on direct actions. If you haven't read
them already, the first one of the series is located here:
http://davidleber.net/?p=63
Now, just because you're using direct actions, that is no guarantee
you have not accidently created a session anyway. It's actually
pretty tough to not create them sometimes. I log all my sessions in
the Session constructor to eliminate confusion:
public Session() {
NSLog.out.appendln("Session created: " + sessionID());
}
If you have created a session, the browser's default language should
be presented thanks to ERXSession. The code below will be doing
nothing.
When there is no session, the language delivered to the browser should
be whatever you set with er.extensions.ERXLocalizer.defaultLanguage in
the properties file every time. The overridden performActionNamed()
method below is designed to change that behavior. If you've set the
default language to English in your properties file, your browser
language is set to English, and your app is delivering zh_CH... try
logging context().request().browserLanguages() and see what you get.
In my project, I have English.lproj, zh_TW.lproj, zh_CN.lproj.
I have my Properies file setup with:
er.extensions.ERXLocalizer.defaultLanguage=English
er
.extensions
.ERXLocalizer
.fileNamesToWatch=("Localizable.strings","ValidationTemplate.strings")
er.extensions.ERXLocalizer.availableLanguages=(English, zh_TW, zh_CN)
er
.extensions
.ERXLocalizer.frameworkSearchPath=(app,ERDirectToWeb,ERExtensions)
My system/browser is English. Default language is English. I print out
context().request().browserLanguages(), which is exactly English. But
at the top of my action, I print out session().languages() and got
zh_TW (Traditional Chinese) localizer.
Why the localizer change its language after the performActionNamed()
but before myAction actually being called?
Are you saying you tried something like this:
public WOActionResults performActionNamed(String actionName) {
if(!context().hasSession()) {
NSLog.out.appendln("1: " +
ERXLocalizer.currentLocalizer().language());
ERXLocalizer localizer =
ERXLocalizer
.localizerForLanguages(context().request().browserLanguages());
NSLog.out.appendln("2: " + localizer.language());
ERXLocalizer.setCurrentLocalizer(localizer);
NSLog.out.appendln("3: " +
ERXLocalizer.currentLocalizer().language());
}
WOActionResults woar = super.performActionNamed(actionName);
NSLog.out.appendln("4: " +
ERXLocalizer.currentLocalizer().language());
return woar;
}
And output something like:
1: English
2: English
3: English
4: zh_CH
? If not, try it, and let us know what you get :-)
My guess is, setup the current localizer not necessary change the
localizer of sessions. Any idea on how to make the code actually work?
If there's a session, and you want to change the localizer, then you'd
want to use ERXSession's setLanguage() or setLanguages() method. But
you wouldn't want to do that in the performActionNamed method.
Perhaps with a language popup and a component action tied to it?
I hope that helped. It should at least be a starting point. If you
are still having problems after trying the above suggestions, let me
know!
rg
Regards,
yllan
On Fri, Jun 13, 2008 at 7:46 AM, Rams <email@hidden> wrote:
--Direct Actions--
If you're using direct actions, you can stick this in your direct
action
class:
@Override
public WOActionResults performActionNamed(String actionName) {
if(!context().hasSession()) {
ERXLocalizer localizer =
ERXLocalizer
.localizerForLanguages(context().request().browserLanguages());
ERXLocalizer.setCurrentLocalizer(localizer);
}
return super.performActionNamed(actionName);
}
That will give the user their browser's default language instead of
your
server's default language if there is no session and their language
is
available. If you aren't defaulting to direct actions though, a
session is
going to be created, that will happen anyway, and this will be
superfluous.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden