1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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(", ") + ")"
}
}
|