|
|
@ -1,4 +1,4 @@
|
|
|
|
// translator.java
|
|
|
|
// translator.java
|
|
|
|
// -------------------------------------
|
|
|
|
// -------------------------------------
|
|
|
|
// part of YACY
|
|
|
|
// part of YACY
|
|
|
|
// (C) by Michael Peter Christen; mc@yacy.net
|
|
|
|
// (C) by Michael Peter Christen; mc@yacy.net
|
|
|
@ -59,7 +59,7 @@ import de.anomic.server.serverSwitch;
|
|
|
|
public class Translator {
|
|
|
|
public class Translator {
|
|
|
|
|
|
|
|
|
|
|
|
public final static String LANG_FILENAME_FILTER = "^.*\\.lng$";
|
|
|
|
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;
|
|
|
@ -76,7 +76,7 @@ public class Translator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Load multiple translationLists from one File. Each List starts with #File: relative/path/to/file
|
|
|
|
* Load multiple translationLists from one File. Each List starts with #File: relative/path/to/file
|
|
|
|
* @param translationFile the File, which contains the Lists
|
|
|
|
* @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){
|
|
|
|
public static boolean translateFile(final File sourceFile, final File destFile, final File translationFile){
|
|
|
|
return translateFile(sourceFile, destFile, loadTranslationsLists(translationFile).get(sourceFile.getName()));
|
|
|
|
return translateFile(sourceFile, destFile, loadTranslationsLists(translationFile).get(sourceFile.getName()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean translateFile(final File sourceFile, final File destFile, final Map<String, String> translationList){
|
|
|
|
public static boolean translateFile(final File sourceFile, final File destFile, final Map<String, String> translationList){
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder content = new StringBuilder();
|
|
|
|
StringBuilder content = new StringBuilder();
|
|
|
@ -140,7 +140,7 @@ public class Translator {
|
|
|
|
} catch (final Exception e) {}
|
|
|
|
} catch (final Exception e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
content = new StringBuilder(translate(content.toString(), translationList));
|
|
|
|
content = new StringBuilder(translate(content.toString(), translationList));
|
|
|
|
BufferedWriter bw = null;
|
|
|
|
BufferedWriter bw = null;
|
|
|
|
try{
|
|
|
|
try{
|
|
|
@ -156,7 +156,7 @@ public class Translator {
|
|
|
|
} catch (final Exception e) {}
|
|
|
|
} catch (final Exception e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -185,7 +185,7 @@ public class Translator {
|
|
|
|
} catch (final IndexOutOfBoundsException e) {
|
|
|
|
} catch (final IndexOutOfBoundsException e) {
|
|
|
|
Log.logSevere("TRANSLATOR", "Error creating relative Path for "+sourceFile.getAbsolutePath());
|
|
|
|
Log.logSevere("TRANSLATOR", "Error creating relative Path for "+sourceFile.getAbsolutePath());
|
|
|
|
relativePath = "wrong path"; //not in translationLists
|
|
|
|
relativePath = "wrong path"; //not in translationLists
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (translationLists.containsKey(relativePath)) {
|
|
|
|
if (translationLists.containsKey(relativePath)) {
|
|
|
|
Log.logInfo("TRANSLATOR", "Translating file: "+ relativePath);
|
|
|
|
Log.logInfo("TRANSLATOR", "Translating file: "+ relativePath);
|
|
|
|
if(!translateFile(
|
|
|
|
if(!translateFile(
|
|
|
@ -217,7 +217,11 @@ public class Translator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Map<String, String> langMap(final serverSwitch env) {
|
|
|
|
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>();
|
|
|
|
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('/');
|
|
|
@ -226,7 +230,7 @@ public class Translator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean changeLang(final serverSwitch env, final File langPath, final String lang) {
|
|
|
|
public static boolean changeLang(final serverSwitch env, final File langPath, final String lang) {
|
|
|
|
boolean ret = false;
|
|
|
|
boolean ret = false;
|
|
|
|
|
|
|
|
|
|
|
@ -258,7 +262,7 @@ public class Translator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static List<String> langFiles(File langPath) {
|
|
|
|
public static List<String> langFiles(File langPath) {
|
|
|
|
return FileUtils.getDirListing(langPath, Translator.LANG_FILENAME_FILTER);
|
|
|
|
return FileUtils.getDirListing(langPath, Translator.LANG_FILENAME_FILTER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|