summaryrefslogtreecommitdiff
path: root/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt
diff options
context:
space:
mode:
authorGravy Boat <thatgravyboat@gmail.com>2021-09-23 19:25:26 -0230
committerGravy Boat <thatgravyboat@gmail.com>2021-09-23 19:25:26 -0230
commit7dc51e6f1f280276d782e3c644099758ff01bdb7 (patch)
tree89bbbbcc22b100c20e752a750ccef0547c466229 /src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt
parentf71b3ccee2ec9949de7e572375a45dbf1c3fadb8 (diff)
downloadRewardClaim-7dc51e6f1f280276d782e3c644099758ff01bdb7.tar.gz
RewardClaim-7dc51e6f1f280276d782e3c644099758ff01bdb7.tar.bz2
RewardClaim-7dc51e6f1f280276d782e3c644099758ff01bdb7.zip
Initial Commit
Diffstat (limited to 'src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt')
-rw-r--r--src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt b/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt
new file mode 100644
index 0000000..6361bc5
--- /dev/null
+++ b/src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt
@@ -0,0 +1,20 @@
+package tech.thatgravyboat.rewardclaim
+
+import java.util.regex.Pattern
+
+private val TRANSLATION_LINE_REGEX = Pattern.compile("\"(?<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.matcher(translationDataFromHtml.replace("\\'", "'")).apply {
+ while (find()) translations[group("key")] = group("text")
+ }
+ }
+} \ No newline at end of file