Skip to content

Commit

Permalink
support xliff for downloaded of language file
Browse files Browse the repository at this point in the history
  • Loading branch information
reger committed Apr 10, 2016
1 parent 2343e3f commit ba51619
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 3 additions & 2 deletions htroot/ConfigLanguage_p.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ <h2>Language selection</h2>
</form>

<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>
<dt><label for="url_install">Install new language from URL</label>:</dt>
<dd>
<input type="text" name="url" id="url_install" size="30" />
</dd>

<dt><label for="use_lang"> Use this language</label></dt>
<dt><label for="use_lang">Use this language</label></dt>
<dd>
<input type="checkbox" name="use_lang" id="use_lang" value="on" checked="checked" />
</dd>
Expand Down
16 changes: 14 additions & 2 deletions htroot/ConfigLanguage_p.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,6 +49,7 @@
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 {
Expand Down Expand Up @@ -103,15 +105,25 @@ public static serverObjects respond(@SuppressWarnings("unused") final RequestHea
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
Expand Down
1 change: 1 addition & 0 deletions locales/de.lng
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ Current language</label>==Aktuelle Sprache</label>
Author(s) (chronological)</label>==Autoren (chronologisch)</label>
Send additions to maintainer</em>==Schicken Sie Ergänzungen bitte an</em>
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
Use this language==Diese Sprachdatei sofort benutzen
"Use"=="Benutzen"
Expand Down

2 comments on commit ba51619

@luccioman
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, don't you think custom lng files should be stored in a specific folder, such as DATA/LOCALE? Thus ConfigLanguage_p.html page would only list and allow deletion or overwriting of these files.
Because currently one can overwrite or delete an original lng file, and then can not go back.

I was thinking of this while merging your last changes on my Java Web Start oriented branch (https://github.com/luccioman/yacy_search_server/tree/deployment), because when running yacy this way released language files are included as resources in a single jar and can not be deleted.

@reger24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
you are probably right, also from the systematic (user files). Was wondering myself that it was the way it is (overwrite/delete in systems root w/o reset = e.g. auto-download from github), but didn't spent much thoughts other than mentioning xliff. I'm still dangling around the lng's &'ll've your point in mind.
cu

Please sign in to comment.