Translate

Description

Identifies keys in files delimited by special tokens and translates them with values read from resource bundles.

A resource bundle contains locale-specific key-value pairs. A resource bundle is a hierarchical set of property files. A bundle name makes up its base family name. Each file that makes up this bundle has this name plus its locale. For example, if the resource bundle name is MyResources, the file that contains German text will take the name MyResources_de. In addition to language, country and variant are also used to form the files in the bundle.

The resource bundle lookup searches for resource files with various suffixes on the basis of (1) the desired locale and (2) the default locale (basebundlename), in the following order from lower-level (more specific) to parent-level (less specific):

basebundlename + "_" + language1 + "_" + country1 + "_" + variant1
basebundlename + "_" + language1 + "_" + country1
basebundlename + "_" + language1
basebundlename
basebundlename + "_" + language2 + "_" + country2 + "_" + variant2
basebundlename + "_" + language2 + "_" + country2
basebundlename + "_" + language2

The file names generated thus are appended with the string ".properties" to make up the file names that are to be used.

File encoding is supported. The encoding scheme of the source files, destination files and the bundle files can be specified. Destination files can be explicitly overwritten using the forceoverwrite attribute. If forceoverwrite is false, the destination file is overwritten only if either the source file or any of the files that make up the bundle have been modified after the destination file was last modified.

New in Apache Ant 1.6:
Line endings of source files are preserved in the translated files.

FileSets are used to select files to translate.

Parameters

Attribute Description Required
todir Destination directory where destination files are to be created. Yes
starttoken The starting token to identify keys. Yes
endtoken The ending token to identify keys. Yes
bundle Family name of resource bundle. Yes
bundlelanguage Locale specific language of resource bundle. Defaults to default locale's language. No
bundlecountry Locale specific country of resource bundle. Defaults to default locale's country. No
bundlevariant Locale specific variant of resource bundle. Defaults to the default variant of the country and language being used. No
srcencoding Source file encoding scheme. Defaults to system default file encoding. No
destencoding Destination file encoding scheme. Defaults to source file encoding. No
bundleencoding Resource Bundle file encoding scheme. Defaults to source file encoding. No
forceoverwrite Overwrite existing files even if the destination files are newer. Defaults to "no". No

Parameters specified as nested elements

fileset

FileSets are used to select files that contain keys for which value translated files are to be generated.

Examples

Translate source file encoded in english into its japanese equivalent using a resource bundle encoded in japanese.

  <translate toDir="$(dest.dir}/ja"
        starttoken="#"
        endtoken="#"
        bundle="resource/BaseResource"
        bundlelanguage="ja"
        forceoverwrite="yes"
        srcencoding="ISO8859_1"
        destencoding="SJIS"
        bundleencoding="SJIS">
        <fileset dir="${src.dir}">
            <include name="**/*.jsp"/>
        </fileset>
  </translate>