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