#3430: Add new fallback field to TranslatableComponent
This commit is contained in:
parent
71ac9b34fa
commit
19424aba9d
@ -30,6 +30,10 @@ public final class TranslatableComponent extends BaseComponent
|
||||
* The components to substitute into the translation
|
||||
*/
|
||||
private List<BaseComponent> with;
|
||||
/**
|
||||
* The fallback, if the translation is not found
|
||||
*/
|
||||
private String fallback;
|
||||
|
||||
/**
|
||||
* Creates a translatable component from the original to clone it.
|
||||
@ -153,6 +157,11 @@ public final class TranslatableComponent extends BaseComponent
|
||||
{
|
||||
String trans = TranslationRegistry.INSTANCE.translate( translate );
|
||||
|
||||
if ( trans.equals( translate ) && fallback != null )
|
||||
{
|
||||
trans = fallback;
|
||||
}
|
||||
|
||||
Matcher matcher = format.matcher( trans );
|
||||
int position = 0;
|
||||
int i = 0;
|
||||
|
@ -28,7 +28,11 @@ public class TranslatableComponentSerializer extends BaseComponentSerializer imp
|
||||
component.setTranslate( object.get( "translate" ).getAsString() );
|
||||
if ( object.has( "with" ) )
|
||||
{
|
||||
component.setWith( Arrays.asList( context.<BaseComponent[]>deserialize( object.get( "with" ), BaseComponent[].class ) ) );
|
||||
component.setWith( Arrays.asList( context.deserialize( object.get( "with" ), BaseComponent[].class ) ) );
|
||||
}
|
||||
if ( object.has( "fallback" ) )
|
||||
{
|
||||
component.setFallback( object.get( "fallback" ).getAsString() );
|
||||
}
|
||||
return component;
|
||||
}
|
||||
@ -43,6 +47,10 @@ public class TranslatableComponentSerializer extends BaseComponentSerializer imp
|
||||
{
|
||||
object.add( "with", context.serialize( src.getWith() ) );
|
||||
}
|
||||
if ( src.getFallback() != null )
|
||||
{
|
||||
object.addProperty( "fallback", src.getFallback() );
|
||||
}
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user