derpatiel.progressivediff.util.TextHelper.java Source code

Java tutorial

Introduction

Here is the source code for derpatiel.progressivediff.util.TextHelper.java

Source

package derpatiel.progressivediff.util;

import net.minecraft.util.text.translation.I18n;
import org.apache.commons.lang3.text.WordUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Taken and adapted from Blood Magic's TextHelper class under the Creative Commons Attribution 4.0 International License
 * (CC BY 4.0)
 * This version initially retrieved 10/2/2016 as git hash b56bbef, committed April 5, 2016 from https://github.com/WayofTime/BloodMagic
 */
public class TextHelper {
    public static String getFormattedText(String string) {
        return string.replaceAll("&", "\u00A7");
    }

    public static String localize(String input, Object... format) {
        return I18n.translateToLocalFormatted(input, format);
    }

    public static String localizeEffect(String input, Object... format) {
        return getFormattedText(localize(input, format));
    }

    public static String[] localizeAll(String[] input) {
        String[] ret = new String[input.length];
        for (int i = 0; i < input.length; i++)
            ret[i] = localize(input[i]);

        return ret;
    }

    public static String[] localizeAllEffect(String[] input) {
        String[] ret = new String[input.length];
        for (int i = 0; i < input.length; i++)
            ret[i] = localizeEffect(input[i]);

        return ret;
    }

    public static ArrayList<String> localizeAll(List<String> input) {
        ArrayList<String> ret = new ArrayList<String>(input.size());
        for (int i = 0; i < input.size(); i++)
            ret.add(i, localize(input.get(i)));

        return ret;
    }

    public static ArrayList<String> localizeAllEffect(List<String> input) {
        ArrayList<String> ret = new ArrayList<String>(input.size());
        for (int i = 0; i < input.size(); i++)
            ret.add(i, localizeEffect(input.get(i)));

        return ret;
    }

    public static String[] cutLongString(String string, int characters) {
        return WordUtils.wrap(string, characters, "/cut", false).split("/cut");
    }

    public static String[] cutLongString(String string) {
        return cutLongString(string, 30);
    }

    public static boolean canTranslate(String key) {
        return I18n.canTranslate(key);
    }
}