Example usage for java.util Locale Locale

List of usage examples for java.util Locale Locale

Introduction

In this page you can find the example usage for java.util Locale Locale.

Prototype

public Locale(String language, String country) 

Source Link

Document

Construct a locale from language and country.

Usage

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain; charset=Shift_JIS");
    PrintWriter out = res.getWriter();
    res.setHeader("Content-Language", "ja");

    Locale locale = new Locale("ja", "");
    DateFormat full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    out.println("In Japanese:");

    try {//from   ww w  .  ja va  2 s.  c  o m
        FileInputStream fis = new FileInputStream(req.getRealPath("/HelloWorld.ISO-2022-JP"));
        InputStreamReader isr = new InputStreamReader(fis, "ISO-2022-JP");
        BufferedReader reader = new BufferedReader(isr);
        String line = null;
        while ((line = reader.readLine()) != null) {
            out.println(line);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    out.println(full.format(new Date()));
}

From source file:JavaSort.java

public JavaSort() {
    Vector list = new Vector();
    list.add("\u00e4pple");
    list.add("banan");
    list.add("p\u00e4ron");
    list.add("orange");

    // Obtain a Swedish collator
    Collator collate = Collator.getInstance(new Locale("sv", ""));
    Collections.sort(list, collate);

    StringBuffer result = new StringBuffer();
    for (int i = 0; i < list.size(); i++) {
        result.append(list.elementAt(i));
        result.append(" ");
    }/* w  ww  . j a  va2s  . c o  m*/
    add(new JLabel(result.toString()));
}

From source file:Main.java

/**
 * Same as toLocale(), but return null when it cannot derive a valid Locale object.
 * /*from  w  w w .  j  a va 2 s .  com*/
 * @param str
 * @return 
 */
public static Locale deriveLocale(String str) {
    if (str == null) {
        return null;
    }
    int len = str.length();
    if (len != 2 && len != 5 && len < 7) {
        return null;
    }
    char ch0 = str.charAt(0);
    char ch1 = str.charAt(1);
    if (ch0 < 'a' || ch0 > 'z' || ch1 < 'a' || ch1 > 'z') {
        return null;
    }
    if (len == 2) {
        return new Locale(str, "");
    } else {
        if (str.charAt(2) != '_') {
            return null;
        }
        char ch3 = str.charAt(3);
        if (ch3 == '_') {
            return new Locale(str.substring(0, 2), "", str.substring(4));
        }
        char ch4 = str.charAt(4);
        if (ch3 < 'A' || ch3 > 'Z' || ch4 < 'A' || ch4 > 'Z') {
            return null;
        }
        if (len == 5) {
            return new Locale(str.substring(0, 2), str.substring(3, 5));
        } else {
            if (str.charAt(5) != '_') {
                return null;
            }
            return new Locale(str.substring(0, 2), str.substring(3, 5), str.substring(6));
        }
    }
}

From source file:Main.java

public Main() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JLabel jl = new JLabel("Try with formatted text field   ");
    Locale local1 = new Locale("en", "US");
    int minFra = 0;
    int maxFra = 3;
    jft = setFormat(jft, local1, minFra, maxFra);
    jft.setMaximumSize(new Dimension(100, 20));
    jft.setMinimumSize(new Dimension(100, 20));
    jft.setPreferredSize(new Dimension(100, 20));

    frame.add(jl);//from  w w w  . j a  va  2s  . c o  m
    frame.add(jft, BorderLayout.NORTH);
    jb.addActionListener(e -> JOptionPane.showMessageDialog(jb, "nel text Box : " + jft.getText()));
    frame.pack();
    frame.setVisible(true);
}

From source file:com.pamarin.income.controller.DateFormat.java

public String format(Date date, String pattern) {
    Format format = new SimpleDateFormat(pattern, new Locale("th", "TH"));
    return format.format(date);
}

