Wiki source code of WOnder-ERXLocalizer

Version 13.1 by Pascal Robert on 2007/09/03 18:51

Show last authors
1 == Overview ==
2
3 ERXLocalizer provides easy KVC (Key-Value Coding) access to localization. For a short description and a full list of all available methods please see the api ([[http://webobjects.mdimension.com/wonder/api/er/extensions/ERXLocalizer.html]]).
4
5 === How to use ===
6
7 The easiest way to use localization in you WebObjects applications is to use Project Wonder's built-in localization support using the the localizer() method in the ERXSessionProgrammingWebObjects-WOnder-ERXSession class. The localizer() method allows you to bind your localized language strings directly to you components. Lets say you want to localize your WebObjects application in english and german. The only thing you have to do is to create the required language resources in you application's resource directory. If you use Eclipse to develop your WebObjects applications, this is the ./Resources directory in you application root directory.
8 For english and german localization you need to create the following files and directories:
9
10 {{code}}
11
12 Resources
13 |
14 +-English.lproj
15 | |
16 | +-Localizable.strings
17 |
18 +-German.lproj
19 | |
20 | +-Localizable.strings
21
22 {{/code}}
23
24 The Localizable.strings files contain the key-value pairs with you your localization. The key is always the //placeholder// for the translation and it is used in your WebObjects application to address the localized value. If your application is a simple //hello world// application, your localized files may look like
25
26 {{code}}
27
28 {
29 "hello" = "Hello";
30 "world" = "World";
31 }
32
33 {{/code}}
34
35 for the Localizable.strings file in the English.lproj directory and
36
37 {{code}}
38
39 {
40 "hello" = "Hallo";
41 "world" = "Welt";
42 }
43
44 {{/code}}
45
46 for the Localizable.strings file in the German.lproj directory.
47
48 To use the localized strings just bind the keys to an appropriate WOComponent (assuming you inherited your Session object from ERXSessionProgrammingWebObjects-WOnder-ERXSession in your application).
49
50 {{code}}
51
52 <p>The application says: <webobject name="langHello"/> <webobject name="langWorld"/></p>
53
54 {{/code}}
55
56 (HTML file)
57
58 {{code}}
59
60 langHello : WOString {
61 value = session.localizer.hello;
62 }
63
64 {{/code}}
65
66 {{code}}
67
68 langWorld : WOString {
69 value = session.localizer.world;
70 }
71
72 {{/code}}
73
74 (WOD file)
75
76 ERXLocalizer magically detects your system locale and puts out the the following HTML code if you use an english locale:
77
78 {{code}}
79
80 <p>The application says: Hello World</p>
81
82 {{/code}}
83
84 === Useful appication settings ===
85
86 These are the default settings for ERXLocalizer:
87
88 {{code}}
89
90 er.extensions.ERXLocalizer.defaultLanguage=English
91 er.extensions.ERXLocalizer.fileNamesToWatch=("Localizable.strings","ValidationTemplate.strings")
92 er.extensions.ERXLocalizer.availableLanguages=(English,German)
93 er.extensions.ERXLocalizer.frameworkSearchPath=(app,ERDirectToWeb,ERExtensions)
94
95 {{/code}}
96
97 You can provide your own defaults in your application properties file or set the defaults somewhere in the initialization code of your application, e.g.
98
99 {{code}}
100
101 public Application() {
102 NSLog.out.appendln("Welcome to " + this.name() + " !");
103 /* ** put your initialization code in here ** */
104 ERXLocalizer.setDefaultLanguage("English");
105 }
106
107 {{/code}}
108
109 === Unicode support ===
110
111 If you are creating UTF-8 applications, please be aware that UTF-8 support for your Localizable.strings files seems not to work. Instead of being desperate, simply convert your Localizable.strings files to UTF-16. The localized strings are shown in the correct way in your UTF-8 application. For further information see [[Localizing Property Labels>>http://developer.apple.com/documentation/WebObjects/DesktopApplications/index.html?http://developer.apple.com/documentation/WebObjects/DesktopApplications/T9LocalizingDComponents/chapter_22_section_2.html]] in the Apple Developer Connection.