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: Thu, 12 Jun 2008 19:46:30 -0400
Hi Drew,
Since I'm not having fun at WWDC, I'll give this one a shot :-)
Have you set your application encoding? I'm using UTF-8. It works
fine for Farsi. I may be wrong, but I don't think there's any reason
you need to use UTF-16, except in your Localized.strings file... that
has to be UTF-16. So in my properties file I set,
# Localization
er.extensions.ERXLocalizer.defaultLanguage=English
er
.extensions
.ERXLocalizer
.fileNamesToWatch=("Localizable.strings","ValidationTemplate.strings")
er.extensions.ERXLocalizer.availableLanguages=(English,Japanese)
er
.extensions
.ERXLocalizer.frameworkSearchPath=(app,ERDirectToWeb,ERExtensions)
And last but not least
# Project Encoding
er.extensions.ERXApplication.DefaultEncoding=UTF8
And in my Application's constructor
WOMessage.setDefaultEncoding("UTF8");
I think that should answer your immediate question, but I'll brain
dump on you since I haven't had the chance to put together a localized
project example to share just yet... I hope you won't mind ;-)
--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.
--Set up your database--
Outside of this, if you are using a database, you'll need to make sure
that is encoded properly as well. I'm using MySQL, so I have in my
EOModel:
jdbc:mysql://localhost/mydatabasetable?
capitalizeTypenames
=true&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8
The database itself is set to default to UTF8. In MySQL
Administrator.app you find that here:
If you don't get the image file, it's in the Options pane of MySQL
Administrator.app under the "Advanced" popup menu item. Of course,
you'll need to use the correct database types too, meaning don't use a
blob for text storage. Use varchar and longtext (varcharLarge is the
name of the Wonder prototype) instead.
--Project layout--
You've already discovered that your Localized.strings file goes in
your Project->Resources->(Language).lproj folders, but you can also
localize an entire component if necessary. Just copy the .wo into
those same folders, leaving the .api file in the Components folder.
You only need one api file and one java file per component, but you'll
need one copy of the component for each .lproj sub-directory. When
you do this, you only need to open one and you'll have tabs at the
bottom of your component view in WOLips to all the others. Very
convenient.
--Eclipse defaults--
You've probably done this already, but I set my default encoding in
Eclipse to UTF-8 as well. That setting is located in General-
>Workspace in the Eclipse prefs. I generally get warnings about the
WOO file for my initial Main component whenever I create a new
project, but if you right-click your Main.wo you'll see "Properties"
at the very bottom of the contextual menu. Open that and flip your
encoding between project default and UTF-8, save it, then open it back
up and return it to the project default and the problem should go
away. This is also how you set your Localized.strings file to UTF-16
even if the rest of your project is not UTF-16.
--WOComponent html--
I think you've got this one covered already... but here's what the
start of my PageWrapper looks like:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang='<wo:localized
value = "ls_lang" />' lang='<wo:localized value = "ls_lang" />'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
--File Uploads?--
I think that covers everything except file uploads and Helmut is
probably a better person to ask. He mentions briefly how to fix a
problem here:
http://wiki.objectstyle.org/confluence/display/WO/Web+Applications-Development-Localization+and+Internationalization
But I have not yet actually tried file uploading in my localized
project just yet.
Well, I hope that was helpful :-)
On Jun 12, 2008, at 6:10 PM, Drew Thoeni wrote:
Cool. I got it working. Was not setting the localizer in the session.
But, now that English and Spanish are working, I'm having a problem
with Arabic. If I use the Mac's Qwerty Arabic keyboard option, I can
type some characters into the Localizable.strings file (which is
saved UTF-16) and the characters look as expected. But, when they
get replaced into the delivered web page, I get a bunch of question
marks "??? ?? ???"
I've also changed the meta tag in the component HTML: <meta http-
equiv="Content-Type" content="text/html; charset=utf-16"/>
Any one done any work with four-byte languages like Arabic or Chinese?
Best,
Drew
On Jun 12, 2008, at 3:55 PM, David Holt wrote:
Hi Drew,
On 12-Jun-08, at 12:19 PM, Drew Thoeni wrote:
My mail box remains empty on this question.
Everyone is having fun in San Francisco!
Is there anyone with localization experience that could suggest
what I'm doing incorrectly?
Not too much, but we will see what I can offer....
I'm trying to send back the language of the users pre-selected
choice (store in database). But the
ERXLocalizer.setDefaultLangauge() seems to have no effect.
This should be no problem if you're using Wonder.
Regards,
Drew
On Jun 10, 2008, at 7:46 AM, Drew Thoeni wrote:
I'm using ERXLocalizer and am using, base on Chuck's Practical
Webobjects recommendations, the "replace string via
localizable.strings" method instead of the "replicate each
component method."
Perfect.
I want the user to select their language of preference in the
application so I store that in the database.
Check out ERXSession for the code used to manipulate the Localizers
that are available and the one that is chosen...
In the session I use ERXLocalizer.setDefaultLanguage to set the
user's preference based on their stored preference. Code:
NSArray<String> languageArray = new NSArray( new Object[]
{"English", "Spanish"} );
ERXLocalizer.setAvailableLanguages( languageArray );
ERXLocalizer
.setDefaultLanguage
( session.currentUserLoggedIn.laguagePreference() );
I think you want "setLanguage(String language)"
Is your "laguagePreference() method named correctly? might have to
be "languagePreference"?
Have you tried setting the localization properties for Wonder
instead of initializing in your app? These properties are used in
BugTracker:
ERXLanguages = (en)
#er.extensions.ERXLocalizer.availableLanguages=(English,German)
er.extensions.ERXLocalizer.availableLanguages=(English)
er.extensions.ERXLocalizer.frameworkSearchPath=("app",
"BTBusinessLogic", "ERExtras", "ERDirectToWeb", "ERExtensions")
er.extensions.ERXLocalizer.fileNamesToWatch =
("Localizable.strings","ValidationTemplate.strings")
I believe, though, that WO is overriding this with the preference
from the browser. Since I'm testing from Safari (Mac) and have
the test computer running in English, I get the English
localization strings instead of the user-selected localization
strings.
What is the method to use to force the return of the language
selected by the user and ignore the browser? And, since I'm just
starting on this, if there are other tips on localization bug-a-
boos, I'd be thankful. (I've already changed the string files to
UTF-16, that helped).
All the Wonder frameworks are done with UTF-8. I think that is the
recommended encoding. I believe that this property will cover
everything for you:
er.extensions.ERXApplication.DefaultEncoding=UTF-8
You may want to take this subject to the Wonder list and/or check
out the Wonder archives where this is covered quite extensively.
David
Regards,
Drew
_______________________________________________
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
_______________________________________________
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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
@mac.com
This email sent to email@hidden
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