From ba5161966f0f633c819dd7939559302cde2b8a91 Mon Sep 17 00:00:00 2001 From: reger Date: Sun, 10 Apr 2016 05:33:21 +0200 Subject: [PATCH] support xliff for downloaded of language file --- htroot/ConfigLanguage_p.html | 5 +++-- htroot/ConfigLanguage_p.java | 16 ++++++++++++++-- locales/de.lng | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/htroot/ConfigLanguage_p.html b/htroot/ConfigLanguage_p.html index bd0a6a44f..3ddc8a644 100644 --- a/htroot/ConfigLanguage_p.html +++ b/htroot/ConfigLanguage_p.html @@ -39,14 +39,15 @@
-
+
Download Language File +

Supported formats are the internal language file (extension .lng) or XLIFF (extension .xlf) format.

:
-
+
diff --git a/htroot/ConfigLanguage_p.java b/htroot/ConfigLanguage_p.java index 1e636fc2e..82fb0059f 100644 --- a/htroot/ConfigLanguage_p.java +++ b/htroot/ConfigLanguage_p.java @@ -29,6 +29,7 @@ //javac -classpath .:../Classes Blacklist_p.java //if the shell's current path is HTROOT +import com.google.common.io.Files; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -48,6 +49,7 @@ import net.yacy.kelondro.util.FileUtils; import net.yacy.search.Switchboard; import net.yacy.server.serverObjects; import net.yacy.server.serverSwitch; +import net.yacy.utils.translation.TranslatorXliff; public class ConfigLanguage_p { @@ -103,15 +105,25 @@ public class ConfigLanguage_p { final DigestURL u = new DigestURL(url); it = FileUtils.strings(u.get(ClientIdentification.yacyInternetCrawlerAgent, null, null)); try { - final File langFile = new File(langPath, url.substring(url.lastIndexOf('/'), url.length())); + File langFile = new File(langPath, u.getFileName()); final OutputStreamWriter bw = new OutputStreamWriter(new FileOutputStream(langFile), StandardCharsets.UTF_8.name()); while (it.hasNext()) { bw.write(it.next() + "\n"); } bw.close(); + + // convert downloaded xliff to internal lng file + final String ext = Files.getFileExtension(langFile.getName()); + if (ext.equalsIgnoreCase("xlf") || ext.equalsIgnoreCase("xliff")) { + TranslatorXliff tx = new TranslatorXliff(); + Map lng = TranslatorXliff.loadTranslationsListsFromXliff(langFile); + langFile = new File(langPath, Files.getNameWithoutExtension(langFile.getName())+".lng"); + tx.saveAsLngFile(null, langFile, lng); + } + if (post.containsKey("use_lang") && "on".equals(post.get("use_lang"))) { - Translator.changeLang(env, langPath, url.substring(url.lastIndexOf('/'), url.length())); + Translator.changeLang(env, langPath, langFile.getName()); } } catch (final IOException e) { prop.put("status", "2");//error saving the language file diff --git a/locales/de.lng b/locales/de.lng index f2d55f2a7..2d2701ac3 100644 --- a/locales/de.lng +++ b/locales/de.lng @@ -549,6 +549,7 @@ Current language==Aktuelle Sprache Author(s) (chronological)==Autoren (chronologisch) Send additions to maintainer==Schicken Sie Ergänzungen bitte an Available Languages==Verfügbare Sprachen +Supported formats are the internal language file (extension .lng) or XLIFF (extension .xlf) format.==Unterstütztes Format ist das interne Sprachdatei (Dateiendung .lng) oder XLIFF (Dateiendung .xlf) Format. Install new language from URL==Neue Sprachdatei herunterladen Use this language==Diese Sprachdatei sofort benutzen "Use"=="Benutzen"