diff options
| author | ilotterytea <iltsu@alright.party> | 2022-09-03 02:25:11 +0600 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2022-09-03 02:25:11 +0600 |
| commit | 3d8639d62a2c28750654b767fd940cd223c62e32 (patch) | |
| tree | cea94e151abb079eb8f0941ce6964c1a74c22d42 /core/src/com/ilotterytea/maxoning/utils | |
| parent | 344f66424c5d94b4443b477ef016730d8615cf91 (diff) | |
Localization!!!
Diffstat (limited to 'core/src/com/ilotterytea/maxoning/utils')
| -rw-r--r-- | core/src/com/ilotterytea/maxoning/utils/AssetLoading.java | 12 | ||||
| -rw-r--r-- | core/src/com/ilotterytea/maxoning/utils/I18N.java | 49 |
2 files changed, 55 insertions, 6 deletions
diff --git a/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java b/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java index 85880d0..a81538f 100644 --- a/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java +++ b/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java @@ -40,9 +40,9 @@ public class AssetLoading { // Sounds: } - public static void registerItems(AssetManager am) { + public static void registerItems(AssetManager am, I18N i18n) { MaxonItemRegister.register( - 0, "The Suspicious and Sleepy Bro", "A falling asleep Bror will help you to pet Maxon almost to besvimers.", + 0, i18n.TranslatableText("pet.bror.name"), i18n.TranslatableText("pet.bror.desc"), new AnimatedImage(SpriteUtils.splitToTextureRegions(am.get("sprites/sheet/bror.png", Texture.class), 112, 112, 11, 7)), MaxonItemEnum.SLAVE, 600, @@ -50,7 +50,7 @@ public class AssetLoading { ); MaxonItemRegister.register( - 1, "The Sandwich Cat", "Even though his head is shielded from the light by bread, he can still to pet Maxon by his cheeks", + 1, i18n.TranslatableText("pet.sandwich.name"), i18n.TranslatableText("pet.sandwich.desc"), new AnimatedImage(SpriteUtils.splitToTextureRegions(am.get("sprites/sheet/sandwich_cat.png", Texture.class), 112, 112, 4, 7)), MaxonItemEnum.SLAVE, 2000, @@ -58,7 +58,7 @@ public class AssetLoading { ); MaxonItemRegister.register( - 2, "Manlooshka", "rrrrr", + 2, i18n.TranslatableText("pet.manlooshka.name"), i18n.TranslatableText("pet.manlooshka.desc"), new AnimatedImage(SpriteUtils.splitToTextureRegions(am.get("sprites/sheet/manlooshka.png", Texture.class), 112, 112, 10, 4)), MaxonItemEnum.SLAVE, 8000, @@ -66,7 +66,7 @@ public class AssetLoading { ); MaxonItemRegister.register( - 3, "The Thirsty Cat", "Every time the kitty drinks water, drops of spilled water fall on the screen and pet Maxon's dry cheeks.", + 3, i18n.TranslatableText("pet.thirsty.name"), i18n.TranslatableText("pet.thirsty.desc"), new AnimatedImage(SpriteUtils.splitToTextureRegions(am.get("sprites/sheet/thirsty_cat.png", Texture.class), 112, 112, 6, 3)), MaxonItemEnum.SLAVE, 20000, @@ -74,7 +74,7 @@ public class AssetLoading { ); MaxonItemRegister.register( - 4, "The Furios Cat", "Petting FURIOSLY !!!", + 4, i18n.TranslatableText("pet.furios.name"), i18n.TranslatableText("pet.furios.desc"), new AnimatedImage(SpriteUtils.splitToTextureRegions(am.get("sprites/sheet/furios_cat.png", Texture.class), 112, 112, 7, 4)), MaxonItemEnum.SLAVE, 75000, diff --git a/core/src/com/ilotterytea/maxoning/utils/I18N.java b/core/src/com/ilotterytea/maxoning/utils/I18N.java new file mode 100644 index 0000000..ef81350 --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/utils/I18N.java @@ -0,0 +1,49 @@ +package com.ilotterytea.maxoning.utils; + +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.utils.JsonReader; +import com.badlogic.gdx.utils.JsonValue; + +import java.lang.StringBuilder; +import java.util.*; + +public class I18N { + private Map<String, String> language = new HashMap<>(); + + public I18N(String languageId) { + FileHandle fh = new FileHandle(String.format("i18n/%s.json", languageId)); + + JsonValue json = new JsonReader().parse(fh); + + for (JsonValue val : json.iterator()) { + language.put(val.name, json.getString(val.name)); + } + } + + public String TranslatableText(String id) { + if (language.containsKey(id)) { + return language.get(id); + } + return null; + } + + public String FormattedText(String id, CharSequence... params) { + if (!language.containsKey(id)) { return null; } + Scanner scan = new Scanner(language.get(id)); + StringBuilder result = new StringBuilder(); + int index = 0; + + while (scan.hasNext()) { + String next = scan.next(); + + if (next.contains("%s")) { + next = next.replace("%s", params[index]); + if (index + 1 < params.length) { index++; } + } + + result.append(next); + } + + return result.toString(); + } +} |
