Understanding Bundles and Elements

From Lime 49 Wiki
Jump to: navigation, search

ResourceBlender uses bundles and elements to represent localized elements in an application. How these are used depends on the output format of that project.

Bundles, elements and resources

Applications in ResourceBlender can contain multiple bundles. Each bundle is unique (though the same name can be used for bundles in different applications), and elements. Each element is assigned a resource, which can be shared by many elements. When outputting to a resource format, the translations for each resource are used to create files for each language. This varies depending on the output format.



Bundles are containers for groups of elements.


Java projects use the bundle name together with the language code to generate the name of the .properties file. For example: A bundle called resources in an application which used the languages English and German would generate two files - resources_en.properties and resources_de.properties.


.NET uses bundles to represent forms. For example: A bundle called FrmMain in an application which used English (language code=en) and Czech (language code=cs) would generate FrmMain.en.resx and FrmMain.cs.resx. .NET can also make use of generic bundles which can be used by any class by creating a new ResourceManager object.


Firefox uses two bundles, JavaScript and XUL. JavaScript bundles are just Java .properties files, XUL bundles are .dtd document type definitions containing entities. For more information on the format used for Firefox extensions, see Mozilla's MDC.

PHP Definitions / PHP Array

The template provided by default uses the bundle name and language code to generate the filename. Eg: MainStrings_en-GB.php.


Elements represent a single object in a resource bundle or form. Each element must be assigned a resource.


In Java applications, the element name is used in calls to the getString method of ResourceBundle. For example: To access an element called MainMenuText in a bundle called myresources, first initialize a new ResourceBundle using

ResourceBundle res = new ResourceBundle.getBundle("myresources", new Locale(country, locale));

then use

String menuText = res.getString("MainMenuText");


.NET handles compilation of bundles automatically when a form is localized. First, the form's localizable property needs to be set to true, then the resources just need to be dropped in to the source folder after generation. Element names comprise of the names of controls on a form and their properties. To localize the text displayed on a button called btnDoSomething, create an element called btnDoSomething.Text. Localized resources can also be accessed programatically using ResourceManager.


Firefox extensions access bundles using nsIStringBundleService/nsIStringBundle or the <stringbundle> tag. Elements in the XUL bundle are accessed by &elementName;, while JavaScript elements can be accessed by calling .getString() on nsIStringBundle.

PHP Definitions
Each element is defined as a constant. After the file has been include()d, the translation can be used as any other constants.
echo ElementName;
PHP Array
Element are defined as keys in an array, translations are the values. After the file has been include()d, use
echo $BundleName['ElementName'];


Resources are strings of text in one or more languages. Each resource contains at least one language, and contains translations from that language into other languages.

Personal tools