From source file:HelloJapan.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain; charset=Shift_JIS");
    PrintWriter out = res.getWriter();
    res.setHeader("Content-Language", "ja");

    Locale locale = new Locale("ja", "");
    DateFormat full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
    out.println("In Japanese:");
    out.println("\u4eca\u65e5\u306f\u4e16\u754c"); // Hello World
    out.println(full.format(new Date()));
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    Locale locale;/*from w  ww .  ja  v  a2s  .  c o m*/
    DateFormat full;

    try {
        res.setContentType("text/plain; charset=UTF-8");
        //PrintWriter out = res.getWriter();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(res.getOutputStream(), "UTF8"), true);

        locale = new Locale("en", "US");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("In English appropriate for the US:");
        out.println("Hello World!");
        out.println(full.format(new Date()));
        out.println();

        locale = new Locale("es", "");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("En Espa\u00f1ol:");
        out.println("\u00a1Hola Mundo!");
        out.println(full.format(new Date()));
        out.println();

        locale = new Locale("ja", "");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("In Japanese:");
        out.println("\u4eca\u65e5\u306f\u4e16\u754c");
        out.println(full.format(new Date()));
        out.println();

        locale = new Locale("zh", "");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("In Chinese:");
        out.println("\u4f60\u597d\u4e16\u754c");
        out.println(full.format(new Date()));
        out.println();

        locale = new Locale("ko", "");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("In Korean:");
        out.println("\uc548\ub155\ud558\uc138\uc694\uc138\uacc4");
        out.println(full.format(new Date()));
        out.println();

        locale = new Locale("ru", "");
        full = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
        out.println("In Russian (Cyrillic):");
        out.print("\u0417\u0434\u0440\u0430\u0432\u0441\u0442");
        out.println("\u0432\u0443\u0439, \u041c\u0438\u0440");
        out.println(full.format(new Date()));
        out.println();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.sf.zekr.engine.audio.RecitationPackConverter.java

public static AudioData convert(File oldRecitationPack) throws IOException, ConfigurationException {
    PropertiesConfiguration props = ConfigUtils.loadConfig(oldRecitationPack, "UTF-8");
    AudioData ad = new AudioData();
    ad.id = props.getString("audio.id");
    if (StringUtils.isBlank(ad.id)) {
        logger.debug("audio.id cannot be null or empty");
        return null;
    }//w ww. jav  a  2s . co  m
    ad.id += "-converted";

    ad.version = "0.7.5";
    ad.lastUpdate = props.getString("audio.lastUpdate");
    ad.quality = "?";

    ad.name = props.getString("audio.name");
    if (StringUtils.isBlank(ad.id)) {
        logger.debug("audio.name cannot be null or empty");
        return null;
    }
    ad.name += " (converted)";

    ad.license = props.getString("audio.license");
    ad.locale = new Locale(props.getString("audio.language"), props.getString("audio.country"));

    String fileName = props.getString("audio.fileName");
    fileName = StringUtils.replace(fileName, "{SURA}", "%1$03d");
    fileName = StringUtils.replace(fileName, "{AYA}", "%2$03d");

    String baseUrl = props.getString("audio.baseUrl");
    if (StringUtils.isBlank(baseUrl)) {
        logger.debug("audio.baseUrl cannot be null or empty");
        return null;
    }
    baseUrl = StringUtils.replace(baseUrl, "%", "%%");

    String path;
    if (props.containsKey("audio.serverUrl")) {
        ad.type = "online";
        String serverUrl = props.getString("audio.serverUrl");
        path = serverUrl + "/" + baseUrl + "/";
        ad.onlineUrl = path + fileName;

        if (props.containsKey("audio.prestartFileName")) {
            ad.onlineAudhubillah = path + props.getString("audio.prestartFileName");
        }
        if (props.containsKey("audio.startFileName")) {
            ad.onlineBismillah = path + props.getString("audio.startFileName");
        }
        if (props.containsKey("audio.endFileName")) {
            ad.onlineSadaghallah = path + props.getString("audio.endFileName");
        }
    } else {
        ad.type = "offline";

        baseUrl = StringUtils.replace(baseUrl, "[base]", "<base>");
        baseUrl = StringUtils.replace(baseUrl, "[workspace]", "<workspace>");
        baseUrl = StringUtils.replace(baseUrl, "[w_b]", "<workspace_base>");

        path = baseUrl + "/";
        ad.offlineUrl = path + fileName;

        if (props.containsKey("audio.prestartFileName")) {
            ad.offlineAudhubillah = path + props.getString("audio.prestartFileName");
        }
        if (props.containsKey("audio.startFileName")) {
            ad.offlineBismillah = path + props.getString("audio.startFileName");
        }
        if (props.containsKey("audio.endFileName")) {
            ad.offlineSadaghallah = path + props.getString("audio.endFileName");
        }
    }

    return ad;
}

From source file:CollatorDemo.java

public static void testCompare() {

    Collator myCollator = Collator.getInstance(new Locale("en", "US"));

    System.out.println(myCollator.compare("abc", "def"));
    System.out.println(myCollator.compare("rtf", "rtf"));
    System.out.println(myCollator.compare("xyz", "abc"));
}

From source file:SimpleInputMethod.java

public SimpleInputMethod() {
    locale = new Locale("iw", "IL");
}