Last modified by Pascal Robert on 2015/05/04 04:24

From version 25.1
edited by Ramsey Gurley
on 2008/07/25 16:55
Change comment: There is no comment for this version
To version 24.1
edited by David Avendasora
on 2011/05/03 04:45
Change comment: There is no comment for this version

Summary

Details

Page properties
Title
... ... @@ -1,1 +1,1 @@
1 -Web Applications-Development-Localization and Internationalization
1 +Development-Localization and Internationalization
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.ramsey
1 +XWiki.avendasora
Content
... ... @@ -1,5 +1,7 @@
1 1  == Unicode ==
2 2  
3 +See also: [[UTF-8 Encoding Tips>>UTF-8 Encoding Tips]]
4 +
3 3  To Enable Unicode for your WO app, add the following to your application constructor:
4 4  
5 5  {{code}}
... ... @@ -62,13 +62,13 @@
62 62  
63 63  {{/code}}
64 64  
65 -To make WOFileUpload components working I also had to add the launch parameter WOUseLegacyMultipartParser true to my application. This launch parameter forces the parsing of all form values, the first time WORequest.formValues is called. See the [[apple developer documentation>>http://developer.apple.com/documentation/WebObjects/Reference/api/com/webobjects/appserver/WORequest.html]] for additional information. Without WOUseLegacyMultipartParser true I had serious problems in my applications using a WOFileUpload component because the bindings //data// and //filePath// have been emptied after a form POST.
67 +To make WOFileUpload components working I also had to add the launch parameter WOUseLegacyMultipartParser true to my application. This launch parameter forces the parsing of all form values, the first time WORequest.formValues is called. See the [[apple developer documentation>>http://webobjects.mdimension.com/javadoc/WebObjects/5.4.2/com/webobjects/appserver/WORequest.html]] for additional information. Without WOUseLegacyMultipartParser true I had serious problems in my applications using a WOFileUpload component because the bindings //data// and //filePath// have been emptied after a form POST.
66 66  
67 67  With Jesse's code and this extension, you will be able to handle UTF-8 character data correctly in your WO application.
68 68  
69 69  If you use localized strings in your UTF-8 application you may also check out Project Wonder's [[ERXLocalizer>>WOnder-ERXLocalizer]] class.
70 70  
71 -=== Project Localization tips [[~~ramsey]] ===
73 +=== Project Localization tips ===
72 72  
73 73  The following are some tips and suggestions for localizing a project in WOLips using Project Wonder.
74 74  
... ... @@ -93,52 +93,70 @@
93 93  
94 94  {{/noformat}}
95 95  
98 +Note that if you need to customize the locale for a language, such as Canadian French, you can do so with this property:
99 +
100 +{{noformat}}
101 +
102 +er.extensions.ERXLocalizer.French_CA.locale = fr_ca
103 +
104 +{{/noformat}}
105 +
106 +The other changes are then in the er.extensions.ERXLocalizer.availableLanguages and ERXLanguages:
107 +In the above case after adding canadian french these would change in:
108 +
109 +{{noformat}}
110 +
111 +er.extensions.ERXLocalizer.availableLanguages=(English,Japanese,French_CA)
112 +
113 +{{/noformat}}
114 +
96 96  ===== Localized strings and components =====
97 97  
98 -For each language available, you will need a corresponding Localizable.strings file. This file should be located in Projects->Resources->"Lang".lproj directory. In these directories, you'll store localized resources such as Localizable.strings files and localized components. So, continuing with the above example, you should create two new Localizable.strings files in the following places in your project directory:
117 +For each language available, you will need a corresponding Localizable.strings file. This file should be located in Projects->Resources->"Lang".lproj directory. In these directories, you'll store localized resources such as Localizable.strings files and localized components. So, continuing with the above example, you should create two new Localizable.strings files in the following places in your project directory:
99 99  
100 100  Project->Resources->English.lproj->Localizable.strings
101 101  Project->Resources->Japanese.lproj->Localizable.strings
121 +Project->Resources->French//CA.lproj->Localizable.strings//
102 102  
103 103  As mentioned earlier, it's recommended that these be in UTF-16 format. You can do that by right clicking on the file in WOLips and selecting "Properties." In the resources panel, change from the project default encoding to UTF-16.
104 104  
105 -If you have any components that need localizing, then you should relocate that component from your Project->Components folder into the appropriate Lang.lproj folder. Then make a copy of the component into the remaining lproj directories and you can begin the process of localizing the component. You do not need more than one copy of the associated API or java file. You only need duplicates of the WO. So, as an example, if you wanted to localize
125 +If you have any components that need localizing, then you should relocate that component from your Project->Components folder into the appropriate Lang.lproj folder. Then make a copy of the component into the remaining lproj directories and you can begin the process of localizing the component. You do not need more than one copy of the associated API or java file. You only need duplicates of the WO. So, as an example, if you wanted to localize
106 106  
107 107  > Project->Components->Main WO
128 +>\\
129 +>>You would right-click->Refactor->Move it to
108 108  
109 -You would right-click->Refactor->Move it to
131 +> Project->Resources->English.lproj->Main WO
132 +>\\
133 +>>and then right-click->Copy it from English.lproj and right-click->Paste it into Japanese.lproj. At this point, when you open the component in WOLips, there will be a tab at the bottom of the component editor view that allows you to switch back and forth between different localized versions of that component.
110 110  
111 -> Project->Resources->English.lproj->Main WO
135 +Your layout would end up something like this:
112 112  
113 -and then right-click->Copy it from English.lproj and right-click->Paste it into Japanese.lproj. At this point, when you open the component in WOLips, there will be a tab at the bottom of the component editor view that allows you to switch back and forth between different localized versions of that component.
137 +[[image:ERXLocalizerEclipseLayout.png]]
114 114  
115 -===== Component HTML =====
139 +===== Localized EOAttributes =====
116 116  
117 -Given the info on this page already, this is a little redundant... but here's what the start of my PageWrapper looks like:
141 +In Wonder, it is also possible to localize attributes. Let's say we have an entity //Blog// with an attribute //content// that we want to localize. This will be realized by not creating a column //content// in the database but a column for each specified language we want i.e. //content//en//, //content//fr//, ...
118 118  
119 -{{code}}
143 +To tell EOF that we want a specific attribute localized you have to add a key ERXLanguages to its user info.
120 120  
121 -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
122 - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
145 +[[image:ERXLocalizerUserInfo_correct.png||border="1"]]
123 123  
124 -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang='<wo:localized value = "ls_lang" />' lang='<wo:localized value = "ls_lang" />'>
125 -<head>
126 - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
147 +In this example we set the type to //Array// and add an item for each needed language setting its value to the language code. This must be done for each attribute in our model we want to localize. If you have many localized attributes that have the very same list of languages and you will likely be changing that list in the future you can define your language list either for a whole model or for all models instead. The first way to specify a per model language list is to put an ERXLanguages key into the user info of the model. For a global setting put that key into your property file:
127 127  
128 -{{/code}}
149 +{{noformat}}
129 129  
130 -and in the Localizable.strings file, I keep a language code for each language
151 +ERXLanguages = (en,jp,fr_ca)
131 131  
132 -{{code}}
153 +{{/noformat}}
133 133  
134 -{
135 - "ls_lang" = "en";
136 -}
155 +All attributes that should use those global settings must have a key //ERXLanguages// in their user info with a type **different** to&nbsp;//Array//. Its value can be anything as only the presence of the key is of importance. The order that the languages are applied to an attribute is:
137 137  
138 -{{/code}}
157 +* attribute user info with an array for ERXLanguages
158 +* if type of found user info is not an array then get array from key ERXLanguages from user info of the model
159 +* if user info of the model has no key ERXLanguages look for a property ERXLanguages in your property files
160 +* if no property ERXLanguages is found ignore localization
139 139  
140 -You'll also notice the "ls//" prefix. You'll definitely want to prefix with something unique so you can do a project-wide search for your keys without difficulty.//
141 -
142 142  ===== Direct Actions =====
143 143  
144 144  If you are defaulting to direct actions, you may not have a session. If you do not have a session, the server will return the default language specified in the Properties mentioned above. If you're using direct actions and you don't like that behavior, you can stick this in your direct action class:
... ... @@ -160,6 +160,8 @@
160 160  
161 161  That should give the user their browser's default language setting instead of your server's default language setting until a session is created.
162 162  
183 +[[Development-Localization and Internationalization^LocalizerTest.zip]] is an example application demonstrating the sessionless use of the localizer with localized strings and localized components, storing the language state in a cookie.
184 +
163 163  ===== Database setup =====
164 164  
165 165  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:
... ... @@ -167,3 +167,7 @@
167 167  jdbc:mysql:~/~/localhost/mydatabase?capitalizeTypenames=true&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8
168 168  
169 169  The database itself is set to default to "UTF8" encoding. (No hyphen in UTF8 for MySQL) You can set that in the "Options" pane of MySQL Administrator.app under the "Advanced" popup menu item in the "Def. char set" field. 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.
192 +
193 +===== Localization presentation from WOWODC West 2009 =====
194 +
195 +Guido Neitzer did a localization presentation at WOWODC West 2009 that give a good overview of how to localize your apps. The presentation is available [[here>>http://www.wocommunity.org/podcasts/wowodc/west09/WOWODCW09-Localization.mov]].