Skip to content

Commit

Permalink
Implement Localization Support for Singularities (#13)
Browse files Browse the repository at this point in the history
Fixes #12 

It is now possible to translate both the default Singularities and custom Singularities via lang files.

Translation strings have been added for the default materials in both the en_us and ru_ru locales. Thanks to @NotMyWing for verifying the existing and supplying new Russian translations.

Custom Singularity lang entries will require the use of a helper mod such as ResourceLoader. Materials without a defined translation will default to the material name converted to Title Case, e.g.:

lots_of_spaghetti => Lots Of Spaghetti

* Bump dependency versions
* Add Resource Loader to dev runtime to support localization

Co-authored-by: NotMyWing <[email protected]>
  • Loading branch information
Exaxxion and NotMyWing authored Sep 21, 2021
1 parent fcabe0e commit 149ac46
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 19 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ repositories {

dependencies {
deobfCompile "mezz.jei:jei_1.12.2:4.16.1.301:api"
runtime "mezz.jei:jei_1.12.2:4.16.1.301"
deobfCompile "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.655"
runtime "mezz.jei:jei_1.12.2:4.16.1.301"
runtime "curse.maven:resource-loader:2477566"
deobfCompile "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.660"
deobfCompile "curse.maven:cucumber:2645867"
deobfCompile "curse.maven:hwyla:2568751"
deobfCompile "curse.maven:packagedauto:3214216"
deobfCompile "curse.maven:packagedauto:3418955"
deobfCompile "curse.maven:pexc:3214400"
deobfCompile "gregtechce:gregtech:1.12.2:1.17.0.764"
deobfCompile "codechicken-lib-1-8:CodeChickenLib-1.12.2:3.2.3.358:universal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.blakebr0.cucumber.helper.ResourceHelper;
import com.blakebr0.cucumber.iface.IEnableable;
import com.blakebr0.cucumber.item.ItemMeta;
import com.blakebr0.cucumber.util.Utils;
import com.blakebr0.extendedcrafting.ExtendedCrafting;
import com.blakebr0.extendedcrafting.config.ModConfig;
import com.blakebr0.extendedcrafting.crafting.CompressorRecipeManager;
Expand All @@ -13,12 +12,12 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import org.apache.commons.lang3.text.WordUtils;

import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -37,8 +36,12 @@ public ItemSingularity() {

@Override
public String getItemStackDisplayName(ItemStack stack) {
String name = items.containsKey(stack.getMetadata()) ? items.get(stack.getMetadata()).getName().replace("_", " ") : "Dummy";
return WordUtils.capitalize(name) + " " + Utils.localize("item.ec.singularity.name");
String localizedMaterialName = "Invalid";
if (items.containsKey(stack.getMetadata())) {
String materialName = items.get(stack.getMetadata()).getName();
localizedMaterialName = I18n.translateToLocal("item.ec.singularity." + materialName);
}
return I18n.translateToLocalFormatted("item.ec.singularity.name", localizedMaterialName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.blakebr0.cucumber.iface.IEnableable;
import com.blakebr0.cucumber.iface.IModelHelper;
import com.blakebr0.cucumber.item.ItemMeta;
import com.blakebr0.cucumber.util.Utils;
import com.blakebr0.extendedcrafting.ExtendedCrafting;
import com.blakebr0.extendedcrafting.config.ModConfig;
import com.blakebr0.extendedcrafting.crafting.CompressorRecipeManager;
Expand All @@ -14,6 +13,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.translation.I18n;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.Configuration;
Expand All @@ -39,8 +39,19 @@ public ItemSingularityCustom() {

@Override
public String getItemStackDisplayName(ItemStack stack) {
String name = items.containsKey(stack.getMetadata()) ? items.get(stack.getMetadata()).getName().replace("_", " ") : "Dummy";
return WordUtils.capitalize(name) + " " + Utils.localize("item.ec.singularity.name");
String localizedMaterialName = "Invalid";
int meta = stack.getMetadata();
if (items.containsKey(meta)) {
String materialName = items.get(meta).getName();
String assumedTranslationKey = "item.ec.singularity." + materialName;

// Try to translate it using lang files
if(I18n.canTranslate(assumedTranslationKey))
localizedMaterialName = I18n.translateToLocal(assumedTranslationKey);
else // fallback to capitalized version of the registration name
localizedMaterialName = WordUtils.capitalize(materialName.replaceAll("_"," "));
}
return I18n.translateToLocalFormatted("item.ec.singularity.name", localizedMaterialName);
}

@Override
Expand All @@ -63,7 +74,11 @@ public void configure(Configuration config) {
+ "\n- Note: you can also specify meta for item ids, by adding them to the end of the item id."
+ "\n- Example: minecraft:stone:3 for a meta of 3. Make the meta 32767 for wildcard value."
+ "\n- 'color' the color of the singularity as a hex value. http://htmlcolorcodes.com/"
+ "\n- Example: 123456 would color it as whatever that color is.");
+ "\n- Example: 123456 would color it as whatever that color is."
+ "\n - Use the localization key \"item.ec.singularity.<name>\" to set the name of your custom Singularity."
+ "\n - Example: item.ec.singularity.carrot=Carrot in your resources/extendedcrafting/lang/en_us.lang"
+ "\n - and item.ec.singularity.carrot=морковь in your resources/extendedcrafting/lang/ru_ru.lang"
+ "\n - Note however that you will need a way to load these resources, such as the mod ResourceLoader.");

for (String value : values) {
String[] parts = value.split(";");
Expand Down
52 changes: 48 additions & 4 deletions src/main/resources/assets/extendedcrafting/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ item.ec.handheld_table.name=Handheld Crafting Table

item.ec.recipe_maker.name=Recipe Maker

item.ec.singularity.name=Singularity
item.ec.singularity_ultimate.name=The Ultimate Singularity

# CONTAINERS
container.ec.crafting_core=Crafting Core
container.ec.interface=Automation Interface
Expand Down Expand Up @@ -200,4 +197,51 @@ guide.entry.interface.page.3=The <red>Automation Interface<r> also has some auto
guide.entry.interface.page.4=<b>Smart Insert:<r> the interface will not allow <red>Auto Insert<r> to insert items into the <red>input<r> slot that can't be inserted into the table.

guide.entry.singularity=Singularities
guide.entry.singularity.page.1=<b>Singularities<r> are highly compressed materials. These are <i>usually<r> created using a <red>Quantum Compressor<r>. <n><n>Crafting all of the available singularities together in an <red>Ultimate Crafting Table<r> will reward you with <red>The Ultimate Singularity<r>.
guide.entry.singularity.page.1=<b>Singularities<r> are highly compressed materials. These are <i>usually<r> created using a <red>Quantum Compressor<r>. <n><n>Crafting all of the available singularities together in an <red>Ultimate Crafting Table<r> will reward you with <red>The Ultimate Singularity<r>.

item.ec.singularity.name=%s Singularity
item.ec.singularity_ultimate.name=The Ultimate Singularity

## Default Singularity Item Names

# Singularity Localizations - Vanilla Materials
item.ec.singularity.coal=Coal
item.ec.singularity.iron=Iron
item.ec.singularity.lapis_lazuli=Lapis Lazuli
item.ec.singularity.redstone=Redstone
item.ec.singularity.glowstone=Glowstone
item.ec.singularity.gold=Gold
item.ec.singularity.diamond=Diamond
item.ec.singularity.emerald=Emerald

#Default Singularities - Common Mod Materials
item.ec.singularity.aluminum=Aluminum
item.ec.singularity.brass=Brass
item.ec.singularity.bronze=Bronze
item.ec.singularity.chrome=Chrome
item.ec.singularity.constantan=Constantan
item.ec.singularity.copper=Copper
item.ec.singularity.electrum=Electrum
item.ec.singularity.invar=Invar
item.ec.singularity.iridium=Iridium
item.ec.singularity.lead=Lead
item.ec.singularity.mithril=Mithril
item.ec.singularity.nickel=Nickel
item.ec.singularity.platinum=Platinum
item.ec.singularity.silver=Silver
item.ec.singularity.steel=Steel
item.ec.singularity.tin=Tin
item.ec.singularity.titanium=Titanium
item.ec.singularity.tungsten=Tungsten
item.ec.singularity.uranium=Uranium
item.ec.singularity.zinc=Zinc

# Default Singularities - Thermal Expansion Alloys
item.ec.singularity.enderium=Enderium
item.ec.singularity.lumium=Lumium
item.ec.singularity.signalum=Signalum

# Default Singularities - Tinkers' Construct Materials
item.ec.singularity.ardite=Ardite
item.ec.singularity.cobalt=Cobalt
item.ec.singularity.manyullyn=Manyullyn
48 changes: 44 additions & 4 deletions src/main/resources/assets/extendedcrafting/lang/ru_ru.lang
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ item.ec.handheld_table.name=Ручной верстак

item.ec.recipe_maker.name=Создатель рецептов

item.ec.singularity.name=Сингулярность
item.ec.singularity_ultimate.name=Максимальная сингулярность

# CONTAINERS
container.ec.crafting_core=Ядро создания
container.ec.interface=Автоматический интерфейс
Expand Down Expand Up @@ -196,4 +193,47 @@ guide.entry.interface.page.3=The <red>Automation Interface<r> also has some auto
guide.entry.interface.page.4=<b>Smart Insert:<r> the interface will not allow <red>Auto Insert<r> to insert items into the <red>input<r> slot that can't be inserted into the table.

guide.entry.singularity=Singularities
guide.entry.singularity.page.1=<b>Singularities<r> are highly compressed materials. These are <i>usually<r> created using a <red>Quantum Compressor<r>. <n><n>Crafting all of the available singularities together in an <red>Ultimate Crafting Table<r> will reward you with <red>The Ultimate Singularity<r>.
guide.entry.singularity.page.1=<b>Singularities<r> are highly compressed materials. These are <i>usually<r> created using a <red>Quantum Compressor<r>. <n><n>Crafting all of the available singularities together in an <red>Ultimate Crafting Table<r> will reward you with <red>The Ultimate Singularity<r>.

# Singularity Localizations
item.ec.singularity.name=%s сингулярность
item.ec.singularity_ultimate.name=Максимальная сингулярность

item.ec.singularity.aluminum=Алюминиевая
item.ec.singularity.brass=Латунная
item.ec.singularity.bronze=Бронзовая
item.ec.singularity.chrome=Хромовая
item.ec.singularity.coal=Угольная
item.ec.singularity.constantan=Константановая
item.ec.singularity.copper=Медная
item.ec.singularity.diamond=Алмазная
item.ec.singularity.electrum=Электрумовая
item.ec.singularity.emerald=Изумрудная
item.ec.singularity.glowstone=Светокаменная
item.ec.singularity.gold=Золотая
item.ec.singularity.invar=Инваровая
item.ec.singularity.iridium=Иридиевая
item.ec.singularity.iron=Железная
item.ec.singularity.lapis_lazuli=Лазуритовая
item.ec.singularity.lead=Свинцовая
item.ec.singularity.mithril=Мифриловая
item.ec.singularity.nickel=Никелевая
item.ec.singularity.platinum=Платиновая
item.ec.singularity.redstone=Краснокаменная
item.ec.singularity.silver=Серебряная
item.ec.singularity.steel=Стальная
item.ec.singularity.tin=Оловянная
item.ec.singularity.titanium=Титановая
item.ec.singularity.tungsten=Вольфрамовая
item.ec.singularity.uranium=Урановая
item.ec.singularity.zinc=Цинковая

# Default Singularities - Thermal Expansion Alloys
item.ec.singularity.enderium=Эндериевая
item.ec.singularity.lumium=Люмиевая
item.ec.singularity.signalum=Сигналовая

# Default Singularities - Tinkers' Construct Materials
item.ec.singularity.ardite=Ардитовая
item.ec.singularity.cobalt=Кобальтовая
item.ec.singularity.manyullyn=Манулиновая

0 comments on commit 149ac46

Please sign in to comment.