Skip to content

Commit

Permalink
Fixed implicitly dropping first keys
Browse files Browse the repository at this point in the history
  • Loading branch information
diareuse committed Aug 24, 2022
1 parent c5871f5 commit 4724877
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class LocalizationKeyReaderCsv(
override val keys: Sequence<String>
get() = sequence {
file.csvParser().use {
for (line in it.drop(1)) {
val lines = it.dropWhile { key -> keyRegex.matches(key.firstOrNull().orEmpty()) }
for (line in lines) {
yield(line[0])
}
}
Expand All @@ -40,7 +41,7 @@ class LocalizationKeyReaderCsv(

private fun CSVParser.asTranslationSequence(key: String): Sequence<Pair<Locale, String>> {
return sequence {
val languages = headerMap.entries.drop(1)
val languages = headerMap.entries.dropWhile { keyRegex.matches(it.key) }
val translations = find { it[0] == key } ?: return@sequence
for ((language, index) in languages) {
val locale = Locale.forLanguageTag(language)
Expand All @@ -62,4 +63,10 @@ class LocalizationKeyReaderCsv(

}

companion object {

private val keyRegex = Regex("^[kK][eE][yY][sS]?")

}

}

0 comments on commit 4724877

Please sign in to comment.