: - translate all source files with a locale - list all non translated files with a localepull/12/head
parent
2f0f0180e2
commit
9752bd5f88
@ -0,0 +1,111 @@
|
||||
// ListNonTranslatedFiles.java
|
||||
// -------------------------------------
|
||||
// part of YACY
|
||||
// (C) by Michael Peter Christen; mc@yacy.net
|
||||
// first published on http://www.anomic.de
|
||||
// Frankfurt, Germany, 2004
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $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
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package net.yacy.utils.translation;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.yacy.cora.util.ConcurrentLog;
|
||||
import net.yacy.data.ListManager;
|
||||
import net.yacy.data.Translator;
|
||||
import net.yacy.kelondro.util.FileUtils;
|
||||
|
||||
/**
|
||||
* Util to help identifying non translated files.
|
||||
*
|
||||
* @author luc
|
||||
*
|
||||
*/
|
||||
public class ListNonTranslatedFiles extends TranslatorUtil {
|
||||
|
||||
/**
|
||||
* Print on standard output result of search
|
||||
* @param nonTranslatedFiles list of non translated files
|
||||
*/
|
||||
private static void printResults(List<File> nonTranslatedFiles) {
|
||||
System.out.println(nonTranslatedFiles.size() + " files are not translated.");
|
||||
for(File file : nonTranslatedFiles) {
|
||||
System.out.println(file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List all files from srcDir directory which are not translated using
|
||||
* specified locale file with specified extensions. If no argument is set,
|
||||
* default values are used.
|
||||
*
|
||||
* @param args
|
||||
* runtime arguments<br/>
|
||||
* <ul>
|
||||
* <li>args[0] : source dir path</li>
|
||||
* <li>args[1] : translation file path</li>
|
||||
* <li>args[2] : extensions (separated by commas)</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
File sourceDir = getSourceDir(args);
|
||||
Path sourcePath = sourceDir.toPath();
|
||||
|
||||
File translationFile = getTranslationFile(args);
|
||||
|
||||
List<String> extensions = ListManager
|
||||
.string2vector(getExtensions(args));
|
||||
|
||||
FilenameFilter fileFilter = new SourceFileFilter(extensions);
|
||||
|
||||
String excludedDir = "locale";
|
||||
|
||||
ConcurrentLog.info("ListNonTranslatedFiles", "Listing non translated "
|
||||
+ extensions + " files from " + sourceDir + " using "
|
||||
+ translationFile);
|
||||
|
||||
try {
|
||||
Set<String> translatedRelativePaths = Translator.loadTranslationsLists(translationFile).keySet();
|
||||
|
||||
List<File> srcFiles = FileUtils.getFilesRecursive(sourceDir, excludedDir, fileFilter);
|
||||
|
||||
List<File> nonTranslatedFiles = new ArrayList<>();
|
||||
for(File srcFile : srcFiles) {
|
||||
Path relativeSrcFile = sourcePath.relativize(srcFile.toPath());
|
||||
if(!translatedRelativePaths.contains(relativeSrcFile.toString())) {
|
||||
nonTranslatedFiles.add(srcFile);
|
||||
}
|
||||
}
|
||||
|
||||
printResults(nonTranslatedFiles);
|
||||
|
||||
|
||||
} finally {
|
||||
ConcurrentLog.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
// TranslateAll.java
|
||||
// -------------------------------------
|
||||
// part of YACY
|
||||
// (C) by Michael Peter Christen; mc@yacy.net
|
||||
// first published on http://www.anomic.de
|
||||
// Frankfurt, Germany, 2004
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $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
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package net.yacy.utils.translation;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.yacy.cora.util.ConcurrentLog;
|
||||
import net.yacy.data.Translator;
|
||||
|
||||
/**
|
||||
* Util to translate all files without launching full YaCy application.
|
||||
*
|
||||
* @author luc
|
||||
*
|
||||
*/
|
||||
public class TranslateAll extends TranslatorUtil {
|
||||
|
||||
/**
|
||||
* Translate all files from srcDir directory into dstDir directory using
|
||||
* specified locale file with specified extensions. If no argument is set,
|
||||
* default values are used.
|
||||
*
|
||||
* @param args
|
||||
* runtime arguments<br/>
|
||||
* <ul>
|
||||
* <li>args[0] : source dir path</li>
|
||||
* <li>args[1] : destination dir path</li>
|
||||
* <li>args[2] : translation file path</li>
|
||||
* <li>args[3] : extensions (separated by commas)</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
File sourceDir = getSourceDir(args);
|
||||
|
||||
File destDir = getDestDir(args);
|
||||
|
||||
File translationFile = getTranslationFile(args);
|
||||
|
||||
String extensions = getExtensions(args);
|
||||
|
||||
ConcurrentLog.info("TranslateAll", "Translating " + extensions
|
||||
+ " files from " + sourceDir + " to " + destDir + " using "
|
||||
+ translationFile);
|
||||
|
||||
try {
|
||||
Translator.translateFilesRecursive(sourceDir, destDir,
|
||||
translationFile, extensions, "locale");
|
||||
} finally {
|
||||
ConcurrentLog.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* main parameters
|
||||
* @return translation source dir from parameters or default
|
||||
* @throws IllegalArgumentException
|
||||
* when no parameters is set and default is not found
|
||||
*/
|
||||
protected static File getDestDir(String[] args) {
|
||||
File destDir;
|
||||
if (args.length > 1) {
|
||||
destDir = new File(args[1]);
|
||||
} else {
|
||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||
if (tmpDir == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"No destination dir specified, and default not found");
|
||||
}
|
||||
destDir = new File(tmpDir + File.separator
|
||||
+ TranslateAll.class.getCanonicalName());
|
||||
}
|
||||
return destDir;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
// TranslateAll.java
|
||||
// -------------------------------------
|
||||
// part of YACY
|
||||
// (C) by Michael Peter Christen; mc@yacy.net
|
||||
// first published on http://www.anomic.de
|
||||
// Frankfurt, Germany, 2004
|
||||
//
|
||||
// $LastChangedDate$
|
||||
// $LastChangedRevision$
|
||||
// $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
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package net.yacy.utils.translation;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.yacy.yacy;
|
||||
import net.yacy.data.Translator;
|
||||
|
||||
/**
|
||||
* Base class for launching a {@link Translator} method without full YaCy
|
||||
* application started.
|
||||
*
|
||||
* @author luc
|
||||
*
|
||||
*/
|
||||
public abstract class TranslatorUtil {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* main parameters
|
||||
* @return translation source dir from parameters or default
|
||||
* (workingDir/htroot)
|
||||
* @throws IllegalArgumentException
|
||||
* when no parameters is set and default is not found
|
||||
*/
|
||||
protected static File getSourceDir(String[] args) {
|
||||
File sourceDir;
|
||||
if (args.length > 0) {
|
||||
sourceDir = new File(args[0]);
|
||||
} else {
|
||||
String workingDir = System.getProperty("user.dir");
|
||||
if (workingDir == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"No translation file specified, and default not found");
|
||||
}
|
||||
sourceDir = new File(workingDir, "htroot");
|
||||
if (!sourceDir.exists() && !sourceDir.isDirectory()) {
|
||||
throw new IllegalArgumentException(
|
||||
"No translation file specified, and default not found : "
|
||||
+ sourceDir.getPath());
|
||||
}
|
||||
}
|
||||
return sourceDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* main parameters
|
||||
* @return translation file from parameters or default (base on current
|
||||
* Locale)
|
||||
* @throws IllegalArgumentException
|
||||
* when no parameters is set and default is not found
|
||||
*/
|
||||
protected static File getTranslationFile(String[] args) {
|
||||
File translationFile;
|
||||
if (args.length > 2) {
|
||||
translationFile = new File(args[2]);
|
||||
} else {
|
||||
String workingDir = System.getProperty("user.dir");
|
||||
if (workingDir == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"No translation file specified, and default not found");
|
||||
}
|
||||
translationFile = new File(workingDir, "locales" + File.separator
|
||||
+ Locale.getDefault().getLanguage() + ".lng");
|
||||
if (!translationFile.exists()) {
|
||||
throw new IllegalArgumentException(
|
||||
"No translation file specified, and default not found : "
|
||||
+ translationFile.getPath());
|
||||
}
|
||||
}
|
||||
return translationFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* main parameters
|
||||
* @return extensions list from parameters or default (same as used in
|
||||
* {@link yacy})
|
||||
*/
|
||||
protected static String getExtensions(String[] args) {
|
||||
String extensions;
|
||||
if (args.length > 3) {
|
||||
extensions = args[3];
|
||||
} else {
|
||||
extensions = "html,template,inc";
|
||||
}
|
||||
return extensions;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue