Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I've recently moved from 1.12.2 and I am having some trouble getting translations from the JSON lang files.

Getting translations for items/blocks or enchantments work perfectly but not with custom keys.

 

I am trying to create translatable components for configs:

 

In the lang JSON file I created an entry like this,

 

"config.<config_name>" : "Some english translation text..."

 

and within the code I call it like this:

 

private static String fromConfigKey(String key) {
	return new TranslationTextComponent("config." + key).getUnformattedComponentText();
}

 

but returns an empty string.

 

I have noticed that TranslationTextComponent#getUnformattedComponentText returns an empty string by default, is this something new? Do I have to create my own sub class of TranslationTextComponent which implements this one way or another? 

  • Author

Ok. I've tried this using ITextComponent instead:

 

private static ITextComponent fromConfigKey(String key) {
	return ITextComponent.getTextComponentOrEmpty("config." + key);
}

 

This returns the key and not its translatation. I get the same result when calling getString or getUnformattedComponentText.

 

Maybe this might help too. Heres how I try to register a config:

 

public class Configs {

	...

    public static ForgeConfigSpec.EnumValue<CarveType> CARVE_TYPE;

    public Configs(ForgeConfigSpec.Builder forgeConfigBuilder) {
        ConfigBuilder builder = new ConfigBuilder(forgeConfigBuilder);

        CARVE_TYPE = builder.defineEnum("carve_type", CarveType.CONNECTED, CarveType.values());
    }
      
    private static class ConfigBuilder {
      
      	private static ForgeConfigSpec.Builder BUILDER;

        private ConfigBuilder(ForgeConfigSpec.Builder builder) {
            BUILDER = builder;
        }
      
      	...
      
        public final <V extends Enum<V>> ForgeConfigSpec.EnumValue<V> defineEnum(String key, V defaultValue, V... enums) {
            ITextComponent note = noteFromConfigKey(key);
            return !note.getString().equals("")
                    ? BUILDER.comment(fromConfigKey(key).getString(), note.getString()).defineEnum(key, defaultValue, enums)
                    : BUILDER.comment(fromConfigKey(key).getString()).defineEnum(key, defaultValue, enums);
        }
      
      	private static ITextComponent fromConfigKey(String key) {
      		return ITextComponent.getTextComponentOrEmpty("config." + key);
      	}
      
      	private static ITextComponent noteFromConfigKey(String key) {
            return fromConfigKey(key + ".note");
        }
	}

    public enum CarveType {
        CONNECTED, ALL
    }
}

 

This results in a config file like this:

 

#config.carve_type
#config.carve_type.note
#Allowed Values: CONNECTED, ALL
carve_type = "CONNECTED"

 

and my en_us.json:

 

{
	"config.carve_type": "Block carve type [...] "
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.