translator updates:

- config string for chinese
- do not copy the language file to DATA/LOCALE any more (and do not use
them there, this is really confusing for new translators)
pull/1/head
Michael Christen 13 years ago
parent ac5b1e891d
commit 17f962fceb

@ -223,9 +223,7 @@ defaultFiles = index.html,index.htm,default.html,search.html,console.html,contro
# the <dir> must exist as sub-path to htLocalePath # the <dir> must exist as sub-path to htLocalePath
# the htLocaleSelection selects from the given locales, value=one-of-<dir> # the htLocaleSelection selects from the given locales, value=one-of-<dir>
locale.source=locales locale.source=locales
locale.work=DATA/LOCALE/locales
locale.translated_html=DATA/LOCALE/htroot locale.translated_html=DATA/LOCALE/htroot
locale.lang=default/English,de/Deutsch,fr/Fran&ccedil;ais,nl/Nederlands,it/Italiano,es/Espa&ntilde;ol,pt/Portug&ecirc;s,fi/Suomi,se/Svenska,dk/Dansk,gr/E&lambda;&lambda;&eta;v&iota;&kappa;&alpha;,sk/Slovensky
locale.language=default locale.language=default
# virtual host for httpdFileServlet access # virtual host for httpdFileServlet access

@ -61,7 +61,7 @@ public class ConfigBasic {
// return variable that accumulates replacements // return variable that accumulates replacements
final Switchboard sb = (Switchboard) env; final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects(); final serverObjects prop = new serverObjects();
final String langPath = env.getDataPath("locale.work", "DATA/LOCALE/locales").getAbsolutePath(); final File langPath = new File(sb.getAppPath("locale.source", "locales").getAbsolutePath());
String lang = env.getConfig("locale.language", "default"); String lang = env.getConfig("locale.language", "default");
final int authentication = sb.adminAuthenticated(header); final int authentication = sb.adminAuthenticated(header);

@ -34,37 +34,35 @@ import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import net.yacy.cora.protocol.ClientIdentification; import net.yacy.cora.protocol.ClientIdentification;
import net.yacy.cora.protocol.RequestHeader; import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.data.meta.DigestURI; import net.yacy.kelondro.data.meta.DigestURI;
import net.yacy.kelondro.util.FileUtils; import net.yacy.kelondro.util.FileUtils;
import net.yacy.search.Switchboard; import net.yacy.search.Switchboard;
import de.anomic.data.WorkTables;
import de.anomic.data.Translator; import de.anomic.data.Translator;
import de.anomic.data.WorkTables;
import de.anomic.server.serverObjects; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
import java.util.Collections;
import java.util.Map;
public class ConfigLanguage_p { public class ConfigLanguage_p {
private final static String LANG_FILENAME_FILTER = "^.*\\.lng$";
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
final serverObjects prop = new serverObjects(); final serverObjects prop = new serverObjects();
final String langPath = env.getDataPath("locale.work", "DATA/LOCALE/locales").getAbsolutePath(); Switchboard sb = (Switchboard) env;
final File langPath = new File(sb.getAppPath("locale.source", "locales").getAbsolutePath());
//Fallback //Fallback
//prop.put("currentlang", ""); //is done by Translationtemplate //prop.put("currentlang", ""); //is done by Translationtemplate
prop.put("status", "0");//nothing prop.put("status", "0");//nothing
List<String> langFiles = FileUtils.getDirListing(langPath, LANG_FILENAME_FILTER); List<String> langFiles = Translator.langFiles(langPath);
if (langFiles == null) { if (langFiles == null) {
return prop; return prop;
} }
@ -128,7 +126,7 @@ public class ConfigLanguage_p {
} }
//re-read language files //re-read language files
langFiles = FileUtils.getDirListing(langPath, LANG_FILENAME_FILTER); langFiles = Translator.langFiles(langPath);
Collections.sort(langFiles); Collections.sort(langFiles);
final Map<String, String> langNames = Translator.langMap(env); final Map<String, String> langNames = Translator.langMap(env);

@ -40,17 +40,16 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import net.yacy.kelondro.logging.Log; import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.FileUtils; import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.Formatter; import net.yacy.kelondro.util.Formatter;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
import java.util.List;
import java.util.Map;
import java.util.Set;
/** /**
* Wordlist based translator * Wordlist based translator
@ -58,6 +57,9 @@ import java.util.Set;
* Uses a Property like file with phrases or single words to translate a string or a file * Uses a Property like file with phrases or single words to translate a string or a file
* */ * */
public class Translator { public class Translator {
public final static String LANG_FILENAME_FILTER = "^.*\\.lng$";
public static String translate(final String source, final Map<String, String> translationTable){ public static String translate(final String source, final Map<String, String> translationTable){
final Set<String> keys = translationTable.keySet(); final Set<String> keys = translationTable.keySet();
String result = source; String result = source;
@ -215,7 +217,7 @@ public class Translator {
} }
public static Map<String, String> langMap(final serverSwitch env) { public static Map<String, String> langMap(final serverSwitch env) {
final String[] ms = env.getConfig("locale.lang", "").split(","); final String[] ms = "default/English,de/Deutsch,fr/Fran&ccedil;ais,nl/Nederlands,it/Italiano,es/Espa&ntilde;ol,pt/Portug&ecirc;s,fi/Suomi,se/Svenska,dk/Dansk,gr/E&lambda;&lambda;&eta;v&iota;&kappa;&alpha;,sk/Slovensky,cn/&#27721;&#35821;/&#28450;&#35486;".split(",");
final Map<String, String> map = new HashMap<String, String>(); final Map<String, String> map = new HashMap<String, String>();
for (final String element : ms) { for (final String element : ms) {
int p = element.indexOf('/'); int p = element.indexOf('/');
@ -225,7 +227,7 @@ public class Translator {
return map; return map;
} }
public static boolean changeLang(final serverSwitch env, final String langPath, final String lang) { public static boolean changeLang(final serverSwitch env, final File langPath, final String lang) {
boolean ret = false; boolean ret = false;
if ("default".equals(lang) || "default.lng".equals(lang)) { if ("default".equals(lang) || "default.lng".equals(lang)) {
@ -256,4 +258,8 @@ public class Translator {
} }
return ret; return ret;
} }
public static List<String> langFiles(File langPath) {
return FileUtils.getDirListing(langPath, Translator.LANG_FILENAME_FILTER);
}
} }

@ -323,26 +323,8 @@ public final class yacy {
// unlock yacyTray browser popup // unlock yacyTray browser popup
Tray.lockBrowserPopup = false; Tray.lockBrowserPopup = false;
// Copy the shipped locales into DATA, existing files are overwritten
final File locale_work = sb.getDataPath("locale.work", "DATA/LOCALE/locales");
final File locale_source = sb.getAppPath("locale.source", "locales");
try{
final File[] locale_source_files = locale_source.listFiles();
mkdirsIfNeseccary(locale_work);
File target;
for (final File locale_source_file : locale_source_files) {
target = new File(locale_work, locale_source_file.getName());
if (locale_source_file.getName().endsWith(".lng")) {
if (target.exists()) delete(target);
FileUtils.copy(locale_source_file, target);
}
}
Log.logInfo("STARTUP", "Copied the default locales to " + locale_work.toString());
}catch(final NullPointerException e){
Log.logSevere("STARTUP", "Nullpointer Exception while copying the default Locales");
}
//regenerate Locales from Translationlist, if needed //regenerate Locales from Translationlist, if needed
final File locale_source = sb.getAppPath("locale.source", "locales");
final String lang = sb.getConfig("locale.language", ""); final String lang = sb.getConfig("locale.language", "");
if (!lang.equals("") && !lang.equals("default")) { //locale is used if (!lang.equals("") && !lang.equals("default")) { //locale is used
String currentRev = ""; String currentRev = "";
@ -357,7 +339,7 @@ public final class yacy {
if (!currentRev.equals(sb.getConfig("svnRevision", ""))) try { //is this another version?! if (!currentRev.equals(sb.getConfig("svnRevision", ""))) try { //is this another version?!
final File sourceDir = new File(sb.getConfig("htRootPath", "htroot")); final File sourceDir = new File(sb.getConfig("htRootPath", "htroot"));
final File destDir = new File(sb.getDataPath("locale.translated_html", "DATA/LOCALE/htroot"), lang); final File destDir = new File(sb.getDataPath("locale.translated_html", "DATA/LOCALE/htroot"), lang);
if (Translator.translateFilesRecursive(sourceDir, destDir, new File(locale_work, lang + ".lng"), "html,template,inc", "locale")){ //translate it if (Translator.translateFilesRecursive(sourceDir, destDir, new File(locale_source, lang + ".lng"), "html,template,inc", "locale")){ //translate it
//write the new Versionnumber //write the new Versionnumber
final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version")))); final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version"))));
bw.write(sb.getConfig("svnRevision", "Error getting Version")); bw.write(sb.getConfig("svnRevision", "Error getting Version"));

Loading…
Cancel
Save