From eb8ec9f8c4f7deedbb6e17c899fb3466dc3c826d Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 19 Jun 2016 11:09:09 +0200 Subject: [PATCH] Add a comment to the output XML containing the source of translations --- .../java/org/solovyev/android/translations/Android.java | 7 ++++++- .../java/org/solovyev/android/translations/Resources.java | 3 +++ .../main/java/org/solovyev/android/translations/Utils.java | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/translations/src/main/java/org/solovyev/android/translations/Android.java b/translations/src/main/java/org/solovyev/android/translations/Android.java index e01ad88f..3c8aa492 100644 --- a/translations/src/main/java/org/solovyev/android/translations/Android.java +++ b/translations/src/main/java/org/solovyev/android/translations/Android.java @@ -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 links) { + to.comment = from.comment; for (TranslationLink translationLink : links) { String translation = translate(from, translationLink); if (!TextUtils.isBlank(translation)) { diff --git a/translations/src/main/java/org/solovyev/android/translations/Resources.java b/translations/src/main/java/org/solovyev/android/translations/Resources.java index 14846c87..9e382b1f 100644 --- a/translations/src/main/java/org/solovyev/android/translations/Resources.java +++ b/translations/src/main/java/org/solovyev/android/translations/Resources.java @@ -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 strings = new ArrayList<>(); + @Transient + public String comment; public Resources() { } diff --git a/translations/src/main/java/org/solovyev/android/translations/Utils.java b/translations/src/main/java/org/solovyev/android/translations/Utils.java index 19e1a976..595ef079 100644 --- a/translations/src/main/java/org/solovyev/android/translations/Utils.java +++ b/translations/src/main/java/org/solovyev/android/translations/Utils.java @@ -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("\n"); + if (translations.comment != null && translations.comment.length() != 0) { + out.write("\n"); + } persister.write(translations, out); } catch (Exception e) { e.printStackTrace();