Changes for page Development-Localization and Internationalization
Last modified by Pascal Robert on 2015/05/04 04:24
From version 58.1
edited by Pascal Robert
on 2012/02/11 08:39
on 2012/02/11 08:39
Change comment:
There is no comment for this version
To version 54.1
edited by Ramsey Gurley
on 2010/02/02 23:01
on 2010/02/02 23:01
Change comment:
There is no comment for this version
Summary
-
Page properties (3 modified, 0 added, 0 removed)
Details
- Page properties
-
- Title
-
... ... @@ -1,1 +1,1 @@ 1 -Development-Localization and Internationalization 1 +Web Applications-Development-Localization and Internationalization - Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. probert1 +XWiki.ramsey - Content
-
... ... @@ -1,6 +1,6 @@ 1 1 == Unicode == 2 2 3 -See also: [[UTF-8 Encoding Tips >>doc:UTF-8 Encoding Tips]]3 +See also: [[UTF-8 Encoding Tips]] 4 4 5 5 To Enable Unicode for your WO app, add the following to your application constructor: 6 6 ... ... @@ -14,7 +14,7 @@ 14 14 15 15 Then you just need to tell the browser. Make all your .wo pages include this meta tag in their HTML: 16 16 17 -{{code 0="xml"}}17 +{{code value="xml"}} 18 18 19 19 <html> 20 20 <head> ... ... @@ -64,23 +64,23 @@ 64 64 65 65 {{/code}} 66 66 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>>url:http://wocommunity.org/documents/javadoc/WebObjects/5.4.2/com/webobjects/appserver/WORequest.html||shape="rect"]] 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://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. 68 68 69 69 With Jesse's code and this extension, you will be able to handle UTF-8 character data correctly in your WO application. 70 70 71 -If you use localized strings in your UTF-8 application you may also check out Project Wonder's [[ERXLocalizer>> doc:WOnder-ERXLocalizer]] class.71 +If you use localized strings in your UTF-8 application you may also check out Project Wonder's [[ERXLocalizer>>WOnder-ERXLocalizer]] class. 72 72 73 -=== Project Localization tips === 73 +=== Project Localization tips [[~~ramsey]] === 74 74 75 75 The following are some tips and suggestions for localizing a project in WOLips using Project Wonder. 76 76 77 77 ===== Eclipse Default Encoding ===== 78 78 79 -I prefer to keep my entire project in UTF-8 format for consistency. You can set that in your Eclipse General->Workspace preferences. The exception, of course will be your Localizable.strings files. Those have to be in UTF-16 format. 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. 79 +I prefer to keep my entire project in UTF-8 format for consistency. You can set that in your Eclipse General->Workspace preferences. The exception, of course will be your Localizable.strings files. Those have to be in UTF-16 format. 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. 80 80 81 81 ===== Properties file ===== 82 82 83 -Let's say your project will be available in English and Japanese. You'll want to include the following in your Project->Resources->Properties file: 83 +Let's say your project will be available in English and Japanese. You'll want to include the following in your Project->Resources->Properties file: 84 84 85 85 {{noformat}} 86 86 ... ... @@ -103,8 +103,8 @@ 103 103 104 104 {{/noformat}} 105 105 106 - (% style="color: rgb(51,51,51);" %)The other changes are then in the er.extensions.ERXLocalizer.availableLanguages and ERXLanguages:(%%)107 - (% style="color: rgb(51,51,51);" %)In the above case after adding canadian french these would change in: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 108 109 109 {{noformat}} 110 110 ... ... @@ -112,48 +112,36 @@ 112 112 113 113 {{/noformat}} 114 114 115 -(% style="color: rgb(51,51,51);" %)Localized formatters use this property: 116 - 117 -{{noformat}} 118 - 119 -er.extensions.ERXLocalizer.useLocalizedFormatters=false 120 - 121 -{{/noformat}} 122 - 123 123 ===== Localized strings and components ===== 124 124 125 -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: 126 126 127 - >Project->Resources->English.lproj->Localizable.strings128 - >Project->Resources->Japanese.lproj->Localizable.strings129 - >Project->Resources->French_CA.lproj->Localizable.strings119 +Project->Resources->English.lproj->Localizable.strings 120 +Project->Resources->Japanese.lproj->Localizable.strings 121 +Project->Resources->French//CA.lproj->Localizable.strings// 130 130 131 -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. 123 +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. 132 132 133 -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 134 134 135 ->Project->Components->Main WO 127 +> Project->Components->Main WO 136 136 137 -You would right-click->Refactor->Move it to 129 +You would right-click->Refactor->Move it to 138 138 139 ->Project->Resources->English.lproj->Main WO 131 +> Project->Resources->English.lproj->Main WO 140 140 141 -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. 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. 142 142 143 143 Your layout would end up something like this: 144 144 145 -[[image: attach:ERXLocalizerEclipseLayout.png]]137 +[[image:ERXLocalizerEclipseLayout.png]] 146 146 147 147 ===== Localized EOAttributes ===== 148 148 149 -In Wonder, it is also possible to localize attributes. Let's say wehaveanentity//Blog// withan attribute//content// thatwe want tolocalize. This will berealized by not creating a column //content//in the database but a column for each specified language we wanti.e. //content_en//, //content_fr//, ...141 +In Wonder, it is also possible to localize attributes. There are two requisites: 150 150 151 - To tell EOFthat we want a specific attributelocalizedyou have to adda keyERXLanguages toitsuser info.143 +First add ERXLanguages to your Properties file: 152 152 153 -[[image:attach:ERXLocalizerUserInfo_correct.png]] 154 - 155 -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: 156 - 157 157 {{noformat}} 158 158 159 159 ERXLanguages = (en,jp,fr_ca) ... ... @@ -160,20 +160,17 @@ 160 160 161 161 {{/noformat}} 162 162 163 - Allattributesthat shoulduse thoseglobalsettings must have akey//ERXLanguages//intheiruserinfowith a type **different** to//Array//.Its value can be anythingas onlythepresence of the keyis ofmportance.The order thathe languages are applied to an attributeis:151 +Then, for the attribute you'd like to localize, add the ERXLanguages key to the UserInfo for that specific attribute: 164 164 165 -* attribute user info with an array for ERXLanguages 166 -* if type of found user info is not an array then get array from key ERXLanguages from user info of the model 167 -* if user info of the model has no key ERXLanguages look for a property ERXLanguages in your property files 168 -* if no property ERXLanguages is found ignore localization 153 +[[image:ERXLocalizerUserInfo.png]] 169 169 170 170 ===== Direct Actions ===== 171 171 172 -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: 157 +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: 173 173 174 174 {{code}} 175 175 176 -@Override 161 + @Override 177 177 public WOActionResults performActionNamed(String actionName) { 178 178 if(!context().hasSession()) { 179 179 ERXLocalizer localizer = ... ... @@ -183,22 +183,17 @@ 183 183 return super.performActionNamed(actionName); 184 184 } 185 185 171 + 186 186 {{/code}} 187 187 188 -That should give the user their browser's default language setting instead of your server's default language setting until a session is created. 174 +That should give the user their browser's default language setting instead of your server's default language setting until a session is created. 189 189 190 -[[ attach:WO.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.176 +[[^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. 191 191 192 192 ===== Database setup ===== 193 193 194 -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: 180 +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: 195 195 196 196 jdbc:mysql:~/~/localhost/mydatabase?capitalizeTypenames=true&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8 197 197 198 -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. 199 - 200 -===== Localization presentation from WOWODC West 2009 ===== 201 - 202 -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>>url:http://www.wocommunity.org/podcasts/wowodc/west09/WOWODCW09-Localization.mov||shape="rect"]]. 203 - 204 - 184 +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.