X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fresources%2FTransBundle.java;h=7b2edb1ca919b4bc9f31e85d968ca8ee771d538f;hb=919bbc354cd2555eb0955be0ef2dcf338047d022;hp=61bc92259de48c9a90164b69df8c4e93799f2253;hpb=ec1f3444e9f238ce1559d5fff32eb5a7ab8aba53;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/resources/TransBundle.java b/src/be/nikiroo/utils/resources/TransBundle.java deleted file mode 100644 index 61bc922..0000000 --- a/src/be/nikiroo/utils/resources/TransBundle.java +++ /dev/null @@ -1,327 +0,0 @@ -package be.nikiroo.utils.resources; - -import java.io.File; -import java.io.IOException; -import java.io.Writer; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.regex.Pattern; - -import be.nikiroo.utils.resources.Bundles; - -/** - * This class manages a translation-dedicated Bundle. - *
- * Two special cases are handled for the used enum: - *
- * Note: this method is NOT thread-safe.
- *
- * @param path
- * the path where the .properties files are
- *
- * @throws IOException
- * in case of IO errors
- */
- @Override
- public void updateFile(String path) throws IOException {
- String prev = locale.getLanguage();
-
- setLanguage(null); // default locale
- super.updateFile(path);
-
- for (String lang : getKnownLanguages()) {
- setLanguage(lang);
- super.updateFile(path);
- }
-
- setLanguage(prev);
- }
-
- @Override
- protected File getUpdateFile(String path) {
- String code = locale.toString();
- File file = null;
- if (!defaultLocale && code.length() > 0) {
- file = new File(path, name.name() + "_" + code + ".properties");
- } else {
- // Default properties file:
- file = new File(path, name.name() + ".properties");
- }
-
- return file;
- }
-
- @Override
- protected void writeHeader(Writer writer) throws IOException {
- String code = locale.toString();
- String name = locale.getDisplayCountry(locale);
-
- if (name.length() == 0) {
- name = locale.getDisplayLanguage(locale);
- }
-
- if (name.length() == 0) {
- name = "default";
- }
-
- if (code.length() > 0) {
- name = name + " (" + code + ")";
- }
-
- name = (name + " " + getBundleDisplayName()).trim();
-
- writer.write("# " + name + " translation file (UTF-8)\n");
- writer.write("# \n");
- writer.write("# Note that any key can be doubled with a _NOUTF suffix\n");
- writer.write("# to use when the NOUTF env variable is set to 1\n");
- writer.write("# \n");
- writer.write("# Also, the comments always refer to the key below them.\n");
- writer.write("# \n");
- }
-
- @Override
- protected void writeValue(Writer writer, E id) throws IOException {
- super.writeValue(writer, id);
-
- String name = id.name() + "_NOUTF";
- if (containsKey(name)) {
- String value = getString(name);
- writeValue(writer, name, value);
- }
- }
-
- /**
- * Return the {@link Locale} representing the given language.
- *
- * @param language
- * the language to initialise, in the form "en-GB" or "fr" for
- * instance
- *
- * @return the corresponding {@link Locale} or the default {@link Locale} if
- * it is not known
- */
- static private Locale getLocaleFor(String language) {
- Locale locale;
-
- if (language == null) {
- locale = Locale.getDefault();
- } else {
- language = language.replaceAll("_", "-");
- String lang = language;
- String country = null;
- if (language.contains("-")) {
- lang = language.split("-")[0];
- country = language.split("-")[1];
- }
-
- if (country != null)
- locale = new Locale(lang, country);
- else
- locale = new Locale(lang);
- }
-
- return locale;
- }
-
- /**
- * Return all the languages known by the program.
- *
- * @param name
- * the enumeration on which we translate
- *
- * @return the known language codes
- */
- static protected List