|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
// translator.java
|
|
|
|
|
// translator.java
|
|
|
|
|
// -------------------------------------
|
|
|
|
|
// part of YACY
|
|
|
|
|
// (C) by Michael Peter Christen; mc@yacy.net
|
|
|
|
@ -59,7 +59,7 @@ import de.anomic.server.serverSwitch;
|
|
|
|
|
public class Translator {
|
|
|
|
|
|
|
|
|
|
public final static String LANG_FILENAME_FILTER = "^.*\\.lng$";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String translate(final String source, final Map<String, String> translationTable){
|
|
|
|
|
final Set<String> keys = translationTable.keySet();
|
|
|
|
|
String result = source;
|
|
|
|
@ -76,7 +76,7 @@ public class Translator {
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load multiple translationLists from one File. Each List starts with #File: relative/path/to/file
|
|
|
|
|
* @param translationFile the File, which contains the Lists
|
|
|
|
@ -119,7 +119,7 @@ public class Translator {
|
|
|
|
|
public static boolean translateFile(final File sourceFile, final File destFile, final File translationFile){
|
|
|
|
|
return translateFile(sourceFile, destFile, loadTranslationsLists(translationFile).get(sourceFile.getName()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean translateFile(final File sourceFile, final File destFile, final Map<String, String> translationList){
|
|
|
|
|
|
|
|
|
|
StringBuilder content = new StringBuilder();
|
|
|
|
@ -140,7 +140,7 @@ public class Translator {
|
|
|
|
|
} catch (final Exception e) {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content = new StringBuilder(translate(content.toString(), translationList));
|
|
|
|
|
BufferedWriter bw = null;
|
|
|
|
|
try{
|
|
|
|
@ -156,7 +156,7 @@ public class Translator {
|
|
|
|
|
} catch (final Exception e) {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -185,7 +185,7 @@ public class Translator {
|
|
|
|
|
} catch (final IndexOutOfBoundsException e) {
|
|
|
|
|
Log.logSevere("TRANSLATOR", "Error creating relative Path for "+sourceFile.getAbsolutePath());
|
|
|
|
|
relativePath = "wrong path"; //not in translationLists
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (translationLists.containsKey(relativePath)) {
|
|
|
|
|
Log.logInfo("TRANSLATOR", "Translating file: "+ relativePath);
|
|
|
|
|
if(!translateFile(
|
|
|
|
@ -217,7 +217,11 @@ public class Translator {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Map<String, String> langMap(final serverSwitch env) {
|
|
|
|
|
final String[] ms = "default/English,de/Deutsch,fr/Français,nl/Nederlands,it/Italiano,es/Español,pt/Portugês,fi/Suomi,se/Svenska,dk/Dansk,gr/Eλληvικα,sk/Slovensky,cn/汉语/漢語".split(",");
|
|
|
|
|
final String[] ms = (
|
|
|
|
|
"default/English,de/Deutsch,fr/Français,nl/Nederlands,it/Italiano,es/Español,pt/Portugês,fi/Suomi,se/Svenska,dk/Dansk," +
|
|
|
|
|
"gr/Eλληvικα,sk/Slovensky,cn/汉语/漢語," +
|
|
|
|
|
"ru/Русский,uk/Українська"
|
|
|
|
|
).split(",");
|
|
|
|
|
final Map<String, String> map = new HashMap<String, String>();
|
|
|
|
|
for (final String element : ms) {
|
|
|
|
|
int p = element.indexOf('/');
|
|
|
|
@ -226,7 +230,7 @@ public class Translator {
|
|
|
|
|
}
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean changeLang(final serverSwitch env, final File langPath, final String lang) {
|
|
|
|
|
boolean ret = false;
|
|
|
|
|
|
|
|
|
@ -258,7 +262,7 @@ public class Translator {
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static List<String> langFiles(File langPath) {
|
|
|
|
|
return FileUtils.getDirListing(langPath, Translator.LANG_FILENAME_FILTER);
|
|
|
|
|
}
|
|
|
|
|