This is the 1st rudimentary approach to support the translatio utilities. It allows currently to edit untranslated text and save it in a local translation file in the DATA/LOCALE directory. + refactor Translator (less static's) to leverage on class overrides and support garbage collection for this 1 time routine + adjust TranslatorXliff to check for local translations in DATA/LOCALE, this includes storing manually downloaded translation files in DATA as well (to keep default untouched) + on 1st call of Translator_p a master tanslation file is generated, checking the supported languages for missing translation text (later this masterfile is planned to part of the distribution, to harmonize translation key text between the languages) Outlook: the local modifications (possibly as translation fragments instead of complete file) to be shared with maintainer using xlif features.pull/56/head
parent
ab7f82f803
commit
a6ba1faa80
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
|
||||
<head>
|
||||
<title>YaCy '#[clientname]#': Translation Editor</title>
|
||||
#%env/templates/metas.template%#
|
||||
|
||||
</head>
|
||||
<body id="Translator">
|
||||
|
||||
#%env/templates/header.template%#
|
||||
#%env/templates/submenuDesign.template%#
|
||||
<h2>Translation Editor</h2>
|
||||
|
||||
<p>Translate untranslated text of the user interface (current language). The modified translation file is stored in DATA/LOCALE directory</p>
|
||||
|
||||
<fieldset>
|
||||
<legend>
|
||||
<label>UI Translation</label>
|
||||
</legend>
|
||||
<p>Target Language: <b>#[targetlang]#</b></p><p class="error">#[errmsg]#</p>
|
||||
<form id="Translation" method="post" action="Translator_p.html" enctype="multipart/form-data" accept-charset="UTF-8">
|
||||
<label for="sourcefile">Source File</label>
|
||||
<select name="sourcefile" onchange="submit();">
|
||||
#{filelist}#
|
||||
<option value="#[filename]#" #(selected)#::selected="selected"#(/selected)#>#[filename]#</option>
|
||||
#{/filelist}#
|
||||
</select> <a href="#[sourcefile]#" target="sourcefilewindow" >view it</a>
|
||||
<label for="filteruntranslated">filter untranslated</label>
|
||||
<input type="checkbox" name="filteruntranslated" id="filteruntranslated" value="true" onclick="submit();" #(filter.checked)#::checked="checked"#(/filter.checked)# />
|
||||
<table>
|
||||
<tr><th style="border-bottom: solid gray; border-bottom-width: 1px;">Source Text</th>
|
||||
<th style="border-bottom: solid gray; border-bottom-width: 1px;">Translated Text ( #[targetlang]# )</th></tr>
|
||||
#{textlist}#
|
||||
<tr>
|
||||
<td style="border-bottom: solid gray; border-bottom-width: 1px;" valign="top">
|
||||
<!--<input type="text" name="sourcetxt" id="sourcetxt#[tokenid]#" size="80" disabled="true" value="#[sourcetxt]#"/>-->
|
||||
<label for="targettxt#[tokenid]#" >#[sourcetxt]#</label>
|
||||
</td>
|
||||
<td style="border-bottom: solid gray; border-bottom-width: 1px;" valign="top" nowrap>
|
||||
<input type="text" name="targettxt#[tokenid]#" id="targettxt#[tokenid]#" size="80" value="#[targettxt]#"/>#(filteruntranslated)#::<button name="approve" type="submit" value="#[tokenid]#" class="btn btn-sm"><span class="glyphicon glyphicon-ok-sign" style="color: green"/></button>#(/filteruntranslated)#
|
||||
</td>
|
||||
</tr>
|
||||
#{/textlist}#
|
||||
</table>
|
||||
|
||||
<input type="submit" name="savetranslationlist" value="Save translation" class="btn btn-primary"/>
|
||||
|
||||
</form>
|
||||
</fieldset>
|
||||
|
||||
#%env/templates/footer.template%#
|
||||
</body>
|
||||
</html>
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<String, Map<String, String>> 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<String> 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<String, String> 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;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue