Add a comment to the output XML containing the source of translations
This commit is contained in:
parent
801b799422
commit
eb8ec9f8c4
@ -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)) {
|
||||||
|
@ -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() {
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,16 @@ public class Utils {
|
|||||||
static final Persister persister = new Persister();
|
static final Persister persister = new Persister();
|
||||||
|
|
||||||
static void saveTranslations(Resources translations, String language, File outDir,
|
static void saveTranslations(Resources translations, String language, File outDir,
|
||||||
String fileName) {
|
String fileName) {
|
||||||
final File dir = new File(outDir, valuesFolderName(language));
|
final File dir = new File(outDir, valuesFolderName(language));
|
||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
FileWriter out = null;
|
FileWriter out = null;
|
||||||
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();
|
||||||
|
Loading…
Reference in New Issue
Block a user