@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -158,72 +158,72 @@ public class Translate extends MatchingTask {
/**
* Sets Family name of resource bundle
*/
public void setBundle(String aB undle) {
this.bundle = aB undle;
public void setBundle(String b undle) {
this.bundle = b undle;
}
/**
* Sets locale specific language of resource bundle
*/
public void setBundleLanguage(String aB undleLanguage ) {
this.bundleLanguage = aB undleLanguage;
public void setBundleLanguage(String b undleLanguage ) {
this.bundleLanguage = b undleLanguage;
}
/**
* Sets locale specific country of resource bundle
*/
public void setBundleCountry(String aB undleCountry) {
this.bundleCountry = aB undleCountry;
public void setBundleCountry(String b undleCountry) {
this.bundleCountry = b undleCountry;
}
/**
* Sets locale specific variant of resource bundle
*/
public void setBundleVariant(String aB undleVariant) {
this.bundleVariant = aB undleVariant;
public void setBundleVariant(String b undleVariant) {
this.bundleVariant = b undleVariant;
}
/**
* Sets Destination directory
*/
public void setToDir(File aT oDir) {
this.toDir = aT oDir;
public void setToDir(File t oDir) {
this.toDir = t oDir;
}
/**
* Sets starting token to identify keys
*/
public void setStartToken(String aS tartToken) {
this.startToken = aS tartToken;
public void setStartToken(String s tartToken) {
this.startToken = s tartToken;
}
/**
* Sets ending token to identify keys
*/
public void setEndToken(String aE ndToken) {
this.endToken = aE ndToken;
public void setEndToken(String e ndToken) {
this.endToken = e ndToken;
}
/**
* Sets source file encoding scheme
*/
public void setSrcEncoding(String aS rcEncoding) {
this.srcEncoding = aS rcEncoding;
public void setSrcEncoding(String s rcEncoding) {
this.srcEncoding = s rcEncoding;
}
/**
* Sets destination file encoding scheme. Defaults to source file
* encoding
*/
public void setDestEncoding(String aD estEncoding) {
this.destEncoding = aD estEncoding;
public void setDestEncoding(String d estEncoding) {
this.destEncoding = d estEncoding;
}
/**
* Sets Resource Bundle file encoding scheme
*/
public void setBundleEncoding(String aB undleEncoding) {
this.bundleEncoding = aB undleEncoding;
public void setBundleEncoding(String b undleEncoding) {
this.bundleEncoding = b undleEncoding;
}
/**
@@ -231,8 +231,8 @@ public class Translate extends MatchingTask {
* the source file as well as the resource bundle file? Defaults to
* false.
*/
public void setForceOverwrite(boolean aF orceOverwrite) {
this.forceOverwrite = aF orceOverwrite;
public void setForceOverwrite(boolean f orceOverwrite) {
this.forceOverwrite = f orceOverwrite;
}
/**
@@ -339,17 +339,17 @@ public class Translate extends MatchingTask {
* but with bundle encoding also considered while loading.
*/
private void loadResourceMaps() throws BuildException {
Locale aL ocale = new Locale(bundleLanguage,
Locale l ocale = new Locale(bundleLanguage,
bundleCountry,
bundleVariant);
String language = aL ocale.getLanguage().length() > 0 ?
"_" + aL ocale.getLanguage() :
String language = l ocale.getLanguage().length() > 0 ?
"_" + l ocale.getLanguage() :
"";
String country = aL ocale.getCountry().length() > 0 ?
"_" + aL ocale.getCountry() :
String country = l ocale.getCountry().length() > 0 ?
"_" + l ocale.getCountry() :
"";
String variant = aL ocale.getVariant().length() > 0 ?
"_" + aL ocale.getVariant() :
String variant = l ocale.getVariant().length() > 0 ?
"_" + l ocale.getVariant() :
"";
String bundleFile = bundle + language + country + variant;
processBundle(bundleFile, 0, false);
@@ -365,16 +365,16 @@ public class Translate extends MatchingTask {
//Load default locale bundle files
//using default file encoding scheme.
aL ocale = Locale.getDefault();
l ocale = Locale.getDefault();
language = aL ocale.getLanguage().length() > 0 ?
"_" + aL ocale.getLanguage() :
language = l ocale.getLanguage().length() > 0 ?
"_" + l ocale.getLanguage() :
"";
country = aL ocale.getCountry().length() > 0 ?
"_" + aL ocale.getCountry() :
country = l ocale.getCountry().length() > 0 ?
"_" + l ocale.getCountry() :
"";
variant = aL ocale.getVariant().length() > 0 ?
"_" + aL ocale.getVariant() :
variant = l ocale.getVariant().length() > 0 ?
"_" + l ocale.getVariant() :
"";
bundleEncoding = System.getProperty("file.encoding");
@@ -391,19 +391,18 @@ public class Translate extends MatchingTask {
/**
* Process each file that makes up this bundle.
*/
private void processBundle(final String bundleFile, final int i,
final boolean checkLoaded)
throws BuildException {
String lBundleFile = bundleFile + ".properties";
private void processBundle(String bundleFile, int i,
boolean checkLoaded) throws BuildException {
bundleFile += ".properties";
FileInputStream ins = null;
try {
ins = new FileInputStream(lB undleFile);
ins = new FileInputStream(b undleFile);
loaded = true;
bundleLastModified[i] = new File(lB undleFile).lastModified();
log("Using " + lB undleFile, Project.MSG_DEBUG);
bundleLastModified[i] = new File(b undleFile).lastModified();
log("Using " + b undleFile, Project.MSG_DEBUG);
loadResourceMap(ins);
} catch (IOException ioe) {
log(lB undleFile + " not found.", Project.MSG_DEBUG);
log(b undleFile + " not found.", Project.MSG_DEBUG);
//if all resource files associated with this bundle
//have been scanned for and still not able to
//find a single resrouce file, throw exception
@@ -525,49 +524,50 @@ public class Translate extends MatchingTask {
srcEncoding));
String line;
while((line = in.readLine()) != null) {
StringBuffer newline = new StringBuffer(line);
int startIndex = -1;
int endIndex = -1;
outer: while (true) {
startIndex = line.indexOf(startToken, endIndex + 1);
if (startIndex < 0 ||
startIndex + 1 >= line.length()) {
break;
}
endIndex = line.indexOf(endToken, startIndex + 1);
if (endIndex < 0) {
break;
}
String matches = line.substring(startIndex + 1,
endIndex);
//If there is a white space or = or :, then
//it isn't to be treated as a valid key.
for (int k = 0; k < matches.length(); k++) {
char c = matches.charAt(k);
if (c == ':' ||
c == '=' ||
Character.isSpaceChar(c)) {
endIndex = endIndex - 1;
continue outer;
}
}
String replace = null;
replace = (String) resourceMap.get(matches);
//If the key hasn't been loaded into resourceMap,
//use the key itself as the value also.
if (replace == null) {
log("Warning: The key: " + matches
+ " hasn't been defined.",
Project.MSG_DEBUG);
replace = matches;
}
line = line.substring(0, startIndex)
+ replace
+ line.substring(endIndex + 1);
endIndex = startIndex + replace.length() + 1;
if (endIndex + 1 >= line.length()) {
break;
outer: while (true) {
startIndex = line.indexOf(startToken, endIndex + 1);
if (startIndex < 0 ||
startIndex + 1 >= line.length()) {
break;
}
endIndex = line.indexOf(endToken, startIndex + 1);
if (endIndex < 0) {
break;
}
String matches = line.substring(startIndex + 1,
endIndex);
//If there is a white space or = or :, then
//it isn't to be treated as a valid key.
for (int k = 0; k < matches.length(); k++) {
char c = matches.charAt(k);
if (c == ':' ||
c == '=' ||
Character.isSpaceChar(c)) {
endIndex = endIndex - 1;
continue outer;
}
}
String replace = null;
replace = (String) resourceMap.get(matches);
//If the key hasn't been loaded into resourceMap,
//use the key itself as the value also.
if (replace == null) {
log("Warning: The key: " + matches
+ " hasn't been defined.",
Project.MSG_DEBUG);
replace = matches;
}
line = line.substring(0, startIndex)
+ replace
+ line.substring(endIndex + 1);
endIndex = startIndex + replace.length() + 1;
if (endIndex + 1 >= line.length()) {
break;
}
}
out.write(line);
out.newLine();
}