diff --git a/.classpath b/.classpath index 6b18d81e5..c28cde823 100644 --- a/.classpath +++ b/.classpath @@ -20,7 +20,7 @@ - + @@ -48,20 +48,20 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/build.xml b/build.xml index 74df0a44e..84085d205 100644 --- a/build.xml +++ b/build.xml @@ -168,7 +168,7 @@ - + @@ -190,20 +190,20 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/htroot/ConfigBasic.java b/htroot/ConfigBasic.java index 8c8d79ade..378ee2e07 100644 --- a/htroot/ConfigBasic.java +++ b/htroot/ConfigBasic.java @@ -36,7 +36,6 @@ import java.util.regex.Pattern; import net.yacy.cora.protocol.Domains; import net.yacy.cora.protocol.HeaderFramework; import net.yacy.cora.protocol.RequestHeader; -import net.yacy.data.Translator; import net.yacy.data.WorkTables; import net.yacy.http.YaCyHttpServer; import net.yacy.kelondro.workflow.InstantBusyThread; @@ -46,6 +45,7 @@ import net.yacy.search.SwitchboardConstants; import net.yacy.server.serverObjects; import net.yacy.server.serverSwitch; import net.yacy.server.http.HTTPDFileHandler; +import net.yacy.utils.translation.TranslatorXliff; import net.yacy.utils.upnp.UPnPMappingType; import net.yacy.utils.upnp.UPnP; @@ -85,7 +85,7 @@ public class ConfigBasic { // language settings if (post != null && post.containsKey("language") && !lang.equals(post.get("language", "default")) && - (Translator.changeLang(env, langPath, post.get("language", "default") + ".lng"))) { + (new TranslatorXliff().changeLang(env, langPath, post.get("language", "default") + ".lng"))) { prop.put("changedLanguage", "1"); } diff --git a/htroot/ConfigLanguage_p.html b/htroot/ConfigLanguage_p.html index 3ddc8a644..d0cca65c6 100644 --- a/htroot/ConfigLanguage_p.html +++ b/htroot/ConfigLanguage_p.html @@ -57,6 +57,7 @@

Make sure that you only download data from trustworthy sources. The new language file might overwrite existing data if a file of the same name exists already.

+

Simple Editor to add untranslated text

#(status)# ::

Unable to get URL: #[url]#

diff --git a/htroot/ConfigLanguage_p.java b/htroot/ConfigLanguage_p.java index 0ec64ea82..eff442e69 100644 --- a/htroot/ConfigLanguage_p.java +++ b/htroot/ConfigLanguage_p.java @@ -82,7 +82,7 @@ public class ConfigLanguage_p { * directory traversal attacks! */ if (langFiles.contains(selectedLanguage) || selectedLanguage.startsWith("default")) { - Translator.changeLang(env, langPath, selectedLanguage); + new TranslatorXliff().changeLang(env, langPath, selectedLanguage); } //delete language file @@ -95,6 +95,7 @@ public class ConfigLanguage_p { if (langFiles.contains(selectedLanguage)) { final File langfile= new File(langPath, selectedLanguage); FileUtils.deletedelete(langfile); + new TranslatorXliff().getScratchFile(langfile).delete(); } //load language file from URL @@ -105,7 +106,8 @@ public class ConfigLanguage_p { final DigestURL u = new DigestURL(url); it = FileUtils.strings(u.get(ClientIdentification.yacyInternetCrawlerAgent, null, null)); try { - File langFile = new File(langPath, u.getFileName()); + TranslatorXliff tx = new TranslatorXliff(); + File langFile = tx.getScratchFile(new File(langPath, u.getFileName())); final OutputStreamWriter bw = new OutputStreamWriter(new FileOutputStream(langFile), StandardCharsets.UTF_8.name()); while (it.hasNext()) { @@ -116,14 +118,13 @@ public class ConfigLanguage_p { // 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); + Map> lng = tx.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, langFile.getName()); + tx.changeLang(env, langPath, langFile.getName()); } } catch (final IOException e) { prop.put("status", "2");//error saving the language file diff --git a/htroot/Translator_p.html b/htroot/Translator_p.html new file mode 100644 index 000000000..772fe221c --- /dev/null +++ b/htroot/Translator_p.html @@ -0,0 +1,53 @@ + + + + YaCy '#[clientname]#': Translation Editor + #%env/templates/metas.template%# + + + + + #%env/templates/header.template%# + #%env/templates/submenuDesign.template%# +

Translation Editor

+ +

Translate untranslated text of the user interface (current language). The modified translation file is stored in DATA/LOCALE directory

+ +
+ + + +

Target Language: #[targetlang]#

#[errmsg]#

+
+ + view it + + + + + + #{textlist}# + + + + + #{/textlist}# +
Source TextTranslated Text ( #[targetlang]# )
+ + + + #(filteruntranslated)#::#(/filteruntranslated)# +
+ + + +
+
+ + #%env/templates/footer.template%# + + diff --git a/htroot/Translator_p.java b/htroot/Translator_p.java new file mode 100644 index 000000000..a8aa5b9a0 --- /dev/null +++ b/htroot/Translator_p.java @@ -0,0 +1,127 @@ + +/** + * Translator_p + * Copyright 2012 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany + * First released 14.09.2011 at http://yacy.net + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program in the file lgpl21.txt + * If not, see . + */ +import java.io.File; +import java.io.IOException; +import java.util.Iterator; +import java.util.Map; +import net.yacy.cora.protocol.RequestHeader; +import net.yacy.cora.util.ConcurrentLog; +import net.yacy.search.Switchboard; +import net.yacy.server.serverObjects; +import net.yacy.server.serverSwitch; +import net.yacy.server.servletProperties; +import net.yacy.utils.translation.CreateTranslationMasters; + +public class Translator_p { + + public static servletProperties respond(@SuppressWarnings("unused") final RequestHeader requestHeader, @SuppressWarnings("unused") final serverObjects post, @SuppressWarnings("unused") final serverSwitch env) { + try { + final servletProperties prop = new servletProperties(); + final Switchboard sb = (Switchboard) env; + + String langcfg = env.getConfig("locale.language", "default"); + prop.put("targetlang", langcfg); + if ("default".equals(langcfg)) { + prop.put("errmsg", "activate a different language"); + return prop; + } else { + prop.put("errmsg", ""); + } + + File lngfile = new File("locales", langcfg + ".lng"); + CreateTranslationMasters ctm = new CreateTranslationMasters(/*new File ("locales","master.lng.xlf")*/); + + File masterxlf = new File("locales", "master.lng.xlf"); + if (!masterxlf.exists()) ctm.createMasterTranslationLists(masterxlf); + Map> origTrans = ctm.joinMasterTranslationLists(masterxlf, lngfile); + int i = 0; + if (origTrans.size() > 0) { + String filename = origTrans.keySet().iterator().next(); + if (post != null && post.containsKey("sourcefile")) { + filename = post.get("sourcefile", filename); + } + + Iterator filenameit = origTrans.keySet().iterator(); + + while (filenameit.hasNext()) { + String tmp = filenameit.next(); + prop.put("filelist_" + i + "_filename", tmp); + prop.put("filelist_" + i + "_selected", tmp.equals(filename)); + i++; + } + prop.put("filelist", i); + + prop.add("sourcefile", filename); + Map origTextList = origTrans.get(filename); + + i = 0; + boolean filteruntranslated = false; + int textlistid = -1; + if (post != null) { + filteruntranslated = post.getBoolean("filteruntranslated"); + if (filteruntranslated) { + prop.put("filter.checked", 1); + } else { + prop.put("filter.checked", 0); + } + textlistid = post.getInt("approve", -1); + } + boolean changed = false; + for (String sourcetext : origTextList.keySet()) { + String targettxt = origTextList.get(sourcetext); + if (targettxt == null || targettxt.isEmpty()) { + prop.put("textlist_" + i + "_filteruntranslated", true); + } else if (filteruntranslated) { + continue; + } + if (i == textlistid && post != null) { + String t = post.get("targettxt" + Integer.toString(textlistid)); + // correct common partial html markup (part of text identification for words also used as html parameter) + if (!t.isEmpty()) { + if (sourcetext.startsWith(">") && !t.startsWith(">")) t=">"+t; + if (sourcetext.endsWith("<") && !t.endsWith("<")) t=t+"<"; + } + targettxt = t; + origTextList.replace(sourcetext, targettxt); + changed = true; + } + prop.putHTML("textlist_" + i + "_sourcetxt", sourcetext); + prop.putHTML("textlist_" + i + "_targettxt", targettxt); + prop.put("textlist_" + i + "_tokenid", Integer.toString(i)); + prop.put("textlist_" + i + "_filteruntranslated_tokenid", Integer.toString(i)); + //prop.put("textlist_" + i +"_filteruntranslated", filteruntranslated); + i++; + } + if (post != null && post.containsKey("savetranslationlist")) { + changed = true; + } + if (changed) { + ctm.saveAsLngFile(langcfg, ctm.getScratchFile(lngfile), origTrans); + } + } + prop.put("textlist", i); + return prop; + } catch (IOException ex) { + ConcurrentLog.logException(ex); + } + return null; + } +} diff --git a/lib/commons-fileupload-1.3.1.jar b/lib/commons-fileupload-1.3.1.jar deleted file mode 100644 index af0cda226..000000000 Binary files a/lib/commons-fileupload-1.3.1.jar and /dev/null differ diff --git a/lib/commons-fileupload-1.3.1.License b/lib/commons-fileupload-1.3.2.License similarity index 100% rename from lib/commons-fileupload-1.3.1.License rename to lib/commons-fileupload-1.3.2.License diff --git a/lib/commons-fileupload-1.3.2.jar b/lib/commons-fileupload-1.3.2.jar new file mode 100644 index 000000000..4975590e3 Binary files /dev/null and b/lib/commons-fileupload-1.3.2.jar differ diff --git a/lib/jetty-9.2.16.v20160414.License b/lib/jetty-9.2.17.v20160517.License similarity index 100% rename from lib/jetty-9.2.16.v20160414.License rename to lib/jetty-9.2.17.v20160517.License diff --git a/lib/jetty-client-9.2.16.v20160414.jar b/lib/jetty-client-9.2.17.v20160517.jar similarity index 65% rename from lib/jetty-client-9.2.16.v20160414.jar rename to lib/jetty-client-9.2.17.v20160517.jar index 18f1bdf67..f39a9f240 100644 Binary files a/lib/jetty-client-9.2.16.v20160414.jar and b/lib/jetty-client-9.2.17.v20160517.jar differ diff --git a/lib/jetty-continuation-9.2.16.v20160414.jar b/lib/jetty-continuation-9.2.17.v20160517.jar similarity index 52% rename from lib/jetty-continuation-9.2.16.v20160414.jar rename to lib/jetty-continuation-9.2.17.v20160517.jar index f0a746693..4c7cc8689 100644 Binary files a/lib/jetty-continuation-9.2.16.v20160414.jar and b/lib/jetty-continuation-9.2.17.v20160517.jar differ diff --git a/lib/jetty-deploy-9.2.16.v20160414.jar b/lib/jetty-deploy-9.2.17.v20160517.jar similarity index 83% rename from lib/jetty-deploy-9.2.16.v20160414.jar rename to lib/jetty-deploy-9.2.17.v20160517.jar index 6782b7244..c6da62d2c 100644 Binary files a/lib/jetty-deploy-9.2.16.v20160414.jar and b/lib/jetty-deploy-9.2.17.v20160517.jar differ diff --git a/lib/jetty-http-9.2.16.v20160414.jar b/lib/jetty-http-9.2.17.v20160517.jar similarity index 65% rename from lib/jetty-http-9.2.16.v20160414.jar rename to lib/jetty-http-9.2.17.v20160517.jar index 5290c1866..57dba992c 100644 Binary files a/lib/jetty-http-9.2.16.v20160414.jar and b/lib/jetty-http-9.2.17.v20160517.jar differ diff --git a/lib/jetty-io-9.2.16.v20160414.jar b/lib/jetty-io-9.2.17.v20160517.jar similarity index 76% rename from lib/jetty-io-9.2.16.v20160414.jar rename to lib/jetty-io-9.2.17.v20160517.jar index dbd93477f..7c6f8ea99 100644 Binary files a/lib/jetty-io-9.2.16.v20160414.jar and b/lib/jetty-io-9.2.17.v20160517.jar differ diff --git a/lib/jetty-jmx-9.2.16.v20160414.jar b/lib/jetty-jmx-9.2.17.v20160517.jar similarity index 82% rename from lib/jetty-jmx-9.2.16.v20160414.jar rename to lib/jetty-jmx-9.2.17.v20160517.jar index d466b23e0..234afd48a 100644 Binary files a/lib/jetty-jmx-9.2.16.v20160414.jar and b/lib/jetty-jmx-9.2.17.v20160517.jar differ diff --git a/lib/jetty-proxy-9.2.16.v20160414.jar b/lib/jetty-proxy-9.2.17.v20160517.jar similarity index 83% rename from lib/jetty-proxy-9.2.16.v20160414.jar rename to lib/jetty-proxy-9.2.17.v20160517.jar index 25e1af612..b05b1859c 100644 Binary files a/lib/jetty-proxy-9.2.16.v20160414.jar and b/lib/jetty-proxy-9.2.17.v20160517.jar differ diff --git a/lib/jetty-security-9.2.16.v20160414.jar b/lib/jetty-security-9.2.17.v20160517.jar similarity index 80% rename from lib/jetty-security-9.2.16.v20160414.jar rename to lib/jetty-security-9.2.17.v20160517.jar index d594e1c48..c4cc1e364 100644 Binary files a/lib/jetty-security-9.2.16.v20160414.jar and b/lib/jetty-security-9.2.17.v20160517.jar differ diff --git a/lib/jetty-server-9.2.16.v20160414.jar b/lib/jetty-server-9.2.17.v20160517.jar similarity index 81% rename from lib/jetty-server-9.2.16.v20160414.jar rename to lib/jetty-server-9.2.17.v20160517.jar index 11a2d2896..4414c83af 100644 Binary files a/lib/jetty-server-9.2.16.v20160414.jar and b/lib/jetty-server-9.2.17.v20160517.jar differ diff --git a/lib/jetty-servlet-9.2.16.v20160414.jar b/lib/jetty-servlet-9.2.17.v20160517.jar similarity index 68% rename from lib/jetty-servlet-9.2.16.v20160414.jar rename to lib/jetty-servlet-9.2.17.v20160517.jar index e5ce8fb30..2af78c045 100644 Binary files a/lib/jetty-servlet-9.2.16.v20160414.jar and b/lib/jetty-servlet-9.2.17.v20160517.jar differ diff --git a/lib/jetty-servlets-9.2.16.v20160414.jar b/lib/jetty-servlets-9.2.17.v20160517.jar similarity index 80% rename from lib/jetty-servlets-9.2.16.v20160414.jar rename to lib/jetty-servlets-9.2.17.v20160517.jar index a4ef0e85b..dfe567179 100644 Binary files a/lib/jetty-servlets-9.2.16.v20160414.jar and b/lib/jetty-servlets-9.2.17.v20160517.jar differ diff --git a/lib/jetty-util-9.2.16.v20160414.jar b/lib/jetty-util-9.2.17.v20160517.jar similarity index 79% rename from lib/jetty-util-9.2.16.v20160414.jar rename to lib/jetty-util-9.2.17.v20160517.jar index b7a8ec3d4..5337754f4 100644 Binary files a/lib/jetty-util-9.2.16.v20160414.jar and b/lib/jetty-util-9.2.17.v20160517.jar differ diff --git a/lib/jetty-webapp-9.2.16.v20160414.jar b/lib/jetty-webapp-9.2.17.v20160517.jar similarity index 89% rename from lib/jetty-webapp-9.2.16.v20160414.jar rename to lib/jetty-webapp-9.2.17.v20160517.jar index 2f591749e..06f1ee655 100644 Binary files a/lib/jetty-webapp-9.2.16.v20160414.jar and b/lib/jetty-webapp-9.2.17.v20160517.jar differ diff --git a/lib/jetty-xml-9.2.16.v20160414.jar b/lib/jetty-xml-9.2.17.v20160517.jar similarity index 66% rename from lib/jetty-xml-9.2.16.v20160414.jar rename to lib/jetty-xml-9.2.17.v20160517.jar index 23d8c6384..f71e16203 100644 Binary files a/lib/jetty-xml-9.2.16.v20160414.jar and b/lib/jetty-xml-9.2.17.v20160517.jar differ diff --git a/pom.xml b/pom.xml index 51d17b892..5fdf70597 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 5.5.1 - 9.2.16.v20160414 + 9.2.17.v20160517 ${DSTAMP} @@ -332,7 +332,8 @@ commons-fileupload commons-fileupload - 1.3.1 + 1.3.2 + jar commons-io diff --git a/source/net/yacy/cora/protocol/Domains.java b/source/net/yacy/cora/protocol/Domains.java index 5f25eeb06..8ed238453 100644 --- a/source/net/yacy/cora/protocol/Domains.java +++ b/source/net/yacy/cora/protocol/Domains.java @@ -101,8 +101,6 @@ public class Domains { private static Set publicIPv4HostAddresses = new HashSet(); // subset of myHostAddresses private static Set publicIPv6HostAddresses = new HashSet(); // subset of myHostAddresses private static Set localHostNames = new HashSet(); // subset of myHostNames - private static Set publicIPv4HostNames = new HashSet(); // subset of myHostNames - private static Set publicIPv6HostNames = new HashSet(); // subset of myHostNames static { localHostNames.add(LOCALHOST); try { @@ -179,10 +177,8 @@ public class Domains { ConcurrentLog.info("Domain Init", "local host address: " + hostaddress + " (public)"); if (a instanceof Inet4Address) { publicIPv4HostAddresses.add(a); - if (hostname != null) {publicIPv4HostNames.add(hostname); publicIPv4HostNames.add(hostaddress);} } else { publicIPv6HostAddresses.add(a); - if (hostname != null) {publicIPv6HostNames.add(hostname); publicIPv6HostNames.add(hostaddress);} } } } diff --git a/source/net/yacy/crawler/CrawlSwitchboard.java b/source/net/yacy/crawler/CrawlSwitchboard.java index 9e3b18081..f6e5c1619 100644 --- a/source/net/yacy/crawler/CrawlSwitchboard.java +++ b/source/net/yacy/crawler/CrawlSwitchboard.java @@ -521,8 +521,8 @@ public final class CrawlSwitchboard { CrawlProfile.getRecrawlDate(CRAWL_PROFILE_SNIPPET_LOCAL_MEDIA_RECRAWL_CYCLE), -1, true, true, true, false, // crawlingQ, followFrames, obeyHtmlRobotsNoindex, obeyHtmlRobotsNofollow, - false, - false, + false, // indexText + false, // indexMedia true, false, -1, false, true, CrawlProfile.MATCH_NEVER_STRING, diff --git a/source/net/yacy/data/Translator.java b/source/net/yacy/data/Translator.java index 97507c091..6f87bd79f 100644 --- a/source/net/yacy/data/Translator.java +++ b/source/net/yacy/data/Translator.java @@ -107,7 +107,7 @@ public class Translator { * @param translationFile the File, which contains the Lists * @return a HashMap, which contains for each File a HashMap with translations. */ - public static Map> loadTranslationsLists(final File translationFile) { + public Map> loadTranslationsLists(final File translationFile) { final Map> lists = new HashMap>(); //list of translationLists for different files. Map translationList = new LinkedHashMap(); //current Translation Table (maintaining input order) @@ -186,7 +186,7 @@ public class Translator { return true; } - public static boolean translateFiles(final File sourceDir, final File destDir, final File baseDir, final File translationFile, final String extensions){ + public boolean translateFiles(final File sourceDir, final File destDir, final File baseDir, final File translationFile, final String extensions){ return translateFiles(sourceDir, destDir, baseDir, loadTranslationsLists(translationFile), extensions); } @@ -219,7 +219,7 @@ public class Translator { return true; } - public static boolean translateFilesRecursive(final File sourceDir, final File destDir, final File translationFile, final String extensions, final String notdir){ + public boolean translateFilesRecursive(final File sourceDir, final File destDir, final File translationFile, final String extensions, final String notdir){ final List dirList=FileUtils.getDirsRecursive(sourceDir, notdir); dirList.add(sourceDir); for (final File file : dirList) { @@ -248,7 +248,7 @@ public class Translator { return map; } - public static boolean changeLang(final serverSwitch env, final File langPath, final String lang) { + public boolean changeLang(final serverSwitch env, final File langPath, final String lang) { boolean ret = false; if ("default".equals(lang) || "default.lng".equals(lang)) { @@ -257,14 +257,10 @@ public class Translator { } else { final String htRootPath = env.getConfig(SwitchboardConstants.HTROOT_PATH, SwitchboardConstants.HTROOT_PATH_DEFAULT); final File sourceDir = new File(env.getAppPath(), htRootPath); - final File destDir = new File(env.getDataPath("locale.translated_html", "DATA/LOCALE/htroot"), lang.substring(0, lang.length() - 4));// cut - // .lng - //File destDir = new File(env.getRootPath(), htRootPath + "/locale/" + lang.substring(0, lang.length() - 4));// cut - // .lng + final File destDir = new File(env.getDataPath("locale.translated_html", "DATA/LOCALE/htroot"), lang.substring(0, lang.length() - 4));// cut .lng final File translationFile = new File(langPath, lang); - //if (translator.translateFiles(sourceDir, destDir, translationFile, "html")) { - if (Translator.translateFilesRecursive(sourceDir, destDir, translationFile, "html,template,inc", "locale")) { + if (translateFilesRecursive(sourceDir, destDir, translationFile, "html,template,inc", "locale")) { env.setConfig("locale.language", lang.substring(0, lang.length() - 4)); Formatter.setLocale(env.getConfig("locale.language", "en")); try { diff --git a/source/net/yacy/search/AutoSearch.java b/source/net/yacy/search/AutoSearch.java index 7783b76e7..5e88f53c9 100644 --- a/source/net/yacy/search/AutoSearch.java +++ b/source/net/yacy/search/AutoSearch.java @@ -289,7 +289,7 @@ public class AutoSearch extends AbstractBusyThread { urls.add(new DigestURL(entry, (byte[]) null)); this.gotresults++; } - sb.addToIndex(urls, null, "AutoSearch", null, true); + sb.addToCrawler(urls, false); ConcurrentLog.info(AutoSearch.class.getName(), "added " + urls.size() + " results from " + seed.getName() + " to index for query=" + currentQuery); } catch (IOException ex) { ConcurrentLog.info(AutoSearch.class.getName(), "no answer from " + seed.getName()); diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.java index 43ba97188..d0167afe6 100644 --- a/source/net/yacy/search/Switchboard.java +++ b/source/net/yacy/search/Switchboard.java @@ -3292,6 +3292,8 @@ public final class Switchboard extends serverSwitch { /** * load the content of a URL, parse the content and add the content to the index This process is started * concurrently. The method returns immediately after the call. + * Loaded/indexed pages are added to the given SearchEvent. If this is not required prefer addToCrawler + * to spare concurrent processes, bandwidth and intransparent crawl/load activity * * @param url the url that shall be indexed * @param searchEvent (optional) a search event that shall get results from the indexed pages directly @@ -3328,7 +3330,7 @@ public final class Switchboard extends serverSwitch { continue; } requests.add(request); - } + } new Thread() { @Override diff --git a/source/net/yacy/utils/translation/CreateTranslationMasters.java b/source/net/yacy/utils/translation/CreateTranslationMasters.java index 67aca5df1..187984447 100644 --- a/source/net/yacy/utils/translation/CreateTranslationMasters.java +++ b/source/net/yacy/utils/translation/CreateTranslationMasters.java @@ -89,7 +89,7 @@ public class CreateTranslationMasters extends TranslatorXliff { public void createMasterTranslationLists(File masterOutputFile) throws IOException { Map> xliffTrans; if (masterOutputFile.exists()) // if file exists, conserve existing master content (may be updated by external tool) - xliffTrans = TranslatorXliff.loadTranslationsListsFromXliff(masterOutputFile); + xliffTrans = loadTranslationsListsFromXliff(masterOutputFile); else xliffTrans = new TreeMap>(); @@ -97,7 +97,7 @@ public class CreateTranslationMasters extends TranslatorXliff { for (String filename : lngFiles) { // load translation list ConcurrentLog.info("TRANSLATOR", "include translation file " + filename); - Map> origTrans = Translator.loadTranslationsLists(new File("locales", filename)); + Map> origTrans = loadTranslationsLists(new File("locales", filename)); for (String transfilename : origTrans.keySet()) { // get translation filename File checkfile = new File("htroot", transfilename); @@ -154,10 +154,10 @@ public class CreateTranslationMasters extends TranslatorXliff { public Map> joinMasterTranslationLists(File xlifmaster, File lngfile) throws IOException { final String filename = lngfile.getName(); - Map> xliffTrans = TranslatorXliff.loadTranslationsListsFromXliff(xlifmaster); + Map> xliffTrans = loadTranslationsListsFromXliff(xlifmaster); // load translation list System.out.println("join into master translation file " + filename); - Map> origTrans = Translator.loadTranslationsLists(lngfile); + Map> origTrans = loadTranslationsLists(lngfile); for (String transfilename : origTrans.keySet()) { // get translation filename // compare translation list diff --git a/source/net/yacy/utils/translation/ListNonTranslatedFiles.java b/source/net/yacy/utils/translation/ListNonTranslatedFiles.java index 69d317ced..075a93f88 100755 --- a/source/net/yacy/utils/translation/ListNonTranslatedFiles.java +++ b/source/net/yacy/utils/translation/ListNonTranslatedFiles.java @@ -87,7 +87,7 @@ public class ListNonTranslatedFiles extends TranslatorUtil { + translationFile); try { - Set translatedRelativePaths = Translator.loadTranslationsLists(translationFile).keySet(); + Set translatedRelativePaths = new Translator().loadTranslationsLists(translationFile).keySet(); List srcFiles = FileUtils.getFilesRecursive(sourceDir, excludedDir, fileFilter); diff --git a/source/net/yacy/utils/translation/TranslateAll.java b/source/net/yacy/utils/translation/TranslateAll.java index e78f70b5d..f5162aece 100755 --- a/source/net/yacy/utils/translation/TranslateAll.java +++ b/source/net/yacy/utils/translation/TranslateAll.java @@ -86,7 +86,7 @@ public class TranslateAll extends TranslatorUtil { File localeDestDir = new File(destDir, localeCode); localeDestDir.mkdirs(); - Translator.translateFilesRecursive(sourceDir, localeDestDir, + new Translator().translateFilesRecursive(sourceDir, localeDestDir, translationFile, extensions, "locale"); } } diff --git a/source/net/yacy/utils/translation/TranslateAllToOneLanguage.java b/source/net/yacy/utils/translation/TranslateAllToOneLanguage.java index e12f28e31..f6a2d00f5 100755 --- a/source/net/yacy/utils/translation/TranslateAllToOneLanguage.java +++ b/source/net/yacy/utils/translation/TranslateAllToOneLanguage.java @@ -66,7 +66,7 @@ public class TranslateAllToOneLanguage extends TranslatorUtil { + translationFile); try { - Translator.translateFilesRecursive(sourceDir, destDir, + new Translator().translateFilesRecursive(sourceDir, destDir, translationFile, extensions, "locale"); } finally { ConcurrentLog.shutdown(); diff --git a/source/net/yacy/utils/translation/TranslatorXliff.java b/source/net/yacy/utils/translation/TranslatorXliff.java index dbef668f3..ddfd45453 100644 --- a/source/net/yacy/utils/translation/TranslatorXliff.java +++ b/source/net/yacy/utils/translation/TranslatorXliff.java @@ -44,6 +44,7 @@ import javax.xml.bind.Unmarshaller; import net.yacy.cora.util.ConcurrentLog; import net.yacy.data.Translator; +import net.yacy.search.Switchboard; import org.oasis.xliff.core_12.Body; import org.oasis.xliff.core_12.Target; @@ -66,7 +67,7 @@ public class TranslatorXliff extends Translator { * @return a HashMap, which contains for each File a HashMap with * translations. */ - public static Map> loadTranslationsListsFromXliff(final File xliffFile) { + public Map> loadTranslationsListsFromXliff(final File xliffFile) { final Map> lngLists = new TreeMap>(); //list of translationLists for different files. /** @@ -144,11 +145,13 @@ public class TranslatorXliff extends Translator { * @param xliffFile * @return translatio map */ - public static Map> loadTranslationsLists(final File xliffFile) { + @Override + public Map> loadTranslationsLists(final File xliffFile) { + File locallng = getScratchFile(xliffFile); if (xliffFile.getName().toLowerCase().endsWith(".xlf") || xliffFile.getName().toLowerCase().endsWith(".xliff")) { - return loadTranslationsListsFromXliff(xliffFile); + return locallng.exists() ? loadTranslationsListsFromXliff(locallng) : loadTranslationsListsFromXliff(xliffFile); } else { - return Translator.loadTranslationsLists(xliffFile); + return locallng.exists() ? super.loadTranslationsLists(locallng) : super.loadTranslationsLists(xliffFile); } } @@ -317,4 +320,21 @@ public class TranslatorXliff extends Translator { } return s; } + + /** + * Get the path to a work/scratch file in the DATA/LOCALE directory with the + * same name as given in the langPath + * + * @param langFile the path with filename to the language file + * @return a path to DATA/LOCALE/langFile.filename() + */ + public File getScratchFile(final File langFile) { + if (Switchboard.getSwitchboard() != null) { // for debug and testing were switchboard is null + File f = Switchboard.getSwitchboard().getDataPath("locale.translated_html", "DATA/LOCALE"); + f = new File(f.getParentFile(), langFile.getName()); + return f; + } else { + return langFile; + } + } } diff --git a/source/net/yacy/yacy.java b/source/net/yacy/yacy.java index 361f18c54..4e26f6dc4 100644 --- a/source/net/yacy/yacy.java +++ b/source/net/yacy/yacy.java @@ -46,7 +46,6 @@ import net.yacy.cora.protocol.TimeoutRequest; import net.yacy.cora.protocol.http.HTTPClient; import net.yacy.cora.sorting.Array; import net.yacy.cora.util.ConcurrentLog; -import net.yacy.data.Translator; import net.yacy.gui.YaCyApp; import net.yacy.gui.framework.Browser; import net.yacy.http.Jetty9HttpServerImpl; @@ -67,6 +66,7 @@ import net.yacy.cora.protocol.ConnectionInfo; import net.yacy.crawler.retrieval.Response; import net.yacy.peers.Seed; import net.yacy.server.serverSwitch; +import net.yacy.utils.translation.TranslatorXliff; /** @@ -362,7 +362,7 @@ public final class yacy { if (currentRev == null || !currentRev.equals(sb.getConfig(Seed.VERSION, ""))) try { //is this another version?! final File sourceDir = new File(sb.getConfig(SwitchboardConstants.HTROOT_PATH, SwitchboardConstants.HTROOT_PATH_DEFAULT)); final File destDir = new File(sb.getDataPath("locale.translated_html", "DATA/LOCALE/htroot"), lang); - if (Translator.translateFilesRecursive(sourceDir, destDir, new File(locale_source, lang + ".lng"), "html,template,inc", "locale")){ //translate it + if (new TranslatorXliff().translateFilesRecursive(sourceDir, destDir, new File(locale_source, lang + ".lng"), "html,template,inc", "locale")){ //translate it //write the new Versionnumber final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version")))); bw.write(sb.getConfig(Seed.VERSION, "Error getting Version")); diff --git a/test/java/net/yacy/utils/translation/TranslatorXliffTest.java b/test/java/net/yacy/utils/translation/TranslatorXliffTest.java index 6534e4852..bc5a3ecdb 100644 --- a/test/java/net/yacy/utils/translation/TranslatorXliffTest.java +++ b/test/java/net/yacy/utils/translation/TranslatorXliffTest.java @@ -31,7 +31,7 @@ public class TranslatorXliffTest { for (String filename : lngFiles) { // load translation list System.out.println("Test translation file " + filename); - Map> origTrans = Translator.loadTranslationsLists(new File("locales", filename)); + Map> origTrans = new Translator().loadTranslationsLists(new File("locales", filename)); TranslatorXliff txlif = new TranslatorXliff(); // save as xliff file