summaryrefslogtreecommitdiff
path: root/support/arara/source/src/main/kotlin/org/islandoftex/arara/localization/Language.kt
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-03-05 03:00:59 +0000
committerNorbert Preining <norbert@preining.info>2020-03-05 03:00:59 +0000
commit898048513951b471a492afa23e46112d14bcb236 (patch)
tree8596afc705f55d2d07b324a756f7283ac0e2d21b /support/arara/source/src/main/kotlin/org/islandoftex/arara/localization/Language.kt
parent19d25b8009801aa98ea2f46b45c37c257f990491 (diff)
CTAN sync 202003050300
Diffstat (limited to 'support/arara/source/src/main/kotlin/org/islandoftex/arara/localization/Language.kt')
-rw-r--r--support/arara/source/src/main/kotlin/org/islandoftex/arara/localization/Language.kt69
1 files changed, 69 insertions, 0 deletions
diff --git a/support/arara/source/src/main/kotlin/org/islandoftex/arara/localization/Language.kt b/support/arara/source/src/main/kotlin/org/islandoftex/arara/localization/Language.kt
new file mode 100644
index 0000000000..2afa77c41e
--- /dev/null
+++ b/support/arara/source/src/main/kotlin/org/islandoftex/arara/localization/Language.kt
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: BSD-3-Clause
+package org.islandoftex.arara.localization
+
+import java.util.Locale
+import org.islandoftex.arara.model.AraraException
+
+/**
+ * Implements the language model.
+ *
+ * @author Island of TeX
+ * @version 5.0
+ * @since 4.0
+ */
+class Language(code: String) {
+ // the language code, based on
+ // ISO 639-1 and language variants
+ private val code: String
+
+ /**
+ * Gets the language name.
+ *
+ * @return A string representing the language name.
+ */
+ val name: String
+ get() = languages.getValue(code).first
+
+ /**
+ * Gets the language locale.
+ *
+ * @return The language locale.
+ */
+ val locale: Locale
+ get() = languages.getValue(code).second
+
+ // throws an exception on invalid language
+ init {
+ if (languages.containsKey(code)) {
+ this.code = code
+ } else {
+ throw AraraException(
+ LanguageController.getMessage(
+ Messages.ERROR_LANGUAGE_INVALID_CODE,
+ languagesList
+ )
+ )
+ }
+ }
+
+ companion object {
+ // map containing all languages
+ // supported by arara
+ private val languages = mapOf(
+ "en" to Pair("English", Locale("en")),
+ "de" to Pair("German", Locale("de")),
+ "nl" to Pair("Dutch", Locale("nl")),
+ "qn" to Pair("Broad Norfolk", Locale("en", "QN")),
+ "ptbr" to Pair("Brazilian Portuguese", Locale("pt", "BR")),
+ "it" to Pair("Italian", Locale("it"))
+ )
+
+ /**
+ * String representing the list of available languages
+ * because they don't change initialized with the string
+ */
+ val languagesList: String = "(" + languages.map { (key, value) ->
+ value.first + ": " + key
+ }.joinToString(", ") + ")"
+ }
+}