Changes

Update again
Line 5: Line 5:  
Localization will happen in the game’s locale. In a Minecraft client the locale is specified by the language settings. On a dedicated server, the only supported locale is <code>en_us</code>. A list of available locales can be found on the [https://minecraft.gamepedia.com/Language#Available_languages Minecraft Wiki].
 
Localization will happen in the game’s locale. In a Minecraft client the locale is specified by the language settings. On a dedicated server, the only supported locale is <code>en_us</code>. A list of available locales can be found on the [https://minecraft.gamepedia.com/Language#Available_languages Minecraft Wiki].
   −
{{Colored box|title=Important|content=The only purpose of a translation key is internationalization. Do not use them for logic, such as comparing if two blocks are equal. Use their [[Registration|registry names]] instead.}}
+
{{Tip/Important|The only purpose of a translation key is internationalization. Do not use them for logic, such as comparing if two blocks are equal. Use their [[Registration|registry names]] instead.}}
    
== Language files ==
 
== Language files ==
Line 21: Line 21:  
== Usage with Blocks and Items ==
 
== Usage with Blocks and Items ==
   −
Block, Item, and a few other Minecraft classes have built-in translation keys used to display their names. These translation keys are specified by overriding <code>getTranslationKey()</code>. Item also has <code>getTranslationKey(ItemStack)</code> which can be overridden to provide different translation keys depending on <code>ItemStack</code> NBT.
+
Block, Item, and a few other Minecraft classes have built-in translation keys used to display their names. These translation keys are specified by overriding <code>getDescriptionId()</code>. Item also has <code>getDescriptionId(ItemStack)</code> which can be overridden to provide different translation keys depending on <code>ItemStack</code> NBT.
   −
By default, <code>getTranslationKey()</code> will return <code>block</code> or <code>item</code>. prepended to the registry name of the block or item, with the colon replaced by a dot. <code>BlockItem</code>s will take their corresponding Block's translation key by default. For example, an item with ID <code>examplemod:example_item</code> effectively requires the following line in a language file:
+
By default, <code>getDescriptionId()</code> will return <code>block</code> or <code>item</code>. prepended to the registry name of the block or item, with the colon replaced by a dot. <code>BlockItem</code>s will take their corresponding Block's translation key by default. For example, an item with ID <code>examplemod:example_item</code> effectively requires the following line in a language file:
    
<syntaxhighlight lang="json">
 
<syntaxhighlight lang="json">
Line 33: Line 33:  
== Localization methods ==
 
== Localization methods ==
   −
{{Colored box|title=Important|content=A common issue is having the server localize for clients. The server can only localize in its own locale, which does not necessarily match the locale of connected clients.
+
{{Tip/Important|A common issue is having the server localize for clients. The server can only localize in its own locale, which does not necessarily match the locale of connected clients.
 
<br/><br/>
 
<br/><br/>
To respect the language settings of clients, the server should have clients localize text in their own locale using <code>TranslationTextComponent</code> or other methods preserving the language neutral translation keys.}}
+
To respect the language settings of clients, the server should have clients localize text in their own locale using components with <code>TranslatableContents</code> or other methods preserving the language neutral translation keys.}}
   −
<h3 id="I18n"><tt style="font-size: 100%">net.minecraft.client.resources.I18n</tt></h3>
+
<h3 id="I18n"><tt style="font-size: 100%">net.minecraft.client.resources.language.I18n</tt></h3>
   −
{{Colored box|background-title-color=#d4101c|title=Warning|content='''This I18n class can only be found on the [[Sides#Different_Kinds_of_Sides|physical client]]!''' It is intended to be used by code that only runs on the client. Attempts to use this on a server will throw exceptions and crash.}}
+
{{Tip/Danger|'''This I18n class can only be found on the [[Sides#Different_Kinds_of_Sides|physical client]]!''' It is intended to be used by code that only runs on the client. Attempts to use this on a server will throw exceptions and crash.}}
   −
<code>format(String, Object...)</code> localizes in the client’s locale with formatting. The first parameter is a translation key, and the rest are formatting arguments for <code>String.format(String, Object...)</code>.
+
<code>get(String, Object...)</code> localizes in the client’s locale with formatting. The first parameter is a translation key, and the rest are formatting arguments for <code>String.format(String, Object...)</code>.
   −
=== <tt style="font-size: 100%">TranslationTextComponent</tt> ===
+
=== <tt style="font-size: 100%">TranslatableContents</tt> ===
   −
<code>TranslationTextComponent</code> is an <code>ITextComponent</code> that is localized and formatted lazily. It is very useful when sending messages to players because it will be automatically localized in their own locale.
+
<code>TranslatableContents</code> is a <code>ComponentContents</code> that is localized and formatted lazily. It is very useful when sending messages to players because it will be automatically localized in their own locale.
   −
The first parameter of the <code>TranslationTextComponent(String, Object...)</code> constructor is a translation key, and the rest are used for formatting. The only supported format specifiers are <code>%s</code> and <code>%1$s</code>, <code>%2$s</code>, <code>%3$s</code> etc. Formatting arguments may be other <code>ITextComponent</code>s that will be inserted into the resulting formatted text with all their attributes preserved.
+
The first parameter of the <code>TranslatableContents(String, Object...)</code> constructor is a translation key, and the rest are used for formatting. The only supported format specifiers are <code>%s</code> and <code>%1$s</code>, <code>%2$s</code>, <code>%3$s</code> etc. Formatting arguments may be other <code>Component</code>s that will be inserted into the resulting formatted text with all their attributes preserved.
 +
 
 +
A <code>MutableComponent</code> can be created using <code>Component#translatable</code> by passing in the <code>TranslatableContents</code>'s parameters. It can also be created using <code>MutableComponent#create</code> by passing in the <code>ComponentContents</code> itself.
 +
 
 +
[[Category:Common Concepts]]