recursive Translations!

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1341 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 19 years ago
parent 7f1192498a
commit fe2d983c3e

@ -89,9 +89,9 @@ public class Language_p {
// .lng // .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")) {
// if(translator.translateFilesRecursive(sourceDir, destDir, if(translator.translateFilesRecursive(sourceDir, destDir,
// translationFile, "html")){ translationFile, "html,template", "locale")){
env.setConfig("htLocaleSelection", lang.substring(0, lang.length() - 4)); env.setConfig("htLocaleSelection", lang.substring(0, lang.length() - 4));
try { try {
BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version")))); BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version"))));

@ -1176,7 +1176,7 @@ Network==Netzwerk
#Log==Log #Log==Log
Settings==Einstellungen Settings==Einstellungen
#Performance==Performance #Performance==Performance
Language==Sprache >Language==>Sprache
#Skins==Skins #Skins==Skins
Project Home==Pojektseite Project Home==Pojektseite
Project News==Neuigkeiten Project News==Neuigkeiten

@ -55,6 +55,7 @@ import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector;
import de.anomic.server.logging.serverLog; import de.anomic.server.logging.serverLog;
import de.anomic.data.listManager; import de.anomic.data.listManager;
@ -154,18 +155,28 @@ public class translator {
return true; return true;
} }
public static boolean translateFiles(File sourceDir, File destDir, File translationFile, String extension){ public static boolean translateFiles(File sourceDir, File destDir, File translationFile, String extensions){
Hashtable translationLists = loadTranslationsLists(translationFile); Hashtable translationLists = loadTranslationsLists(translationFile);
return translateFiles(sourceDir, destDir, translationLists, extension); return translateFiles(sourceDir, destDir, translationLists, extensions);
} }
public static boolean translateFiles(File sourceDir, File destDir, Hashtable translationLists, String extension){ public static boolean translateFiles(File sourceDir, File destDir, Hashtable translationLists, String extensions){
destDir.mkdirs(); destDir.mkdirs();
File[] sourceFiles = sourceDir.listFiles(); File[] sourceFiles = sourceDir.listFiles();
Vector exts=listManager.string2vector(extensions);
boolean rightExtension;
Iterator it;
for(int i=0;i<sourceFiles.length;i++){ for(int i=0;i<sourceFiles.length;i++){
it=exts.iterator();
if(sourceFiles[i].getName().endsWith(extension)){ rightExtension=false;
if(translationLists.containsKey(sourceFiles[i].getName())){ while(it.hasNext()){
if(sourceFiles[i].getName().endsWith((String) it.next())){
rightExtension=true;
break;
}
}
if(rightExtension){
if(translationLists.containsKey(sourceFiles[i].getName())){ //TODO: relative Path to htroot
if(translateFile(sourceFiles[i], new File(destDir, sourceFiles[i].getName()), (Hashtable)translationLists.get(sourceFiles[i].getName()))){ if(translateFile(sourceFiles[i], new File(destDir, sourceFiles[i].getName()), (Hashtable)translationLists.get(sourceFiles[i].getName()))){
serverLog.logInfo("Translator", "Translated file: "+ sourceFiles[i].getName()); serverLog.logInfo("Translator", "Translated file: "+ sourceFiles[i].getName());
}else{ }else{
@ -180,17 +191,24 @@ public class translator {
return true; return true;
} }
public static boolean translateFilesRecursive(File sourceDir, File destDir, File translationFile, String extension){ public static boolean translateFilesRecursive(File sourceDir, File destDir, File translationFile, String extensions, String notdir){
ArrayList dirList=listManager.getDirsRecursive(sourceDir); ArrayList dirList=listManager.getDirsRecursive(sourceDir);
dirList.add(sourceDir);
Iterator it=dirList.iterator(); Iterator it=dirList.iterator();
String sourceName=sourceDir.getPath(); File file=null;
String destName=destDir.getPath(); File file2=null;
File dir=null;
File dir2=null;
while(it.hasNext()){ while(it.hasNext()){
dir=(File)it.next(); file=(File)it.next();
dir2=new File(dir.getPath().replaceFirst(sourceName.replaceAll("\\\\", "\\\\"), destName)); //cuts the sourcePath and prepends the destPath
translateFiles(dir, dir2, translationFile, extension); file2=new File(destDir, file.getPath().substring(sourceDir.getPath().length(), file.getPath().length()));
//file2=new File(file.getPath().replaceFirst(sourceName.replaceAll("\\\\", "\\\\"), destName));
if(file.isDirectory() && !file.getName().equals(notdir)){
//file2.mkdirs();
translateFiles(file, file2, translationFile, extensions);
//translateFilesRecursive(file, file2, translationFile, extension, notdir);
}/*else{
translateFiles(file, file2, translationFile, extension);
}*/
} }
return true; return true;
} }

@ -439,8 +439,8 @@ public final class yacy {
if(! currentRev.equals(sb.getConfig("svnRevision", "")) ){ //is this another version?! if(! currentRev.equals(sb.getConfig("svnRevision", "")) ){ //is this another version?!
final File sourceDir = new File(sb.getConfig("htRootPath", "htroot")); final File sourceDir = new File(sb.getConfig("htRootPath", "htroot"));
final File destDir = new File(sourceDir, "locale/"+lang); final File destDir = new File(sourceDir, "locale/"+lang);
if(translator.translateFiles(sourceDir, destDir, new File("DATA/LOCALE/"+lang+".lng"), "html")){ //translate it
//if(translator.translateFilesRecursive(sourceDir, destDir, new File("DATA/LOCALE/"+lang+".lng"), "html")){ //translate it if(translator.translateFilesRecursive(sourceDir, destDir, new File("DATA/LOCALE/"+lang+".lng"), "html,template", "locale")){ //translate it
//write the new Versionnumber //write the new Versionnumber
final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version")))); final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version"))));
bw.write(sb.getConfig("svnRevision", "Error getting Version")); bw.write(sb.getConfig("svnRevision", "Error getting Version"));

Loading…
Cancel
Save