java left logo
java middle logo
java right logo
 

Home arrow Other API Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 3942
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to use Translate task E-mail
User Rating: / 1
PoorBest 

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 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>

Source: Apache Ant


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.