From 829096915083e54ef2d38f395f8cf4b404bdbb58 Mon Sep 17 00:00:00 2001 From: allo Date: Thu, 30 Jun 2005 20:30:05 +0000 Subject: [PATCH] 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 --- htroot/Language_p.java | 5 +++-- source/yacy.java | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/htroot/Language_p.java b/htroot/Language_p.java index dda5cf7e0..1accd7f0f 100644 --- a/htroot/Language_p.java +++ b/htroot/Language_p.java @@ -95,8 +95,9 @@ public class Language_p { env.setConfig("htLocaleSelection", "default"); return true; }else{ - File sourceDir = new File(env.getRootPath(), "htroot"); - File destDir = new File(env.getRootPath(), "htroot/locale/"+lang.substring(0,lang.length()-4));//cut .lng + String htRootPath = env.getConfig("htRootPath", "htroot"); + 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); if(translator.translateFiles(sourceDir, destDir, translationFile, "html")){ diff --git a/source/yacy.java b/source/yacy.java index 2963bb889..2f48d1015 100644 --- a/source/yacy.java +++ b/source/yacy.java @@ -64,6 +64,9 @@ */ +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.FileInputStream; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; @@ -104,6 +107,7 @@ import de.anomic.server.serverSystem; import de.anomic.server.logging.serverLog; import de.anomic.tools.enumerateFiles; import de.anomic.yacy.yacyCore; +import de.anomic.data.translator; public final class yacy { @@ -319,6 +323,34 @@ public final class yacy { }catch(NullPointerException e){ 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 serverLog.logSystem("STARTUP", "Registering Shutdown Hook");