support xliff for downloaded of language file

pull/51/head
reger 9 years ago
parent 2343e3f1cd
commit ba5161966f

@ -39,14 +39,15 @@
</form> </form>
<form action="ConfigLanguage_p.html" accept-charset="UTF-8"> <form action="ConfigLanguage_p.html" accept-charset="UTF-8">
<fieldset> <fieldset><legend>Download Language File</legend>
<p>Supported formats are the internal language file (extension .lng) or XLIFF (extension .xlf) format.</p>
<dl> <dl>
<dt><label for="url_install">Install new language from URL</label>:</dt> <dt><label for="url_install">Install new language from URL</label>:</dt>
<dd> <dd>
<input type="text" name="url" id="url_install" size="30" /> <input type="text" name="url" id="url_install" size="30" />
</dd> </dd>
<dt><label for="use_lang"> Use this language</label></dt> <dt><label for="use_lang">Use this language</label></dt>
<dd> <dd>
<input type="checkbox" name="use_lang" id="use_lang" value="on" checked="checked" /> <input type="checkbox" name="use_lang" id="use_lang" value="on" checked="checked" />
</dd> </dd>

@ -29,6 +29,7 @@
//javac -classpath .:../Classes Blacklist_p.java //javac -classpath .:../Classes Blacklist_p.java
//if the shell's current path is HTROOT //if the shell's current path is HTROOT
import com.google.common.io.Files;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -48,6 +49,7 @@ import net.yacy.kelondro.util.FileUtils;
import net.yacy.search.Switchboard; import net.yacy.search.Switchboard;
import net.yacy.server.serverObjects; import net.yacy.server.serverObjects;
import net.yacy.server.serverSwitch; import net.yacy.server.serverSwitch;
import net.yacy.utils.translation.TranslatorXliff;
public class ConfigLanguage_p { public class ConfigLanguage_p {
@ -103,15 +105,25 @@ public class ConfigLanguage_p {
final DigestURL u = new DigestURL(url); final DigestURL u = new DigestURL(url);
it = FileUtils.strings(u.get(ClientIdentification.yacyInternetCrawlerAgent, null, null)); it = FileUtils.strings(u.get(ClientIdentification.yacyInternetCrawlerAgent, null, null));
try { 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()); final OutputStreamWriter bw = new OutputStreamWriter(new FileOutputStream(langFile), StandardCharsets.UTF_8.name());
while (it.hasNext()) { while (it.hasNext()) {
bw.write(it.next() + "\n"); bw.write(it.next() + "\n");
} }
bw.close(); 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"))) { 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) { } catch (final IOException e) {
prop.put("status", "2");//error saving the language file prop.put("status", "2");//error saving the language file

@ -549,6 +549,7 @@ Current language</label>==Aktuelle Sprache</label>
Author(s) (chronological)</label>==Autoren (chronologisch)</label> Author(s) (chronological)</label>==Autoren (chronologisch)</label>
Send additions to maintainer</em>==Schicken Sie Ergänzungen bitte an</em> Send additions to maintainer</em>==Schicken Sie Ergänzungen bitte an</em>
Available Languages</label>==Verfügbare Sprachen</label> Available Languages</label>==Verfügbare Sprachen</label>
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 Install new language from URL==Neue Sprachdatei herunterladen
Use this language==Diese Sprachdatei sofort benutzen Use this language==Diese Sprachdatei sofort benutzen
"Use"=="Benutzen" "Use"=="Benutzen"

Loading…
Cancel
Save