From 898048513951b471a492afa23e46112d14bcb236 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Thu, 5 Mar 2020 03:00:59 +0000 Subject: CTAN sync 202003050300 --- .../org/islandoftex/arara/localization/Language.kt | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 support/arara/source/src/main/kotlin/org/islandoftex/arara/localization/Language.kt (limited to 'support/arara/source/src/main/kotlin/org/islandoftex/arara/localization/Language.kt') 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(", ") + ")" + } +} -- cgit v1.2.3