Skip to content

Commit

Permalink
fixed great mess with localization paths. the problem was:
Browse files Browse the repository at this point in the history
automatic re-translation after update did not work. hopefully now

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3952 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Jul 4, 2007
1 parent 53266e6 commit a9e73b6
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 67 deletions.
6 changes: 3 additions & 3 deletions htroot/ConfigBasic.java
Expand Up @@ -79,8 +79,8 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
ConfigBasic config = new ConfigBasic();
plasmaSwitchboard sb = (plasmaSwitchboard) env;
serverObjects prop = new serverObjects();
String langPath = new File(env.getRootPath(), env.getConfig("langPath", "DATA/LOCALE")).toString();
String lang = env.getConfig("htLocaleSelection", "default");
String langPath = new File(env.getRootPath(), env.getConfig("locale.work", "DATA/LOCALE/locales")).toString();
String lang = env.getConfig("locale.language", "default");

int authentication = sb.adminAuthenticated(header);
if (authentication < 2) {
Expand Down Expand Up @@ -227,7 +227,7 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
prop.put("defaultName", env.getConfig("peerName", ""));
prop.put("defaultUser", "admin");
prop.put("defaultPort", env.getConfig("port", "8080"));
lang = env.getConfig("htLocaleSelection", "default"); // re-assign lang, may have changed
lang = env.getConfig("locale.language", "default"); // re-assign lang, may have changed
if (lang.equals("default")) {
prop.put("langDeutsch", 0);
prop.put("langEnglish", 1);
Expand Down
6 changes: 3 additions & 3 deletions htroot/ConfigLanguage_p.java
Expand Up @@ -71,7 +71,7 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
//listManager.switchboard = (plasmaSwitchboard) env;
serverObjects prop = new serverObjects();
plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
String langPath = new File(env.getRootPath(), env.getConfig("langPath", "DATA/LOCALE")).toString();
String langPath = new File(env.getRootPath(), env.getConfig("locale.work", "DATA/LOCALE/locales")).toString();

//Fallback
//prop.put("currentlang", ""); //is done by Translationtemplate
Expand Down Expand Up @@ -141,7 +141,7 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
langName = (String) langNames.get(langKey);
prop.put("langlist_"+(i+1)+"_file", langFiles[i]);
prop.put("langlist_"+(i+1)+"_name", ((langName == null) ? langKey : langName));
if(env.getConfig("htLocaleSelection", "default").equals(langKey)) {
if(env.getConfig("locale.language", "default").equals(langKey)) {
prop.put("langlist_"+(i+1)+"_selected", "selected");
prop.put("langlist_0_selected", " "); // reset Default
} else {
Expand All @@ -152,7 +152,7 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
prop.put("langlist", (i+1));

//is done by Translationtemplate
//langName = (String) langNames.get(env.getConfig("htLocaleSelection", "default"));
//langName = (String) langNames.get(env.getConfig("locale.language", "default"));
//prop.put("currentlang", ((langName == null) ? "default" : langName));
return prop;
}
Expand Down
13 changes: 0 additions & 13 deletions htroot/SettingsAck_p.java
Expand Up @@ -79,19 +79,6 @@
public class SettingsAck_p {

private static boolean nothingChanged;

/*
public static HashMap langMap(serverSwitch env) {
String[] ms = env.getConfig("htLocaleLang", "").split(",");
HashMap map = new HashMap();
int p;
for (int i = 0; i < ms.length; i++) {
p = ms[i].indexOf("/");
if (p > 0) map.put(ms[i].substring(0, p), ms[i].substring(p + 1));
}
return map;
}
*/

public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
// return variable that accumulates replacements
Expand Down
2 changes: 1 addition & 1 deletion htroot/Settings_p.java
Expand Up @@ -105,7 +105,7 @@ else if (page.equals("crawler")) {

prop.put("peerName", env.getConfig("peerName", "nameless"));
prop.put("staticIP", env.getConfig("staticIP", ""));
String peerLang = env.getConfig("htLocaleSelection", "default");
String peerLang = env.getConfig("locale.language", "default");
if (peerLang.equals("default")) peerLang = "en";
prop.put("peerLang", peerLang);

Expand Down
10 changes: 5 additions & 5 deletions source/de/anomic/data/translator.java
Expand Up @@ -10,7 +10,7 @@
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
// $LastChangedBy: $
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -238,7 +238,7 @@ public static boolean translateFilesRecursive(File sourceDir, File destDir, File
}

public static HashMap langMap(serverSwitch env) {
String[] ms = env.getConfig("htLocaleLang", "").split(",");
String[] ms = env.getConfig("locale.lang", "").split(",");
HashMap map = new HashMap();
int p;
for (int i = 0; i < ms.length; i++) {
Expand All @@ -251,12 +251,12 @@ public static HashMap langMap(serverSwitch env) {

public static boolean changeLang(serverSwitch env, String langPath, String lang) {
if ((lang.equals("default")) || (lang.equals("default.lng"))) {
env.setConfig("htLocaleSelection", "default");
env.setConfig("locale.language", "default");
return true;
}
String htRootPath = env.getConfig("htRootPath", "htroot");
File sourceDir = new File(env.getRootPath(), htRootPath);
File destDir = new File(env.getConfig("htLocalePath","DATA/HTDOCS/locale"), lang.substring(0, lang.length() - 4));// cut
File destDir = new File(env.getConfig("locale.translated_html","DATA/LOCALE/htroot"), lang.substring(0, lang.length() - 4));// cut
// .lng
//File destDir = new File(env.getRootPath(), htRootPath + "/locale/" + lang.substring(0, lang.length() - 4));// cut
// .lng
Expand All @@ -265,7 +265,7 @@ public static boolean changeLang(serverSwitch env, String langPath, String lang)
//if (translator.translateFiles(sourceDir, destDir, translationFile, "html")) {
if(translator.translateFilesRecursive(sourceDir, destDir,
translationFile, "html,template,inc", "locale")){
env.setConfig("htLocaleSelection", lang.substring(0, lang.length() - 4));
env.setConfig("locale.language", lang.substring(0, lang.length() - 4));
try {
BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version"))));
bw.write(env.getConfig("svnRevision", "Error getting Version"));
Expand Down
15 changes: 7 additions & 8 deletions source/de/anomic/http/httpdFileHandler.java
Expand Up @@ -194,8 +194,7 @@ public httpdFileHandler(serverSwitch switchboard) {

// create htLocaleDefault, htLocalePath
if (htDefaultPath == null) htDefaultPath = new File(switchboard.getRootPath(), switchboard.getConfig("htDefaultPath","htroot"));
if (htLocalePath == null) htLocalePath = new File(switchboard.getConfig("htLocalePath","DATA/HTDOCS/locale"));
//htLocaleSelection = switchboard.getConfig("htLocaleSelection","default");
if (htLocalePath == null) htLocalePath = new File(switchboard.getConfig("locale.translated_html","DATA/LOCALE/htroot"));
}

}
Expand All @@ -206,18 +205,18 @@ public static final void initDefaultPath() {
if (defaultFiles.length == 0) defaultFiles = new String[] {"index.html"};
}

/** Returns a path to the localized or default file according to the htLocaleSelection (from he switchboard)
/** Returns a path to the localized or default file according to the locale.language (from he switchboard)
* @param path relative from htroot */
public static File getLocalizedFile(String path){
return getLocalizedFile(path, switchboard.getConfig("htLocaleSelection","default"));
return getLocalizedFile(path, switchboard.getConfig("locale.language","default"));
}

/** Returns a path to the localized or default file according to the parameter localeSelection
* @param path relative from htroot
* @param localeSelection language of localized file; htLocaleSelection from switchboard is used if localeSelection.equals("") */
* @param localeSelection language of localized file; locale.language from switchboard is used if localeSelection.equals("") */
public static File getLocalizedFile(String path, String localeSelection){
if (htDefaultPath == null) htDefaultPath = new File(switchboard.getRootPath(), switchboard.getConfig("htDefaultPath","htroot"));
if (htLocalePath == null) htLocalePath = new File(switchboard.getRootPath(), switchboard.getConfig("htLocalePath","htroot/locale"));
if (htLocalePath == null) htLocalePath = new File(switchboard.getRootPath(), switchboard.getConfig("locale.translated_html","DATA/LOCALE/htroot"));

if (!(localeSelection.equals("default"))) {
File localePath = new File(htLocalePath, localeSelection + "/" + path);
Expand Down Expand Up @@ -423,8 +422,8 @@ public void doResponse(Properties conProp, httpHeader requestHeader, OutputStrea
// locate the file
if (!(path.startsWith("/"))) path = "/" + path; // attach leading slash

// a different language can be desired (by i.e. ConfigBasic.html) than the one stored in the htLocaleSelection
String localeSelection = switchboard.getConfig("htLocaleSelection","default");
// a different language can be desired (by i.e. ConfigBasic.html) than the one stored in the locale.language
String localeSelection = switchboard.getConfig("locale.language","default");
if (args != null && (args.containsKey("language")))
{
// TODO 9.11.06 Bost: a class with information about available languages is needed.
Expand Down
4 changes: 2 additions & 2 deletions source/migration.java
Expand Up @@ -226,8 +226,8 @@ public static void migrateSwitchConfigSettings(plasmaSwitchboard sb) {
sb.setConfig("parseableMimeTypes.ICAP", value);
}
//Locales in DATA, because DATA must be writable, htroot not.
if(sb.getConfig("htLocalePath", "htroot/locale").equals("htroot/locale")){
sb.setConfig("htLocalePath", "DATA/HTDOCS/locale");
if(sb.getConfig("locale.translated_html", "DATA/LOCALE/htroot").equals("htroot/locale")){
sb.setConfig("locale.translated_html", "DATA/LOCALE/htroot");
}

// migration for port forwarding settings
Expand Down
53 changes: 25 additions & 28 deletions source/yacy.java
Expand Up @@ -383,50 +383,47 @@ private static void startup(String homePath, long startupMemFree, long startupMe
serverSystem.openBrowser((server.withSSL()?"https":"http") + "://localhost:" + serverCore.getPortNr(port) + "/" + browserPopUpPage, browserPopUpApplication);
}

//Copy the shipped locales into DATA
final File localesPath = new File(homePath, sb.getConfig("localesPath", "DATA/LOCALE"));
final File defaultLocalesPath = new File(homePath, "locales");


// Copy the shipped locales into DATA, existing files are overwritten
final File locale_work = new File(homePath, sb.getConfig("locale.work", "DATA/LOCALE/locales"));
final File locale_source = new File(homePath, sb.getConfig("locale.source", "locales"));
try{
final File[] defaultLocales = defaultLocalesPath.listFiles();
localesPath.mkdirs();
for(int i=0;i < defaultLocales.length; i++){
if(defaultLocales[i].getName().endsWith(".lng"))
serverFileUtils.copy(defaultLocales[i], new File(localesPath, defaultLocales[i].getName()));
final File[] locale_source_files = locale_source.listFiles();
locale_work.mkdirs();
File target;
for (int i=0; i < locale_source_files.length; i++){
target = new File(locale_work, locale_source_files[i].getName());
if (locale_source_files[i].getName().endsWith(".lng")) {
if (target.exists()) target.delete();
serverFileUtils.copy(locale_source_files[i], target);
}
}
serverLog.logInfo("STARTUP", "Copied the default locales to DATA/LOCALE");
serverLog.logInfo("STARTUP", "Copied the default locales to " + locale_work.toString());
}catch(NullPointerException e){
serverLog.logSevere("STARTUP", "Nullpointer Exception while copying the default Locales");
}

//regenerate Locales from Translationlist, if needed
final String lang = sb.getConfig("htLocaleSelection", "");
if(! lang.equals("") && ! lang.equals("default") ){ //locale is used
final String lang = sb.getConfig("locale.language", "");
if (!lang.equals("") && !lang.equals("default")) { //locale is used
String currentRev = "";
try{
final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File( sb.getConfig("htLocalePath", "DATA/HTDOCS/locale"), lang+"/version" ))));
final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(sb.getConfig("locale.translated_html", "DATA/LOCALE/htroot"), lang+"/version" ))));
currentRev = br.readLine();
br.close();
}catch(IOException e){
//Error
}

try{ //seperate try, because we want this, even if the file "version" does not exist.
if(! currentRev.equals(sb.getConfig("svnRevision", "")) ){ //is this another version?!
final File sourceDir = new File(sb.getConfig("htRootPath", "htroot"));
final File destDir = new File(sb.getConfig("htLocalePath", "DATA/HTDOCS/locale"), lang);

if(translator.translateFilesRecursive(sourceDir, destDir, new File("DATA/LOCALE/"+lang+".lng"), "html,template,inc", "locale")){ //translate it
//write the new Versionnumber
final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version"))));
bw.write(sb.getConfig("svnRevision", "Error getting Version"));
bw.close();
}
if (!currentRev.equals(sb.getConfig("svnRevision", ""))) try { //is this another version?!
final File sourceDir = new File(sb.getConfig("htRootPath", "htroot"));
final File destDir = new File(sb.getConfig("locale.translated_html", "DATA/LOCALE/htroot"), lang);
if (translator.translateFilesRecursive(sourceDir, destDir, new File(locale_work, lang + ".lng"), "html,template,inc", "locale")){ //translate it
//write the new Versionnumber
final 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
}
} catch (IOException e) {}
}

// registering shutdown hook
Expand Down
13 changes: 9 additions & 4 deletions yacy.init
Expand Up @@ -116,6 +116,10 @@ httpdMinIdleSessions = 5
htRootPath = htroot
htTemplatePath = htroot/env/templates

# the htroot path
# root path for the httpd file server
htDefaultPath=htroot

# individual htroot folder
# every user may publicise her/his own web pages
# these pages shall be placed in the path defined here
Expand All @@ -133,10 +137,11 @@ defaultFiles = ConfigBasic.html,index.html,default.html,search.html,console.html
# The htLocaleLang defines a list of language options as <dir>/<named-language>
# the <dir> must exist as sub-path to htLocalePath
# the htLocaleSelection selects from the given locales, value=one-of-<dir>
htDefaultPath=htroot
htLocalePath=DATA/HTROOT/locale
htLocaleLang=default/English,de/Deutsch,fr/Fran&ccedil;ais,nl/Nederlands,it/Italiano,es/Espa&ntilde;ol,pt/Portug&ecirc;s,fi/Suomi,se/Svenska,dk/Dansk,gr/E&lambda;&lambda;&eta;v&iota;&kappa;&alpha;,sk/Slovensky
htLocaleSelection=default
locale.source=locales
locale.work=DATA/LOCALE/locales
locale.translated_html=DATA/LOCALE/htroot
locale.lang=default/English,de/Deutsch,fr/Fran&ccedil;ais,nl/Nederlands,it/Italiano,es/Espa&ntilde;ol,pt/Portug&ecirc;s,fi/Suomi,se/Svenska,dk/Dansk,gr/E&lambda;&lambda;&eta;v&iota;&kappa;&alpha;,sk/Slovensky
locale.language=default

# virtual host for httpdFileServlet access
# for example http://<fileHost>/ shall access the file servlet and
Expand Down

0 comments on commit a9e73b6

Please sign in to comment.