Version 8.1 by smmccraw on 2007/07/08 09:46

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 [[ERXSession>>Programming__WebObjects-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 {{panel}}
11
12 Resources
13 |
14 +-English.lproj
15 | |
16 | +-Localizable.strings
17 |
18 +-German.lproj
19 | |
20 | +-Localizable.strings
21
22 {{/panel}}
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 {{panel}}
27
28 {
29 "hello" = "Hello";
30 "world" = "World";
31 }
32
33 {{/panel}}
34
35 for the Localizable.strings file in the English.lproj directory and
36
37 {{panel}}
38
39 {
40 "hello" = "Hallo";
41 "world" = "Welt";
42 }
43
44 {{/panel}}
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 [[ERXSession>>Programming__WebObjects-WOnder-ERXSession]] in your application).
49
50 {{panel}}
51
52 {noformat}<p>The application says: <webobject name="langHello"/> <webobject name="langWorld"/></p>{noformat}
53
54 {{/panel}}
55
56 (HTML file)
57
58 {{panel}}
59
60 langHello : WOString {
61 value = session.localizer.hello;
62 }
63
64 {{/panel}}
65
66 langWorld : WOString {
67
68 {{panel}}
69
70 value = session.localizer.world;
71 }
72
73 {{/panel}}
74
75 (WOD file)
76
77 ERXLocalizer //magically// detects your system locale and puts out the the following HTML code if you use an english locale:
78
79 {{panel}}
80
81 {noformat}<p>The application says: Hello World</p>{noformat}
82
83 {{/panel}}
84
85 Category:WebObjects
86
87 === Useful appication settings ===
88
89 These are the default settings for ERXLocalizer:
90
91 {{panel}}
92
93 er.extensions.ERXLocalizer.defaultLanguage=English
94 er.extensions.ERXLocalizer.fileNamesToWatch=("Localizable.strings","ValidationTemplate.strings")
95 er.extensions.ERXLocalizer.availableLanguages=(English,German)
96 er.extensions.ERXLocalizer.frameworkSearchPath=(app,ERDirectToWeb,ERExtensions)
97
98 {{/panel}}
99
100 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.
101
102 {{panel}}
103
104 public Application() {
105 NSLog.out.appendln("Welcome to " + this.name() + " !");
106 /* ** put your initialization code in here ** */
107 ERXLocalizer.setDefaultLanguage("English");
108 }
109
110 {{/panel}}
111
112 === Unicode support ===
113
114 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.