Changes for page Development-Localization and Internationalization
Last modified by Pascal Robert on 2015/05/04 04:24
From version 60.1
edited by Johan Henselmans
on 2015/05/04 04:24
on 2015/05/04 04:24
Change comment:
Migrated to Confluence 5.3
To version 56.1
edited by David Holt
on 2011/06/10 19:20
on 2011/06/10 19:20
Change comment:
Moved latest addition to the "properties" section
Summary
-
Page properties (4 modified, 0 added, 0 removed)
-
Attachments (0 modified, 0 added, 4 removed)
Details
- Page properties
-
- Parent
-
... ... @@ -1,1 +1,0 @@ 1 -Localization - Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. johanhenselmans1 +XWiki.dholt - Tags
-
... ... @@ -1,1 +1,0 @@ 1 -internationalization|localization|favourite - Content
-
... ... @@ -1,10 +1,11 @@ 1 1 == Unicode == 2 2 3 -See also: [[ doc:UTF-8 Encoding Tips]]3 +See also: [[UTF-8 Encoding Tips>>UTF-8 Encoding Tips]] 4 4 5 5 To Enable Unicode for your WO app, add the following to your application constructor: 6 6 7 7 {{code}} 8 + 8 8 WOMessage.setDefaultEncoding("UTF8"); 9 9 10 10 {{/code}} ... ... @@ -13,7 +13,8 @@ 13 13 14 14 Then you just need to tell the browser. Make all your .wo pages include this meta tag in their HTML: 15 15 16 -{{code 0="xml"}} 17 +{{code value="xml"}} 18 + 17 17 <html> 18 18 <head> 19 19 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> ... ... @@ -26,6 +26,7 @@ 26 26 Great tip - here is a simple method call you can stick in your Application object to automatically achieve the results outlined above: 27 27 28 28 {{code}} 31 + 29 29 private boolean enableUTFEncoding = false; 30 30 31 31 public void enableUTFEncoding() { ... ... @@ -50,6 +50,7 @@ 50 50 To make sure that UTF-8 is supported in multipart forms as well, you have to add the following code to your Application object: 51 51 52 52 {{code}} 56 + 53 53 public WORequest createRequest(String aMethod, String aURL, String anHTTPVersion, 54 54 NSDictionary someHeaders, NSData aContent, NSDictionary someInfo) { 55 55 WORequest newRequest = super.createRequest(aMethod, aURL, anHTTPVersion, ... ... @@ -60,11 +60,11 @@ 60 60 61 61 {{/code}} 62 62 63 -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://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. 64 64 65 65 With Jesse's code and this extension, you will be able to handle UTF-8 character data correctly in your WO application. 66 66 67 -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. 68 68 69 69 === Project Localization tips === 70 70 ... ... @@ -72,13 +72,14 @@ 72 72 73 73 ===== Eclipse Default Encoding ===== 74 74 75 -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. 76 76 77 77 ===== Properties file ===== 78 78 79 -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: 80 80 81 81 {{noformat}} 86 + 82 82 # Localization 83 83 er.extensions.ERXLocalizer.defaultLanguage=English 84 84 er.extensions.ERXLocalizer.fileNamesToWatch=("Localizable.strings","ValidationTemplate.strings") ... ... @@ -93,21 +93,31 @@ 93 93 Note that if you need to customize the locale for a language, such as Canadian French, you can do so with this property: 94 94 95 95 {{noformat}} 101 + 96 96 er.extensions.ERXLocalizer.French_CA.locale = fr_ca 97 97 98 98 {{/noformat}} 99 99 100 -(% style="color: rgb(51,51,51);" %)The other changes are then in the er.extensions.ERXLocalizer.availableLanguages and ERXLanguages:(%%) 101 - (% style="color: rgb(51,51,51);" %)In the above case after adding canadian french these would change in: 106 +{{color value="#333333"}} 107 +The other changes are then in the er.extensions.ERXLocalizer.availableLanguages and ERXLanguages: 108 +{{/color}} 102 102 110 +{{color value="#333333"}} 111 +In the above case after adding canadian french these would change in: 112 +{{/color}} 113 + 103 103 {{noformat}} 115 + 104 104 er.extensions.ERXLocalizer.availableLanguages=(English,Japanese,French_CA) 105 105 106 106 {{/noformat}} 107 107 108 -(% style="color: rgb(51,51,51);" %)Localized formatters use this property: 120 +{{color value="#333333"}} 121 +Localized formatters use this property: 122 +{{/color}} 109 109 110 110 {{noformat}} 125 + 111 111 er.extensions.ERXLocalizer.useLocalizedFormatters=false 112 112 113 113 {{/noformat}} ... ... @@ -114,44 +114,45 @@ 114 114 115 115 ===== Localized strings and components ===== 116 116 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: 132 +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: 118 118 119 - >Project->Resources->English.lproj->Localizable.strings120 - >Project->Resources->Japanese.lproj->Localizable.strings121 - >Project->Resources->French_CA.lproj->Localizable.strings134 +Project->Resources->English.lproj->Localizable.strings 135 +Project->Resources->Japanese.lproj->Localizable.strings 136 +Project->Resources->French//CA.lproj->Localizable.strings// 122 122 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. 138 +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. 124 124 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 140 +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 126 126 127 ->Project->Components->Main WO 142 +> Project->Components->Main WO 143 +>\\ 144 +>>You would right-click->Refactor->Move it to 128 128 129 -You would right-click->Refactor->Move it to 146 +> Project->Resources->English.lproj->Main WO 147 +>\\ 148 +>>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. 130 130 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. 134 - 135 135 Your layout would end up something like this: 136 136 137 -[[image: attach:ERXLocalizerEclipseLayout.png]]152 +[[image:ERXLocalizerEclipseLayout.png]] 138 138 139 139 ===== Localized EOAttributes ===== 140 140 141 -In Wonder, it is also possible to localize attributes. Let's say we have an entity //Blog// _en//, //content_fr//, ...156 +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//, ... 142 142 143 143 To tell EOF that we want a specific attribute localized you have to add a key ERXLanguages to its user info. 144 144 145 -[[image: attach:ERXLocalizerUserInfo_correct.png]]160 +[[image:ERXLocalizerUserInfo_correct.png||border="1"]] 146 146 147 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: 148 148 149 149 {{noformat}} 165 + 150 150 ERXLanguages = (en,jp,fr_ca) 151 151 152 152 {{/noformat}} 153 153 154 -All attributes that should use those global settings must have a key //ERXLanguages// in their user info with a type **different** to 170 +All attributes that should use those global settings must have a key //ERXLanguages// in their user info with a type **different** to //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: 155 155 156 156 * attribute user info with an array for ERXLanguages 157 157 * if type of found user info is not an array then get array from key ERXLanguages from user info of the model ... ... @@ -160,9 +160,10 @@ 160 160 161 161 ===== Direct Actions ===== 162 162 163 -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: 179 +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: 164 164 165 165 {{code}} 182 + 166 166 @Override 167 167 public WOActionResults performActionNamed(String actionName) { 168 168 if(!context().hasSession()) { ... ... @@ -177,18 +177,20 @@ 177 177 178 178 That should give the user their browser's default language setting instead of your server's default language setting until a session is created. 179 179 180 -[[ 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.197 +[[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. 181 181 182 182 ===== Database setup ===== 183 183 184 -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: 201 +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: 185 185 186 186 jdbc:mysql:~/~/localhost/mydatabase?capitalizeTypenames=true&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8 187 187 188 -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. 205 +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. 189 189 190 190 ===== Localization presentation from WOWODC West 2009 ===== 191 191 192 -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/WOWODC09W-Localization.mov||shape="rect"]].209 +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]]. 193 193 194 - 211 +=== === 212 + 213 +
- ERXLocalizerEclipseLayout.png
-
- Author
-
... ... @@ -1,1 +1,0 @@ 1 -XWiki.XWikiGuest - Size
-
... ... @@ -1,1 +1,0 @@ 1 -15.8 KB - Content
- ERXLocalizerUserInfo.png
-
- Author
-
... ... @@ -1,1 +1,0 @@ 1 -XWiki.XWikiGuest - Size
-
... ... @@ -1,1 +1,0 @@ 1 -74.0 KB - Content
- ERXLocalizerUserInfo_correct.png
-
- Author
-
... ... @@ -1,1 +1,0 @@ 1 -XWiki.XWikiGuest - Size
-
... ... @@ -1,1 +1,0 @@ 1 -66.3 KB - Content
- LocalizerTest.zip
-
- Author
-
... ... @@ -1,1 +1,0 @@ 1 -XWiki.XWikiGuest - Size
-
... ... @@ -1,1 +1,0 @@ 1 -53.0 KB - Content