Automatic regeneration of Locales on Restart with a new (SVN) Version

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@353 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 20 years ago
parent 129929b396
commit 8290969150

@ -95,8 +95,9 @@ public class Language_p {
env.setConfig("htLocaleSelection", "default"); env.setConfig("htLocaleSelection", "default");
return true; return true;
}else{ }else{
File sourceDir = new File(env.getRootPath(), "htroot"); String htRootPath = env.getConfig("htRootPath", "htroot");
File destDir = new File(env.getRootPath(), "htroot/locale/"+lang.substring(0,lang.length()-4));//cut .lng File sourceDir = new File(env.getRootPath(), htRootPath);
File destDir = new File(env.getRootPath(), htRootPath + "/locale/"+lang.substring(0,lang.length()-4));//cut .lng
File translationFile = new File(langPath, lang); File translationFile = new File(langPath, lang);
if(translator.translateFiles(sourceDir, destDir, translationFile, "html")){ if(translator.translateFiles(sourceDir, destDir, translationFile, "html")){

@ -64,6 +64,9 @@
*/ */
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -104,6 +107,7 @@ import de.anomic.server.serverSystem;
import de.anomic.server.logging.serverLog; import de.anomic.server.logging.serverLog;
import de.anomic.tools.enumerateFiles; import de.anomic.tools.enumerateFiles;
import de.anomic.yacy.yacyCore; import de.anomic.yacy.yacyCore;
import de.anomic.data.translator;
public final class yacy { public final class yacy {
@ -319,6 +323,34 @@ public final class yacy {
}catch(NullPointerException e){ }catch(NullPointerException e){
serverLog.logError("STARTUP", "Nullpointer Exception while copying the default Locales"); serverLog.logError("STARTUP", "Nullpointer Exception while copying the default Locales");
} }
//regenerate Locales from Translationlist, if needed
String lang = sb.getConfig("htLocaleSelection", "");
if(! lang.equals("") && ! lang.equals("default") ){ //locale is used
String currentRev = "";
try{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File( sb.getConfig("htRootPath", "htroot"), "locale/"+lang+"/version" ))));
currentRev = br.readLine();
br.close();
}catch(IOException e){
//Error
}
try{ //seperate try, because we want this, even when the File "version2 does not exist.
if(! currentRev.equals(sb.getConfig("svnRevision", "")) ){ //is this another version?!
File sourceDir = new File(sb.getConfig("htRootPath", "htroot"));
File destDir = new File(sourceDir, "locale/"+lang);
if(translator.translateFiles(sourceDir, destDir, new File("DATA/LOCALE/"+lang+".lng"), "html")){ //translate it
//write the new Versionnumber
BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version"))));
bw.write(sb.getConfig("svnRevision", "Error getting Version"));
bw.close();
}
}
}catch(IOException e){
//Error
}
}
// registering shutdown hook // registering shutdown hook
serverLog.logSystem("STARTUP", "Registering Shutdown Hook"); serverLog.logSystem("STARTUP", "Registering Shutdown Hook");

Loading…
Cancel
Save