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));
}
}
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) {
@ -115,6 +119,7 @@ public class Android {
}
private static void translate(Resources from, Resources to, List<TranslationLink> links) {
to.comment = from.comment;
for (TranslationLink translationLink : links) {
String translation = translate(from, translationLink);
if (!TextUtils.isBlank(translation)) {

View File

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

View File

@ -16,13 +16,16 @@ public class Utils {
static final Persister persister = new Persister();
static void saveTranslations(Resources translations, String language, File outDir,
String fileName) {
String fileName) {
final File dir = new File(outDir, valuesFolderName(language));
dir.mkdirs();
FileWriter out = null;
try {
out = new FileWriter(new File(dir, fileName));
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);
} catch (Exception e) {
e.printStackTrace();