You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/08/14 10:18:28 UTC
[tomcat] 01/03: Refactor i18n export tool to make re-use easier.
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 21aa776a63912e1d32d0c6e4da5ed6a7b1ac0096
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Aug 14 10:30:49 2019 +0100
Refactor i18n export tool to make re-use easier.
---
.../apache/tomcat/buildutil/translate/Export.java | 69 +---------------------
.../apache/tomcat/buildutil/translate/Utils.java | 54 +++++++++++++++++
2 files changed, 56 insertions(+), 67 deletions(-)
diff --git a/java/org/apache/tomcat/buildutil/translate/Export.java b/java/org/apache/tomcat/buildutil/translate/Export.java
index a4d73b8..2b963d1 100644
--- a/java/org/apache/tomcat/buildutil/translate/Export.java
+++ b/java/org/apache/tomcat/buildutil/translate/Export.java
@@ -37,79 +37,14 @@ public class Export {
public static void main(String... args) {
for (String dir : Constants.SEARCH_DIRS) {
- processRoot(dir);
+ File root = new File(dir);
+ Utils.processDirectory(root, translations);
}
outputTranslations();
}
- private static void processRoot(String dir) {
- // Run from within IDE so working dir is root of project.
- File root = new File(dir);
-
- // Assumes no l18n files directly in roots
- for (File f : root.listFiles()) {
- if (f.isDirectory()) {
- processDirectory(f);
- }
- }
- }
-
-
- private static void processDirectory(File dir) {
- for (File f : dir.listFiles()) {
- if (f.isDirectory()) {
- processDirectory(f);
- } else if (f.isFile()) {
- processFile(f);
- }
- }
- }
-
-
- private static void processFile(File f) {
- String name = f.getName();
-
- // non-l10n files
- if (!name.startsWith(Constants.L10N_PREFIX)) {
- return;
- }
-
- // Determine language
- String language = Utils.getLanguage(name);
-
- String keyPrefix = getKeyPrefix(f);
- Properties props = Utils.load(f);
-
- // Create a Map for the language if one does not exist.
- Properties translation = translations.get(language);
- if (translation == null) {
- translation = new Properties();
- translations.put(language, translation);
- }
-
- // Add the properties from this file to the combined file, prefixing the
- // key with the package name to ensure uniqueness.
- for (Object obj : props.keySet()) {
- String key = (String) obj;
- String value = props.getProperty(key);
-
- translation.put(keyPrefix + key, value);
- }
- }
-
-
- private static String getKeyPrefix(File f) {
- File wd = new File(".");
- String prefix = f.getParentFile().getAbsolutePath();
- prefix = prefix.substring(wd.getAbsolutePath().length() - 1);
- prefix = prefix.replace(File.separatorChar, '.');
- prefix = prefix + Constants.END_PACKAGE_MARKER;
- return prefix;
- }
-
-
private static void outputTranslations() {
File storageDir = new File(Constants.STORAGE_DIR);
diff --git a/java/org/apache/tomcat/buildutil/translate/Utils.java b/java/org/apache/tomcat/buildutil/translate/Utils.java
index 9a5f5d7..d441c35 100644
--- a/java/org/apache/tomcat/buildutil/translate/Utils.java
+++ b/java/org/apache/tomcat/buildutil/translate/Utils.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
+import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern;
@@ -70,4 +71,57 @@ public class Utils {
}
return result;
}
+
+
+ static void processDirectory(File dir, Map<String,Properties> translations) {
+ for (File f : dir.listFiles()) {
+ if (f.isDirectory()) {
+ processDirectory(f, translations);
+ } else if (f.isFile()) {
+ processFile(f, translations);
+ }
+ }
+ }
+
+
+ static void processFile(File f, Map<String,Properties> translations) {
+ String name = f.getName();
+
+ // non-l10n files
+ if (!name.startsWith(Constants.L10N_PREFIX)) {
+ return;
+ }
+
+ // Determine language
+ String language = Utils.getLanguage(name);
+
+ String keyPrefix = getKeyPrefix(f);
+ Properties props = Utils.load(f);
+
+ // Create a Map for the language if one does not exist.
+ Properties translation = translations.get(language);
+ if (translation == null) {
+ translation = new Properties();
+ translations.put(language, translation);
+ }
+
+ // Add the properties from this file to the combined file, prefixing the
+ // key with the package name to ensure uniqueness.
+ for (Object obj : props.keySet()) {
+ String key = (String) obj;
+ String value = props.getProperty(key);
+
+ translation.put(keyPrefix + key, value);
+ }
+ }
+
+
+ static String getKeyPrefix(File f) {
+ File wd = new File(".");
+ String prefix = f.getParentFile().getAbsolutePath();
+ prefix = prefix.substring(wd.getAbsolutePath().length() - 1);
+ prefix = prefix.replace(File.separatorChar, '.');
+ prefix = prefix + Constants.END_PACKAGE_MARKER;
+ return prefix;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org