diff options
author | Gravy Boat <thatgravyboat@gmail.com> | 2021-09-23 19:25:26 -0230 |
---|---|---|
committer | Gravy Boat <thatgravyboat@gmail.com> | 2021-09-23 19:25:26 -0230 |
commit | 7dc51e6f1f280276d782e3c644099758ff01bdb7 (patch) | |
tree | 89bbbbcc22b100c20e752a750ccef0547c466229 /src/main/kotlin/tech/thatgravyboat/rewardclaim/RewardLanguage.kt | |
parent | f71b3ccee2ec9949de7e572375a45dbf1c3fadb8 (diff) | |
download | RewardClaim-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.kt | 20 |
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 |