use of org.lanternpowered.server.text.translation.MinecraftTranslation in project LanternServer by LanternPowered.
the class JsonTextTranslatableSerializer method serialize.
@SuppressWarnings("deprecation")
@Override
public JsonElement serialize(TranslatableText src, Type typeOfSrc, JsonSerializationContext context) {
final Translation translation = src.getTranslation();
if (this.networkingFormat && !(translation instanceof MinecraftTranslation)) {
final ImmutableList<Object> arguments = src.getArguments();
final Object[] rawArguments = arguments.toArray(new Object[arguments.size()]);
final Locale locale = currentLocale.get();
for (int i = 0; i < rawArguments.length; i++) {
Object object = rawArguments[i];
if (object instanceof TextRepresentable) {
if (!(object instanceof Text)) {
object = ((TextRepresentable) object).toText();
}
rawArguments[i] = ((LanternTextSerializer) TextSerializers.LEGACY_FORMATTING_CODE).serialize((Text) object, locale);
} else {
rawArguments[i] = object.toString();
}
}
final String content = src.getTranslation().get(locale, rawArguments);
return JsonTextLiteralSerializer.serializeLiteralText(src, content, context, this.removeComplexity);
}
final JsonObject obj = new JsonObject();
obj.addProperty(TRANSLATABLE, src.getTranslation().getId());
final ImmutableList<Object> arguments = src.getArguments();
if (!arguments.isEmpty()) {
final JsonArray argumentsArray = new JsonArray();
for (Object object : arguments) {
// so we need to convert the objects if possible
if (object instanceof TextRepresentable) {
if (!(object instanceof Text)) {
object = ((TextRepresentable) object).toText();
}
argumentsArray.add(context.serialize(object, Text.class));
} else {
argumentsArray.add(new JsonPrimitive(object.toString()));
}
}
obj.add(TRANSLATABLE_ARGS, argumentsArray);
}
serialize(obj, src, context);
return obj;
}
Aggregations