PATH |
WebObjects relies on a specific application directory structure to find localized resources. The resources are placed in .lproj subdirectories of the Resources and WebServerResources directories.
MyApp.woa/ Resources/ English.lproj/ MyApplicationWide.strings Main.wo/ Main.html Main.wod Main.woo French.lproj/ MyApplicationWide.strings Main.wo/ Main.html Main.wod Main.woo WebServerResources/ English.lproj/ Flag.gif French.lproj/ Flag.gif
The .lproj subdirectories should contain everything that has localized content: string tables, sounds, images, and so on. The Resources directory contains resources that your WebObjects application uses, including .wo directories (containing components) and .strings files (containing localized strings). The WebServerResources directory contains resources that the web server needs, such as .gif and .jpg files. When WebObjects needs a resource, it searches the .lproj subdirectories before the top-level resource directory to ensure that if a localized resource is available, it is used. Thus, you need to be sure there are no files of the same name in localized locations when no localization is supposed to occur.
Project Builder maintains a Resources suitcase and a WebServerResources suitcase corresponding to the directories in the application, and creates the application directory structure from the contents of these suitcases. To add a localized resource file to your project, you first need to create a non-localized file, add it to the appropriate suitcase using Project->Add Files, and localize it using the following steps.
Select the file and open the inspector.
Project Builder creates copies of the resource in the appropriate .lproj folders and offers to remove the global (non-localized) version from the disk. Components can be localized in the same way.
To tell WebObjects the languages your application supports, use WOSession's setLanguages method, as shown in the code below.
public Session() { NSMutableArray languages = new NSMutableArray(); languages.addObject("English"); languages.addObject("French"); this.setLanguages (languages); }
The order of languages in the NSArray indicates the preferred order. The names of the languages are the names of the corresponding .lproj subdirectories.
You can determine the language of the request sender by sending a browserLanguages message to the WORequest object. The browserLanguages method returns an array of language preferences from the user's browser converted to the same format that WOSession's setLanguages method understands. The following code shows how to determine the user's language preferences from a component.
A .strings file contains a simple property list that maps common keys to words, phrases, or sentences in a particular language. For instance, a MyApplicationWide.strings file in English.lproj might have the following content:
{ buttonTitle = "Submit your request"; }
The MyApplicationWide.strings file in French.lproj would have the following:
{ buttonTitle = "Soumettez votre requete"; }
To access the .strings file use the WOResourceManager stringForKey method ( stringForKey:inTableNamed:withDefaultValue:inFramework:languages: in Objective-C). For example, the following code implements an accessor method that can be bound to a button's value attribute.