Add a comment to the output XML containing the source of translations

This commit is contained in:
serso 2016-06-19 11:09:09 +02:00
parent 801b799422
commit eb8ec9f8c4
3 changed files with 13 additions and 2 deletions

View File

@ -98,7 +98,11 @@ public class Android {
inFile = makeStringsFile(from, languageLocale.substring(0, i)); inFile = makeStringsFile(from, languageLocale.substring(0, i));
} }
} }
return Utils.persister.read(Resources.class, inFile); final Resources resources = Utils.persister.read(Resources.class, inFile);
if (resources != null) {
resources.comment = "Copied from " + from;
}
return resources;
} }
private static File makeStringsFile(File from, String languageLocale) { private static File makeStringsFile(File from, String languageLocale) {
@ -115,6 +119,7 @@ public class Android {
} }
private static void translate(Resources from, Resources to, List<TranslationLink> links) { private static void translate(Resources from, Resources to, List<TranslationLink> links) {
to.comment = from.comment;
for (TranslationLink translationLink : links) { for (TranslationLink translationLink : links) {
String translation = translate(from, translationLink); String translation = translate(from, translationLink);
if (!TextUtils.isBlank(translation)) { if (!TextUtils.isBlank(translation)) {

View File

@ -2,6 +2,7 @@ package org.solovyev.android.translations;
import org.simpleframework.xml.ElementList; import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root; import org.simpleframework.xml.Root;
import org.simpleframework.xml.Transient;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -10,6 +11,8 @@ import java.util.List;
public class Resources { public class Resources {
@ElementList(inline = true) @ElementList(inline = true)
public List<ResourceString> strings = new ArrayList<>(); public List<ResourceString> strings = new ArrayList<>();
@Transient
public String comment;
public Resources() { public Resources() {
} }

View File

@ -23,6 +23,9 @@ public class Utils {
try { try {
out = new FileWriter(new File(dir, fileName)); out = new FileWriter(new File(dir, fileName));
out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
if (translations.comment != null && translations.comment.length() != 0) {
out.write("<!-- " + translations.comment + " -->\n");
}
persister.write(translations, out); persister.write(translations, out);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();