From 567a3385ff3f407dda1c38bc1d6abfc109652af4 Mon Sep 17 00:00:00 2001 From: marhali Date: Sun, 10 Apr 2022 20:27:37 +0200 Subject: [PATCH] provide translation value replacement --- .../marhali/easyi18n/model/Translation.java | 1 + .../model/translation/TranslationValue.java | 107 ++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 src/main/java/de/marhali/easyi18n/model/translation/TranslationValue.java diff --git a/src/main/java/de/marhali/easyi18n/model/Translation.java b/src/main/java/de/marhali/easyi18n/model/Translation.java index 3237813..cced758 100644 --- a/src/main/java/de/marhali/easyi18n/model/Translation.java +++ b/src/main/java/de/marhali/easyi18n/model/Translation.java @@ -7,6 +7,7 @@ import java.util.HashMap; * This class contains only the translations for this unspecific element. * @author marhali */ +@Deprecated // Replaced by TranslationValue public class Translation extends HashMap { public Translation() { super(); diff --git a/src/main/java/de/marhali/easyi18n/model/translation/TranslationValue.java b/src/main/java/de/marhali/easyi18n/model/translation/TranslationValue.java new file mode 100644 index 0000000..f3e2688 --- /dev/null +++ b/src/main/java/de/marhali/easyi18n/model/translation/TranslationValue.java @@ -0,0 +1,107 @@ +package de.marhali.easyi18n.model.translation; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; + +/** + * Represents the set values behind a specific translation. + * @author marhali + */ +public class TranslationValue { + + private @Nullable String description; + private @NotNull Map values; + private @Nullable Object misc; + + public TranslationValue(@Nullable String description, @NotNull Map values, @Nullable Object misc) { + this.description = description; + this.values = values; + this.misc = misc; + } + + public TranslationValue(@NotNull Map values) { + this(null, values, null); + } + + public TranslationValue(@NotNull String locale, @NotNull String value) { + this(Map.of(locale, value)); + } + + public TranslationValue() { + this(null, new HashMap<>(), null); + } + + /** + * Retrieve additional description for this translation + * @return Description + */ + public @Nullable String getDescription() { + return description; + } + + /** + * Override or set description for this translation + * @param description Description + */ + public void setDescription(@Nullable String description) { + this.description = description; + } + + /** + * Set locale specific values. + * @param values New values + */ + public void setValues(@NotNull Map values) { + this.values = values; + } + + /** + * Overrides or sets a value for a specific locale. + * @param locale Locale type + * @param value New value + */ + public void put(@NotNull String locale, @Nullable String value) { + if(value == null) { // Delete operation + values.remove(locale); + } else { + values.put(locale, value); + } + } + + /** + * Retrieves the associated value for a specific locale + * @param locale Locale type + * @return Value or null if missing + */ + public @Nullable String get(@NotNull String locale) { + return values.get(locale); + } + + /** + * I18n support data + * @return Data + */ + public @Nullable Object getMisc() { + return misc; + } + + /** + * Set or update I18n support data + * @param misc New Data + */ + public void setMisc(@Nullable Object misc) { + this.misc = misc; + } + + @Override + public String toString() { + return "TranslationValue{" + + "description='" + description + '\'' + + ", values=" + values + + ", misc=" + misc + + '}'; + } +}