Defining Resource Bundles
Resource bundles contain one or more resources. They are created as text files using the simple syntax described below, then compiled into an efficient, binary form (see Compiling Resource Bundles). Resource text may be in any recognized encoding; it is converted to Unicode when you compile the text file.
Resources may be simple or complex. Simple resources hold a single value. Complex resources hold one or more simple or complex resources. Simple resources are specified in the text resource files using the following syntax:
 
name:type { value }
A simple resource can be of type string, integer, integer vector, or binary:
*Strings
Strings hold text. For example:
 
helloWorldMessage:string { "Hello World" }
Because string values are so common in resource bundles, the type, the double quotes, or both may be omitted for brevity:
 
helloWorldMessage { Hello World }
The type is required for all other simple resources, so ambiguities do not occur.
*Integers
Integers hold 32-bit integer values. For example:
 
numStatesOrProvinces:int { 50 }
*Integer Vectors
Integer vectors hold vectors of 32-bit integer values. For example:
 
buttonSize:intVector { 10, 15, 10, 15 }
*Binaries
Binary values store binary data, such as processed data or images. For example:
 
pgpkey:bin { a1b2c3d4e5f67890 }
Alternatively, you can import a binary file:
 
logo:import { "logo.gif" }
Complex resources can be arranged as a table or as an array:
*Tables
Tables are collections that hold named resources. The name of each resource is a key into the table. Tables are specified using the following syntax:
 
name:table {
key1 { subresource1 }
key2 { subresource2 }
...
keyN { subresourceN }
}
For example:
 
salutations:table {
morningGreeting:string { "Good morning" }
afternoonGreeting:string { "Good afternoon" }
eveningGreeting:string { "Good evening" }
}
*Arrays
Arrays are collections that hold unnamed resources. Elements in an array are accessed by integer index. Arrays are specified using the following syntax:
 
name:array { subresource1, subresource2, ..., subresourceN }
For example:
 
AmPmMarkers:array { "AM", "PM" }
Note that tables and arrays may themselves contain other tables and arrays, not just simple resources. As with all resources held by arrays, a table held within an array must not be named.
Because tables and arrays can be disambiguated from each other solely on the basis of their syntactic form, you may omit the type information from complex resources. For example, this resource is unambiguously an array:
 
AmPmMarkers { "AM", "PM" }
Resource bundles are themselves tables, named after the locale they are associated with. For example, this is a simple root resource bundle:
 
root {
 
Version { "2.1.0" }
salutations {
morningGreeting { "Good morning" }
afternoonGreeting { "Good afternoon" }
eveningGreeting { "Good night" }
}
}
To define the root resource bundle for your application, gather all the application data that may need to be translated or localized, express it in the resource syntax described above, and save it in a text file called root.txt.
The resources in the root bundle can be localized, as necessary, to particular locales. For example, this might be a localization of the resources above to the es locale, saved in a text file called es.txt:
es {
salutations {
morningGreeting { "Buenos días" }
afternoonGreeting { "Buenas tardes" }
eveningGreeting { "Buenos noches" }
}
}
Note that the Version resource is not localized. If that resource is sought in the es resource bundle, the fallback mechanism ensures it is found in the root resource bundle.