From 47d06cf312c7f7a86b5861bb9a762c8856c4f58e Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Fri, 1 Apr 2016 21:17:56 +0200 Subject: [PATCH] Fix _NOUTF flag handling in "--i18n" --- src/be/nikiroo/jvcard/launcher/Main.java | 2 +- src/be/nikiroo/jvcard/resources/Bundles.java | 24 ++++++++++++++++--- .../jvcard/resources/bundles/ColorBundle.java | 20 ++++++++-------- .../jvcard/resources/bundles/TransBundle.java | 12 +++++++++- .../jvcard/resources/enums/StringId.java | 2 +- .../jvcard/resources/resources.properties | 3 ++- .../jvcard/resources/resources_en.properties | 3 ++- .../jvcard/resources/resources_fr.properties | 3 ++- 8 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/be/nikiroo/jvcard/launcher/Main.java b/src/be/nikiroo/jvcard/launcher/Main.java index 65fbf9c..f193be1 100644 --- a/src/be/nikiroo/jvcard/launcher/Main.java +++ b/src/be/nikiroo/jvcard/launcher/Main.java @@ -429,7 +429,7 @@ public class Main { + trans(StringId.CLI_HELP_LANG)); System.out.println("\t--tui : " + trans(StringId.CLI_HELP_TUI)); System.out.println("\t--gui : " + trans(StringId.CLI_HELP_GUI)); - System.out.println("\t--noutf : " + trans(StringId.CLI_HELP_NOUTF)); + System.out.println("\t--noutf : " + trans(StringId.CLI_HELP_NOUTF_OPTION)); System.out.println("\t--config : " + trans(StringId.CLI_HELP_CONFIG)); System.out.println(); diff --git a/src/be/nikiroo/jvcard/resources/Bundles.java b/src/be/nikiroo/jvcard/resources/Bundles.java index b83b1b0..ef6e0d7 100644 --- a/src/be/nikiroo/jvcard/resources/Bundles.java +++ b/src/be/nikiroo/jvcard/resources/Bundles.java @@ -313,11 +313,29 @@ public class Bundles { * in case of IO error */ protected void writeValue(Writer writer, E id) throws IOException { - writer.write(id.name()); + writeValue(writer, id.name(), getString(id)); + } + + /** + * Write the given data to the config file, i.e., + * "MY_ID = my_curent_value" followed by a new line + * + * @param writer + * the {@link Writer} to write into + * @param id + * the id to write + * @param value + * the id's value + * + * @throws IOException + * in case of IO error + */ + protected void writeValue(Writer writer, String id, String value) + throws IOException { + writer.write(id); writer.write(" = "); - String[] lines = getString(id).replaceAll("\\\t", "\\\\\\t").split( - "\n"); + String[] lines = value.replaceAll("\\\t", "\\\\\\t").split("\n"); for (int i = 0; i < lines.length; i++) { writer.write(lines[i]); if (i < lines.length - 1) { diff --git a/src/be/nikiroo/jvcard/resources/bundles/ColorBundle.java b/src/be/nikiroo/jvcard/resources/bundles/ColorBundle.java index 899ca75..25accfe 100644 --- a/src/be/nikiroo/jvcard/resources/bundles/ColorBundle.java +++ b/src/be/nikiroo/jvcard/resources/bundles/ColorBundle.java @@ -26,18 +26,18 @@ public class ColorBundle extends Bundle { @Override protected void writeValue(Writer writer, ColorOption id) throws IOException { - writer.write(id.name() + "_FG"); - writer.write(" = "); - if (map.containsKey(id.name() + "_FG")) - writer.write(map.getString(id.name() + "_FG").trim()); + String name = id.name() + "_FG"; + String value = ""; + if (map.containsKey(name)) + value = map.getString(name).trim(); - writer.write("\n"); + writeValue(writer, name, value); - writer.write(id.name() + "_BG"); - writer.write(" = "); - if (map.containsKey(id.name() + "_BG")) - writer.write(map.getString(id.name() + "_BG").trim()); + name = id.name() + "_BG"; + value = ""; + if (map.containsKey(name)) + value = map.getString(name).trim(); - writer.write("\n"); + writeValue(writer, name, value); } } diff --git a/src/be/nikiroo/jvcard/resources/bundles/TransBundle.java b/src/be/nikiroo/jvcard/resources/bundles/TransBundle.java index c79b0b6..6ff63bf 100644 --- a/src/be/nikiroo/jvcard/resources/bundles/TransBundle.java +++ b/src/be/nikiroo/jvcard/resources/bundles/TransBundle.java @@ -148,6 +148,17 @@ public class TransBundle extends Bundle { StringId.writeHeader(writer, name); } + @Override + protected void writeValue(Writer writer, StringId id) throws IOException { + super.writeValue(writer, id); + + String name = id.name() + "_NOUTF"; + if (map.containsKey(name)) { + String value = map.getString(name).trim(); + writeValue(writer, name, value); + } + } + /** * Return the {@link Locale} representing the given language. * @@ -180,5 +191,4 @@ public class TransBundle extends Bundle { return locale; } - } diff --git a/src/be/nikiroo/jvcard/resources/enums/StringId.java b/src/be/nikiroo/jvcard/resources/enums/StringId.java index 0a3d004..ced8bfc 100644 --- a/src/be/nikiroo/jvcard/resources/enums/StringId.java +++ b/src/be/nikiroo/jvcard/resources/enums/StringId.java @@ -89,7 +89,7 @@ public enum StringId { @Meta(what = "CLI --help", where = "", format = "", info = "The Help message line for: --") CLI_HELP_TUI, // @Meta(what = "CLI --help", where = "", format = "", info = "The Help message line for: --") - CLI_HELP_NOUTF, // + CLI_HELP_NOUTF_OPTION, // @Meta(what = "CLI --help", where = "", format = "", info = "The Help message line for: --") CLI_HELP_CONFIG, // @Meta(what = "CLI --help", where = "", format = "", info = "The Help message footer about files and jvcard:// links") diff --git a/src/be/nikiroo/jvcard/resources/resources.properties b/src/be/nikiroo/jvcard/resources/resources.properties index 875a1ca..b1783d3 100644 --- a/src/be/nikiroo/jvcard/resources/resources.properties +++ b/src/be/nikiroo/jvcard/resources/resources.properties @@ -46,6 +46,7 @@ KEY_ACTION_SEARCH = Search # (FORMAT: we could use: ' ', ┃, │...) # Field separator DEAULT_FIELD_SEPARATOR = ┃ +DEAULT_FIELD_SEPARATOR_NOUTF = | # (WHAT: Action key, WHERE: ContactDetails) # Invert the photo's colours KEY_ACTION_INVERT = Invert colours @@ -113,7 +114,7 @@ CLI_HELP_GUI = force the SWING terminal emulator CLI_HELP_TUI = force text mode (and supports headless JRE) # (WHAT: CLI --help) # The Help message line for: -- -CLI_HELP_NOUTF = do not use UTF-8, prefer simple ASCII +CLI_HELP_NOUTF_OPTION = do not use UTF-8, prefer simple ASCII # (WHAT: CLI --help) # The Help message line for: -- CLI_HELP_CONFIG = set the configuration directory to DIR diff --git a/src/be/nikiroo/jvcard/resources/resources_en.properties b/src/be/nikiroo/jvcard/resources/resources_en.properties index 7dbc1c4..237c898 100644 --- a/src/be/nikiroo/jvcard/resources/resources_en.properties +++ b/src/be/nikiroo/jvcard/resources/resources_en.properties @@ -46,6 +46,7 @@ KEY_ACTION_SEARCH = Search # (FORMAT: we could use: ' ', ┃, │...) # Field separator DEAULT_FIELD_SEPARATOR = ┃ +DEAULT_FIELD_SEPARATOR_NOUTF = | # (WHAT: Action key, WHERE: ContactDetails) # Invert the photo's colours KEY_ACTION_INVERT = Invert colours @@ -113,7 +114,7 @@ CLI_HELP_GUI = force the SWING terminal emulator CLI_HELP_TUI = force text mode (and supports headless JRE) # (WHAT: CLI --help) # The Help message line for: -- -CLI_HELP_NOUTF = do not use UTF-8, prefer simple ASCII +CLI_HELP_NOUTF_OPTION = do not use UTF-8, prefer simple ASCII # (WHAT: CLI --help) # The Help message line for: -- CLI_HELP_CONFIG = set the configuration directory to DIR diff --git a/src/be/nikiroo/jvcard/resources/resources_fr.properties b/src/be/nikiroo/jvcard/resources/resources_fr.properties index f1af0f3..e14a1fd 100644 --- a/src/be/nikiroo/jvcard/resources/resources_fr.properties +++ b/src/be/nikiroo/jvcard/resources/resources_fr.properties @@ -46,6 +46,7 @@ KEY_ACTION_SEARCH = Rechercher # (FORMAT: we could use: ' ', ┃, │...) # Field separator DEAULT_FIELD_SEPARATOR = ┃ +DEAULT_FIELD_SEPARATOR_NOUTF = | # (WHAT: Action key, WHERE: ContactDetails) # Invert the photo's colours KEY_ACTION_INVERT = Couleurs inversées @@ -113,7 +114,7 @@ CLI_HELP_GUI = force l'émulateur de terminal SWING CLI_HELP_TUI = force le mode texte (et supporte les JRE headless) # (WHAT: CLI --help) # The Help message line for: -- -CLI_HELP_NOUTF = évite l'utilisation de UTF-8, utilise le format ASCII +CLI_HELP_NOUTF_OPTION = évite l'utilisation de UTF-8, utilise le format ASCII # (WHAT: CLI --help) # The Help message line for: -- CLI_HELP_CONFIG = cherche les fichiers de configuration dans DIR -- 2.27.0