1 package net.sf.openrocket.l10n;
3 import java.util.Locale;
4 import java.util.regex.Pattern;
7 * Helper methods for localization needs.
9 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
11 public final class L10N {
14 // Prevent instantiation
19 * Replace a text token by a replacement value.
21 * A text token is a string portion that should be surrounded by
24 * @param original the original string.
25 * @param token the text token to replace.
26 * @param replacement the replacement text.
27 * @return the modified string.
29 public static String replace(String original, String token, String replacement) {
30 return Pattern.compile(token, Pattern.LITERAL).matcher(original).replaceAll(replacement);
35 * Convert a language code into a Locale.
37 * @param langcode the language code (<code>null</code> ok).
38 * @return the corresponding locale (or <code>null</code> if the input was <code>null</code>)
40 public static Locale toLocale(String langcode) {
41 if (langcode == null) {
46 String[] split = langcode.split("[_-]", 3);
47 if (split.length == 1) {
48 l = new Locale(split[0]);
49 } else if (split.length == 2) {
50 l = new Locale(split[0], split[1]);
52 l = new Locale(split[0], split[1], split[2]);