mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-21 08:07:16 +00:00
updates in IetfLanguageCode
This commit is contained in:
parent
7229a3e198
commit
5ee5bfd1d5
@ -2,6 +2,10 @@
|
||||
|
||||
## 0.5.19
|
||||
|
||||
* `LanguageCode`:
|
||||
* `IetfLanguageCode` became as sealed class
|
||||
* `IetfLanguageCode` now override `toString` and returns its code
|
||||
|
||||
## 0.5.18
|
||||
|
||||
* `LanguageCode`:
|
||||
|
@ -5,6 +5,7 @@ import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.File
|
||||
import java.text.Normalizer
|
||||
|
||||
private val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
@ -29,6 +30,8 @@ fun String.adaptAsTitle() = if (first().isDigit()) {
|
||||
this
|
||||
}
|
||||
|
||||
fun String.normalized() = Normalizer.normalize(this, Normalizer.Form.NFD).replace(Regex("[^\\p{ASCII}]"), "")
|
||||
|
||||
@Serializable
|
||||
private data class LanguageCodeWithTag(
|
||||
@SerialName("langType")
|
||||
@ -74,11 +77,11 @@ private fun printLanguageCodeAndTags(
|
||||
indents: String = " "
|
||||
): String = if (tag.subtags.isEmpty()) {
|
||||
"""${indents}${baseClassSerializerAnnotationName}
|
||||
${indents}object ${tag.title} : ${parent ?.title ?.let { "$it()" } ?: baseClassName} { override val code: String = "${tag.tag}" }"""
|
||||
${indents}object ${tag.title} : ${parent ?.title ?: baseClassName}() { override val code: String = "${tag.tag}" }"""
|
||||
} else {
|
||||
"""
|
||||
${indents}${baseClassSerializerAnnotationName}
|
||||
${indents}sealed class ${tag.title} : ${parent ?.title ?.let { "$it()" } ?: baseClassName} {
|
||||
${indents}sealed class ${tag.title} : ${parent ?.title ?: baseClassName}() {
|
||||
${indents} override val code: String = "${tag.tag}"
|
||||
|
||||
${tag.subtags.joinToString("\n") { printLanguageCodeAndTags(it, tag, "${indents} ") }}
|
||||
@ -98,13 +101,15 @@ import kotlinx.serialization.Serializable
|
||||
* https://datahub.io/core/language-codes/ files (base and tags) and create the whole hierarchy using it.
|
||||
*/
|
||||
${baseClassSerializerAnnotationName}
|
||||
sealed interface $baseClassName {
|
||||
val code: String
|
||||
sealed class $baseClassName {
|
||||
abstract val code: String
|
||||
|
||||
${tags.joinToString("\n") { printLanguageCodeAndTags(it, indents = " ") } }
|
||||
|
||||
$baseClassSerializerAnnotationName
|
||||
data class $unknownBaseClassName (override val code: String) : $baseClassName
|
||||
data class $unknownBaseClassName (override val code: String) : $baseClassName()
|
||||
|
||||
override fun toString() = code
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@ -179,18 +184,14 @@ suspend fun main(vararg args: String) {
|
||||
val subtags = unformattedSubtags.mapNotNull {
|
||||
if (it.endTag == null) {
|
||||
val currentSubtags = (threeLevelTags[it.subtag] ?: emptyList()).map {
|
||||
Tag(it.endTagAsTitle!!, it.withSubtag, emptyList())
|
||||
Tag(it.endTagAsTitle!!.normalized(), it.withSubtag, emptyList())
|
||||
}
|
||||
Tag(it.middleTagTitle, it.withSubtag, currentSubtags)
|
||||
Tag(it.middleTagTitle.normalized(), it.withSubtag, currentSubtags)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
Tag(
|
||||
it.title,
|
||||
it.tag,
|
||||
subtags
|
||||
)
|
||||
Tag(it.title.normalized(), it.tag, subtags)
|
||||
}
|
||||
|
||||
File(outputFolder, "LanguageCodes.kt").apply {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -461,9 +461,9 @@ fun String.asIetfLanguageCode(): IetfLanguageCode {
|
||||
IetfLanguageCode.Burmese.code -> IetfLanguageCode.Burmese
|
||||
IetfLanguageCode.Burmese.MM.code -> IetfLanguageCode.Burmese.MM
|
||||
IetfLanguageCode.Nauru.code -> IetfLanguageCode.Nauru
|
||||
IetfLanguageCode.BokmålNorwegianNorwegianBokmål.code -> IetfLanguageCode.BokmålNorwegianNorwegianBokmål
|
||||
IetfLanguageCode.BokmålNorwegianNorwegianBokmål.NO.code -> IetfLanguageCode.BokmålNorwegianNorwegianBokmål.NO
|
||||
IetfLanguageCode.BokmålNorwegianNorwegianBokmål.SJ.code -> IetfLanguageCode.BokmålNorwegianNorwegianBokmål.SJ
|
||||
IetfLanguageCode.BokmalNorwegianNorwegianBokmal.code -> IetfLanguageCode.BokmalNorwegianNorwegianBokmal
|
||||
IetfLanguageCode.BokmalNorwegianNorwegianBokmal.NO.code -> IetfLanguageCode.BokmalNorwegianNorwegianBokmal.NO
|
||||
IetfLanguageCode.BokmalNorwegianNorwegianBokmal.SJ.code -> IetfLanguageCode.BokmalNorwegianNorwegianBokmal.SJ
|
||||
IetfLanguageCode.NdebeleNorthNorthNdebele.code -> IetfLanguageCode.NdebeleNorthNorthNdebele
|
||||
IetfLanguageCode.NdebeleNorthNorthNdebele.ZW.code -> IetfLanguageCode.NdebeleNorthNorthNdebele.ZW
|
||||
IetfLanguageCode.Nepali.code -> IetfLanguageCode.Nepali
|
||||
@ -639,8 +639,8 @@ fun String.asIetfLanguageCode(): IetfLanguageCode {
|
||||
IetfLanguageCode.Venda.code -> IetfLanguageCode.Venda
|
||||
IetfLanguageCode.Vietnamese.code -> IetfLanguageCode.Vietnamese
|
||||
IetfLanguageCode.Vietnamese.VN.code -> IetfLanguageCode.Vietnamese.VN
|
||||
IetfLanguageCode.Volapük.code -> IetfLanguageCode.Volapük
|
||||
IetfLanguageCode.Volapük.L001.code -> IetfLanguageCode.Volapük.L001
|
||||
IetfLanguageCode.Volapuk.code -> IetfLanguageCode.Volapuk
|
||||
IetfLanguageCode.Volapuk.L001.code -> IetfLanguageCode.Volapuk.L001
|
||||
IetfLanguageCode.Walloon.code -> IetfLanguageCode.Walloon
|
||||
IetfLanguageCode.Wolof.code -> IetfLanguageCode.Wolof
|
||||
IetfLanguageCode.Wolof.SN.code -> IetfLanguageCode.Wolof.SN
|
||||
|
Loading…
Reference in New Issue
Block a user