"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "javase/src/main/java/com/google/zxing/client/j2se/StringsResourceTranslator.java" between
zxing-zxing-3.4.1.tar.gz and zxing-zxing-3.5.0.tar.gz

About: ZXing ("zebra crossing") is a multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages. Info: Project is in maintenance mode (no active development).

StringsResourceTranslator.java  (zxing-zxing-3.4.1):StringsResourceTranslator.java  (zxing-zxing-3.5.0)
skipping to change at line 52 skipping to change at line 52
* <p>A utility which auto-translates English strings in Android string resource s using * <p>A utility which auto-translates English strings in Android string resource s using
* Google Translate.</p> * Google Translate.</p>
* *
* <p>Pass the Android client res/ directory as first argument, and optionally m essage keys * <p>Pass the Android client res/ directory as first argument, and optionally m essage keys
* who should be forced to retranslate. * who should be forced to retranslate.
* Usage: {@code StringsResourceTranslator android/res/ [key_1 ...]}</p> * Usage: {@code StringsResourceTranslator android/res/ [key_1 ...]}</p>
* *
* <p>You must set your Google Translate API key into the environment with -Dtra nslateAPI.key=...</p> * <p>You must set your Google Translate API key into the environment with -Dtra nslateAPI.key=...</p>
* *
* @author Sean Owen * @author Sean Owen
* @deprecated without replacement since 3.4.2
*/ */
@Deprecated
public final class StringsResourceTranslator { public final class StringsResourceTranslator {
private static final String API_KEY = System.getProperty("translateAPI.key"); private static final String API_KEY = System.getProperty("translateAPI.key");
static { static {
if (API_KEY == null) { if (API_KEY == null) {
throw new IllegalArgumentException("translateAPI.key is not specified"); throw new IllegalArgumentException("translateAPI.key is not specified");
} }
} }
private static final Pattern ENTRY_PATTERN = Pattern.compile("<string name=\"( [^\"]+)\".*>([^<]+)</string>"); private static final Pattern ENTRY_PATTERN = Pattern.compile("<string name=\"( [^\"]+)\".*>([^<]+)</string>");
skipping to change at line 99 skipping to change at line 101
private StringsResourceTranslator() {} private StringsResourceTranslator() {}
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
Path resDir = Paths.get(args[0]); Path resDir = Paths.get(args[0]);
Path valueDir = resDir.resolve("values"); Path valueDir = resDir.resolve("values");
Path stringsFile = valueDir.resolve("strings.xml"); Path stringsFile = valueDir.resolve("strings.xml");
Collection<String> forceRetranslation = Arrays.asList(args).subList(1, args. length); Collection<String> forceRetranslation = Arrays.asList(args).subList(1, args. length);
DirectoryStream.Filter<Path> filter = entry -> DirectoryStream.Filter<Path> filter = entry ->
Files.isDirectory(entry) && !Files.isSymbolicLink(entry) && Files.isDirectory(entry) && !Files.isSymbolicLink(entry) &&
VALUES_DIR_PATTERN.matcher(entry.getFileName().toString()).matches(); VALUES_DIR_PATTERN.matcher(entry.getFileName().toString()).matches();
try (DirectoryStream<Path> dirs = Files.newDirectoryStream(resDir, filter)) { try (DirectoryStream<Path> dirs = Files.newDirectoryStream(resDir, filter)) {
for (Path dir : dirs) { for (Path dir : dirs) {
translate(stringsFile, dir.resolve("strings.xml"), forceRetranslation); translate(stringsFile, dir.resolve("strings.xml"), forceRetranslation);
} }
} }
} }
private static void translate(Path englishFile, private static void translate(Path englishFile,
Path translatedFile, Path translatedFile,
skipping to change at line 207 skipping to change at line 209
translation = translation.replaceAll("&(amp;)?#39;", "'"); translation = translation.replaceAll("&(amp;)?#39;", "'");
System.out.println(" Got translation " + translation); System.out.println(" Got translation " + translation);
return translation; return translation;
} }
private static CharSequence fetch(URI translateURI) throws IOException { private static CharSequence fetch(URI translateURI) throws IOException {
URLConnection connection = translateURI.toURL().openConnection(); URLConnection connection = translateURI.toURL().openConnection();
connection.connect(); connection.connect();
StringBuilder translateResult = new StringBuilder(200); StringBuilder translateResult = new StringBuilder(200);
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection try (BufferedReader in =
.getInputStream(), StandardCharsets.UTF_8))) { new BufferedReader(new InputStreamReader(connection.getInputStream(),
StandardCharsets.UTF_8))) {
char[] buffer = new char[8192]; char[] buffer = new char[8192];
int charsRead; int charsRead;
while ((charsRead = in.read(buffer)) > 0) { while ((charsRead = in.read(buffer)) > 0) {
translateResult.append(buffer, 0, charsRead); translateResult.append(buffer, 0, charsRead);
} }
} }
return translateResult; return translateResult;
} }
private static Map<String,String> readLines(Path file) throws IOException { private static Map<String,String> readLines(Path file) throws IOException {
 End of changes. 4 change blocks. 
3 lines changed or deleted 6 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)