Fix unescaped quote in new translation and make translator escape quotes going forward

This commit is contained in:
Sean Owen 2015-01-30 17:08:37 +00:00
parent 9c4b8ed860
commit 563294b36e
2 changed files with 8 additions and 6 deletions

View file

@ -112,7 +112,7 @@
<string name="preferences_front_light_summary">Améliore le balayage lors d\'une faible luminosité sur certains téléphone, mais peut causer un reflet. Ne fonctionne pas sur tous les téléphones.</string>
<string name="preferences_front_light_title">Utiliser la lumière frontale</string>
<string name="preferences_general_title">Paramètres généraux</string>
<string name="preferences_history_summary">Stockez vos scans dans l'histoire</string>
<string name="preferences_history_summary">Stockez vos scans dans l\'histoire</string>
<string name="preferences_history_title">Ajouter à Histoire</string>
<string name="preferences_invert_scan_summary">Balayer des codes-barres blancs sur fond noir. Non disponible sur certains appareils.</string>
<string name="preferences_invert_scan_title">Balayage négatif</string>

View file

@ -118,7 +118,9 @@ public final class StringsResourceTranslator {
String parentName = translatedFile.getParent().getFileName().toString();
Matcher stringsFileNameMatcher = STRINGS_FILE_NAME_PATTERN.matcher(parentName);
stringsFileNameMatcher.find();
if (!stringsFileNameMatcher.find()) {
throw new IllegalArgumentException("Invalid parent dir: " + parentName);
}
String language = stringsFileNameMatcher.group(1);
String massagedLanguage = LANGUAGE_CODE_MASSAGINGS.get(language);
if (massagedLanguage != null) {
@ -151,6 +153,8 @@ public final class StringsResourceTranslator {
if (translatedString == null || forceRetranslation.contains(key)) {
anyChange = true;
translatedString = translateString(value, language);
// Specially for string resources, escape ' with \
translatedString = translatedString.replaceAll("'", "\\\\'");
}
out.write(translatedString);
@ -193,10 +197,8 @@ public final class StringsResourceTranslator {
String translation = m.group(1);
// This is a little crude; unescape some common escapes in the raw response
translation = translation.replaceAll("&quot;", "\"");
translation = translation.replaceAll("&#39;", "'");
translation = translation.replaceAll("&amp;quot;", "\"");
translation = translation.replaceAll("&amp;#39;", "'");
translation = translation.replaceAll("&(amp;)?quot;", "\"");
translation = translation.replaceAll("&(amp;)?#39;", "'");
System.out.println(" Got translation " + translation);
return translation;