summaryrefslogtreecommitdiff
path: root/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt
blob: 8a9ab36e0448994270e1b039ce0a1cb15a55eb45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package tech.thatgravyboat.rewardclaim

private val TRANSLATION_LINE_REGEX = Regex("\"(?<key>.*)\": ?\"(?<text>.*)\",?")

class RewardLanguage(translationDataFromHtml: String) {

    private val translations = hashMapOf<String, String>()

    fun translate(key: String) = translations.getValue(key)

    //We have to do it this way as this is easier than fixing all the things that isn't
    //valid in normal json but is valid in javascript objects. Such as escaped single quotes and trailing commas.
    init {
        TRANSLATION_LINE_REGEX.findAll(translationDataFromHtml.replace("\\'", "'")).apply {
            this.forEach { translations[it.groups["key"]!!.value] = it.groups["text"]!!.value }
        }
    }
}