String -> l33t Bundle

In case you are translating your game to different languages using resource bundles, here’s one that you don’t want to miss. ;D ;D ;D

To translate any language to l33t use:


public ResourceBundle createL33tBundle(ResourceBundle originalBundle) {
  return new L33tBundle(originalBundle)
}


import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * L33t Type resource bundle.
 *
 * @author  Christoph Aschwanden
 * @since  December 28, 2006
 */
public class L33tBundle extends ResourceBundle {

  /** The original resource bundle for localization. */
  private ResourceBundle resourceBundle;
 
 
  /**
   * L33t bundle.
   *
   * @param resourceBundle  The bundle.
   */
  public L33tBundle(ResourceBundle resourceBundle) {
    this.resourceBundle = resourceBundle;
  }
 
  /**
   * Converts regular text to l33t.
   *
   * @param text  The original text.
   * @return  The l33t text.
   */
  public String text2l33t(String text) {
    StringBuilder leet = new StringBuilder();
   
    // Translate normal text
    for(int i = 0; i < text.length(); i++) {
      char c = text.charAt(i);
     
      if (c == 'a' || c == 'A') {
        leet.append("@");
      }
      else if (c == 'b' || c == 'B') {
        leet.append("8");
      }
      else if (c == 'c' || c == 'C') {
        leet.append("[");
      }
      else if (c == 'd' || c == 'D') {
        leet.append("[)");
      }
      else if (c == 'e' || c == 'E') {
        leet.append("3");
      }
      else if (c == 'f' || c == 'F') {
        leet.append("|=");
      }
      else if (c == 'g' || c == 'G') {
        leet.append("6");
      }
      else if (c == 'h' || c == 'H') {
        leet.append("#");
      }
      else if (c == 'i' || c == 'I') {
        leet.append("!");
      }
      else if (c == 'j' || c == 'J') {
        leet.append(";");
      }
      else if (c == 'k' || c == 'K') {
        leet.append("|<");
      }
      else if (c == 'l' || c == 'L') {
        leet.append("1");
      }
      else if (c == 'm' || c == 'M') {
        leet.append("^^");
      }
      else if (c == 'n' || c == 'N') {
        leet.append("N");
      }
      else if (c == 'o' || c == 'O') {
        leet.append("0");
      }
      else if (c == 'p' || c == 'P') {
        leet.append("P");
      }
      else if (c == 'q' || c == 'Q') {
        leet.append("9");
      }
      else if (c == 'r' || c == 'R') {
        leet.append("|2");
      }
      else if (c == 's' || c == 'S') {
        leet.append("5");
      }
      else if (c == 't' || c == 'T') {
        leet.append("7");
      }
      else if (c == 'u' || c == 'U') {
        leet.append("|_|");
      }
      else if (c == 'v' || c == 'V') {
        leet.append("V");
      }
      else if (c == 'w' || c == 'W') {
        leet.append("W");
      }
      else if (c == 'x' || c == 'X') {
        leet.append("><");
      }
      else if (c == 'y' || c == 'Y') {
        leet.append("%");
      }
      else if (c == 'z' || c == 'Z') {
        leet.append("2");
      }
      else {
        leet.append(c);
      }
    }   
    return leet.toString();
  }

  /**
   * Returns the keys.
   *
   * @return  The keys.
   */
  public Enumeration<String> getKeys() {
    return resourceBundle.getKeys();
  }

  /**
   * Returns the locale.
   *
   * @return  The locale.
   */
  public Locale getLocale() {
    return resourceBundle.getLocale();
  }

  /**
   * Returns the translated object.
   *
   * @param arg0  The key.
   * @return  The translated object.
   */
  protected Object handleGetObject(String arg0) {
    Object object = resourceBundle.getObject(arg0);
    if (object instanceof String) {
      return text2l33t((String)object);
    }
    else {
      return object;
    }
  }
} 

‘N’ is “||”

one word: regex.