Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package org.litesoft.servlet;

import org.litesoft.locale.*;

import javax.servlet.http.*;
import org.litesoft.core.typeutils.Objects;
import java.util.*;

public class LocalesFromRequest
{
    public static List<String> getCodes( HttpServletRequest pRequest )
    {
        ArrayList<String> zCodes = new ArrayList<>();
        Enumeration zLocales = pRequest.getLocales();
        while ( zLocales.hasMoreElements() )
        {
            Locale zLocale = (Locale) zLocales.nextElement();
            zCodes.add( AbstractLocale.toCode( zLocale.getLanguage(), zLocale.getCountry() ) );
        }
        return zCodes;
    }

//    private Properties supportedLanguages;
//    private Locale requestLocale = (Locale) supportedLanguages.get("DEFAULT");
//
//    public LousyServlet() {
//        supportedLanguages = new Properties();
//        // Just for demonstration of the concept
//        // you would probably load it from i.e. XML
//        supportedLanguages.put("DEFAULT", Locale.US);
//        // example mapping of "de" to "de_DE"
//        supportedLanguages.put("de-DEFAULT", Locale.GERMANY);
//        supportedLanguages.put("de_AT", new Locale("de", "AT"));
//        supportedLanguages.put("de_CH", new Locale("de", "CH"));
//        supportedLanguages.put("ja_JP", Locale.JAPAN);
//    }
//
//  private void detectLocale(HttpServletRequest request) {
//        Enumeration locales = request.getLocales();
//        while (locales.hasMoreElements()) {
//            Locale locale = (Locale) locales.nextElement();
//            if (supportedLanguages.contains(locale)) {
//                requestLocale = locale;
//                break;
//            }
//        }
//    }
//
//    public String getLanguage() {
//        // get English name of the language
//        // For native call requestLocale.getDisplayName(requestLocale)
//        return requestLocale.getDisplayLanguage();
//    }
}

Commits for litesoft/trunk/DeviceDesktopTest/src/org/litesoft/servlet/LocalesFromRequest.java

Diff revisions: vs.
Revision Author Commited Message
939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

935 Diff Diff GeorgeS picture GeorgeS Fri 30 May, 2014 20:28:08 +0000

Reformatted.

931 GeorgeS picture GeorgeS Tue 01 Apr, 2014 20:11:20 +0000

Locale Support.