better Translationsystem.

You only need to escape Chars, which have special meanings in regexps.
some you have to escape: ()[]{}


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@348 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 20 years ago
parent 8a4f297324
commit bef3aaec38

@ -10,8 +10,10 @@
<h2>Language selection</h2>
<p>
You can change the language of YaCy with translation files.
<br>
<b>Current language: #[currentlang]#</b>
<b>Current language:</b> <!-- lang -->default(english)<br>
<b>Languagefile Author:</b> <!-- author --><br>
<p>
<form action="Language_p.html">

@ -114,7 +114,7 @@ public class Language_p {
String langPath = new File(env.getRootPath(), env.getConfig("langPath", "DATA/LOCALE")).toString();
//Fallback
prop.put("currentlang", "");
//prop.put("currentlang", ""); //is done by Translationtemplate
prop.put("status", 0);//nothing
String[] langFiles = listManager.getDirListing(langPath);
@ -184,8 +184,9 @@ public class Language_p {
}
prop.put("langlist", (i+1));
langName = (String) langNames.get(env.getConfig("htLocaleSelection", "default"));
prop.put("currentlang", ((langName == null) ? "default" : langName));
//is done by Translationtemplate
//langName = (String) langNames.get(env.getConfig("htLocaleSelection", "default"));
//prop.put("currentlang", ((langName == null) ? "default" : langName));
return prop;
}

@ -1,40 +1,44 @@
#English=German
<!-- lang -->default\(english\)=Deutsch
<!-- author -->=Übersetzer eintragen
#-----------------------------------------------------------
#index.html
P2P\ WEB\ SEARCH=P2P Web-Suche
P2P WEB SEARCH=P2P Web-Suche
#only the Button
"Search"="Suchen"
Enter\ search\ word\ list,\ separated\ by\ space\:=Geben Sie hier die Suchworte getrennt durch Leerzeichen ein:
Max.\ number\ of\ results\:=Max. Anzahl Ergebnisse:
order\ by\:=sortiert nach:
Enter search word list, separated by space:=Geben Sie hier die Suchworte getrennt durch Leerzeichen ein:
Max. number of results:=Max. Anzahl Ergebnisse:
order by:=sortiert nach:
# ">" to avoid replacing value=
>Quality-Date=>Qualit&auml;t-Datum
>Date-Quality=>Datum-Qualit&auml;t
Resource\:=Quelle:
Max.\ search\ time=Max. Suchzeit
seconds=Sekunden
Resource:=Quelle:
Max. search time \(seconds\)=Max. Suchzeit (Sekunden)
"URL mask":=URL-Maske
#-------------------------------------------------------
#IndexCreate_p.html
Index\ Creation=Index Erzeugung
You\ can\ define\ url's\ as\ start\ points\ for\ Web\ page\ crawling\ and\ start\ that\ crawling\ here\.=Du kannst hier URLs angeben, die gecrawlt werden sollen und dann das Crawling starten.
Index Creation=Index Erzeugung
You can define url's as start points for Web page crawling and start that crawling here.=Du kannst hier URLs angeben, die gecrawlt werden sollen und dann das Crawling starten.
#-------------------------------------------------------
#Status.html
#Das passt hier, aber wenn wo anders Protection steht eher nicht..,
Protection=Sicherheit
Welcome\ to\ YaCy\!=Willkommen bei YaCy!
System\ version=Systemversion
Proxy\ host=Proxy Host
Remote\ proxy=Zweiter Proxy
This\ peer's\ address=Adresse dieses Peers
This\ peer's\ name=Name dieses Peers
This\ peer's\ statistics= Statistik dieses Peers
This\ peer's\ status=Status dieses Peers
Other\ peers=Andere Peers
Seed\ server=Seed Server
Auto-popup\ on\ start-up=Popup bei YaCy-Start
Online-mode=Onlinemodus
Welcome to YaCy!=Willkommen bei YaCy!
System version=Systemversion
Proxy host=Proxy Host
Remote proxy=Zweiter Proxy
This peer's address=Adresse dieses Peers
This peer's name=Name dieses Peers
This peer's statistics= Statistik dieses Peers
This peer's status=Status dieses Peers
Other peers=Andere Peers
Seed server=Seed Server
Auto-popup on start-up=Popup bei YaCy-Start
Online-mode=Onlinemodus

@ -52,43 +52,66 @@ import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Vector;
import de.anomic.server.logging.serverLog;
import de.anomic.data.listManager;
/**
* Wordlist based translator
*
* Uses a Property 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 static String translate(String source, Properties translationList){
Enumeration keys = translationList.propertyNames();
public static String translate(String source, Hashtable translationList){
Enumeration keys = translationList.keys();
String result = source;
String key = "";
while(keys.hasMoreElements()){
key = (String)keys.nextElement();
result = result.replaceAll(key, translationList.getProperty(key));
result = result.replaceAll(key, (String)translationList.get(key));
//System.out.println("Replaced \""+key+"\" by \""+translationList.getProperty(key)+"\""); //DEBUG
}
return result;
}
public static boolean translateFile(File sourceFile, File destFile, File translationFile){
Properties translationList = new Properties();
public static Hashtable loadTranslationsList(File translationFile){
Hashtable translationList = new Hashtable();
FileInputStream fileIn = null;
try{
translationList.load(fileIn = new FileInputStream(translationFile));
return translateFile(sourceFile, destFile, translationList);
}catch(IOException e){
return false;
} finally {
if (fileIn!=null)try{fileIn.close();}catch(Exception e){}
}
Vector list = listManager.getListArray(translationFile);
Iterator it = list.iterator();
String line = "";
String value = "";
String[] splitted;
while(it.hasNext()){
line = (String)it.next();
if(! line.startsWith("#")){
splitted = line.split("=");
if(splitted.length == 2){
translationList.put(splitted[0], splitted[1]);
}else if(splitted.length > 2){
value = "";
for(int i = splitted.length-1;i>=1;i--){
value += splitted[i];
}
translationList.put(splitted[0], value);
}else{ //Invalid line
}
}
}
return translationList;
}
public static boolean translateFile(File sourceFile, File destFile, File translationFile){
Hashtable translationList = loadTranslationsList(translationFile);
return translateFile(sourceFile, destFile, translationList);
}
public static boolean translateFile(File sourceFile, File destFile, Properties translationList){
public static boolean translateFile(File sourceFile, File destFile, Hashtable translationList){
String content = "";
String line = "";
@ -121,19 +144,11 @@ public class translator {
}
public static boolean translateFiles(File sourceDir, File destDir, File translationFile, String extension){
Properties translationList = new Properties();
FileInputStream fileIn = null;
try{
translationList.load(fileIn = new FileInputStream(translationFile));
Hashtable translationList = loadTranslationsList(translationFile);
return translateFiles(sourceDir, destDir, translationList, extension);
}catch(IOException e){
return false;
} finally {
if (fileIn!=null)try{fileIn.close();}catch(Exception e){}
}
}
public static boolean translateFiles(File sourceDir, File destDir, Properties translationList, String extension){
public static boolean translateFiles(File sourceDir, File destDir, Hashtable translationList, String extension){
destDir.mkdirs();
File[] sourceFiles = sourceDir.listFiles();
for(int i=0;i<sourceFiles.length;i++){

Loading…
Cancel
Save