/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.tomcat.buildutil.translate;
if (in.startsWith(PADDING)) {
result = in.substring(PADDING.length());
} else {
result = in;
}
return formatValueCommon(result);
}
/* * Values containing "[{n}]" and "'" need to have the "'" escaped as "''". * POEditor attempts to do this automatically but does it for any value * containing "{" or "}" leading to some unnecessary escaping. This method * undoes the unnecessary escaping.
*/ static String fixUnnecessaryEscaping(String key, String value) { if (KEYS_WITH_UNNECESSARY_ESCAPING.contains(key)) { return value.replace("''", "'");
} return value;
}
/* * Common formatting to convert a String for storage as a value in a * property file.
*/ static String formatValueCommon(String in) {
String result = in.replace("\n", "\\n\\\n"); if (result.endsWith("\\n\\\n")) {
result = result.substring(0, result.length() - 2);
}
result = ESCAPE_LEADING_SPACE.matcher(result).replaceAll("\\\\$1");
// 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 root, File f) throws IOException {
String prefix = f.getParentFile().getCanonicalPath();
prefix = prefix.substring(root.getCanonicalPath().length() + 1);
prefix = prefix.replace(File.separatorChar, '.');
prefix = prefix + Constants.END_PACKAGE_MARKER; // POEditor uses javax package names. // Renaming here is less work than renaming terms in POEditor
prefix = prefix.replace(Constants.JAKARTA_EE_SUBSTRING, Constants.JAVA_EE_SUBSTRING); return prefix;
}
staticvoid export(String language, Properties translation, File storageDir) {
File out = new File(storageDir, Constants.L10N_PREFIX + language + Constants.L10N_SUFFIX); try (FileOutputStream fos = new FileOutputStream(out);
Writer w = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {
String[] keys = translation.keySet().toArray(new String[0]);
Arrays.sort(keys); for (Object key : keys) {
w.write(key + "=" + formatValueExport(translation.getProperty((String) key)) + "\n");
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.