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

From version 41.1
edited by Pascal Robert
on 2007/09/03 18:51
Change comment: There is no comment for this version
To version 42.1
edited by Ramsey Gurley
on 2008/07/25 16:53
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.probert
1 +XWiki.ramsey
Content
... ... @@ -67,3 +67,103 @@
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 +
71 +=== Project Localization tips [[~~ramsey]] ===
72 +
73 +The following are some tips and suggestions for localizing a project in WOLips using Project Wonder.
74 +
75 +===== Eclipse Default Encoding =====
76 +
77 +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.
78 +
79 +===== Properties file =====
80 +
81 +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:
82 +
83 +{{noformat}}
84 +
85 +# Localization
86 +er.extensions.ERXLocalizer.defaultLanguage=English
87 +er.extensions.ERXLocalizer.fileNamesToWatch=("Localizable.strings","ValidationTemplate.strings")
88 +er.extensions.ERXLocalizer.availableLanguages=(English,Japanese)
89 +er.extensions.ERXLocalizer.frameworkSearchPath=(app,ERDirectToWeb,ERExtensions)
90 +
91 +# Project Encoding
92 +er.extensions.ERXApplication.DefaultEncoding=UTF-8
93 +
94 +{{/noformat}}
95 +
96 +===== Localized strings and components =====
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:
99 +
100 +Project->Resources->English.lproj->Localizable.strings
101 +Project->Resources->Japanese.lproj->Localizable.strings
102 +
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 +
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
106 +
107 +> Project->Components->Main WO
108 +
109 +You would right-click->Refactor->Move it to
110 +
111 +> Project->Resources->English.lproj->Main WO
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.
114 +
115 +===== Component HTML =====
116 +
117 +And, although this is a little redundant... here's what the start of my PageWrapper looks like:
118 +
119 +{{code}}
120 +
121 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
122 + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
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"/>
127 +
128 +{{/code}}
129 +
130 +and in the Localizable.strings file, I keep a language code for each language
131 +
132 +{{code}}
133 +
134 +{
135 + "ls_lang" = "en";
136 +}
137 +
138 +{{/code}}
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 +===== Direct Actions =====
143 +
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:
145 +
146 +{{code}}
147 +
148 + @Override
149 + public WOActionResults performActionNamed(String actionName) {
150 + if(!context().hasSession()) {
151 + ERXLocalizer localizer =
152 + ERXLocalizer.localizerForLanguages(context().request().browserLanguages());
153 + ERXLocalizer.setCurrentLocalizer(localizer);
154 + }
155 + return super.performActionNamed(actionName);
156 + }
157 +
158 +
159 +{{/code}}
160 +
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 +
163 +===== Database setup =====
164 +
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:
166 +
167 +jdbc:mysql:~/~/localhost/mydatabase?capitalizeTypenames=true&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8
168 +
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.