Package | mx.resources |
Interface | public interface IResourceBundle |
Implementors | ResourceBundle |
Language Version: | ActionScript 3.0 |
Product Version: | Flex 3 |
Runtime Versions: | Flash Player 9, AIR 1.1 |
There are three main concepts involved in localization: locales, resources, and resource bundles.
A locale specifies a language and a country
for which your application has been localized.
For example, the locale "en_US"
specifies English as spoken in the United States.
(See the mx.resources.Locale class for more information.)
A resource is a named value that is locale-dependent.
For example, your application might have a resource
whose name is "OPEN"
and whose value for an English locale is "Open"
but whose value for a French locale is "Ouvrir"
.
A resource bundle is a named group of resources
whose values have been localized for a particular locale.
A resource bundle is identified by the combination of its
bundleName
and its locale
,
and has a content
Object that contains
the name-value pairs for the bundle's resources.
The IResourceBundle interface represents a specific resource bundle.
However, most applications will only need to use IResourceManager.
A single ResourceManager object implementing this interface
manages multiple resource bundles, possibly for multiple locales,
and provides access to the resources that they contain.
For example, you can retrieve a specific resource as a String by calling
resourceManager.getString(bundleName, resourceName)
.
By changing the localeChain
property of the ResourceManager,
you can change which resource bundles are searched for resource values.
Generally, you do not create resource bundles yourself;
instead, they are usually compiled from *.properties files.
A properties file named MyResources.properties
produces a resource bundle with "MyResources"
for its bundleName
.
You generally produce multiple versions of each properties file,
one for each locale that your application supports.
Flex properties files are similar to Java properties files,
except that they also support MXML's Embed()
and ClassReference()
directives.
These directives work the same way in a properties file
as they do in a CSS file, producing class references.
Also, the encoding for Flex properties files
is always assumed to be UTF-8.
The Flex framework's resources have been localized
for U.S. English (the "en_US"
locale) and
for Japanese (the "ja_JP"
locale).
The framework resources are organized into multiple bundles
corresponding to framework packages; for example, the "formatters"
bundle is used by classes in the mx.formatters package.
(There is also a "SharedResources" bundle for resources used by
multiple packages.)
The properties files for the framework resources, such as formatters.properties, can be found in the frameworks/projects/framework/bundles/{locale}/src directories of the Flex SDK. Your applications normally link against the Flex framework as a precompiled library, framework.swc, in the frameworks/libs directory. This library has no resources in it. Instead, the framework resources have been compiled into separate resource bundle libraries such as framework_rb.swc. These are located in the frameworks/locales/{locale} directories and your application must also link in one or more of these.
You are free to organize your application's own resources
into whatever bundles you find convenient.
If you localize your application for locales
other than "en_US"
and "ja_JP"
,
you should localize the framework's properties files for those locales
as well and compile additional resource bundle libaries for them.
When your application starts, the ResourceManager is automatically populated with whatever resource bundles were compiled into the application. If you create a code module, by default the resources that its classes need are compiled into the module. When the module is loaded into an application, any bundles that the application does not already have are added to the ResourceManager.
You can compile "resource modules" that have only resources in them,
and load them with the loadResourceModule()
method
of the ResourceManager.
With resource modules, you can support multiple locales by loading
the resources you need at run time rather than compiling them into
your application.
Although the ResourceManager is normally populated with resource bundles
that were compiled into your application or loaded from modules,
you can also programmatically create resource bundles and add them
to the ResourceManager yourself with the addResourceBundle()
method.
Related API Elements
Property | Defined By |
---|
Wed Nov 21 2018, 06:34 AM -08:00