Example usage for java.util Locale toString

List of usage examples for java.util Locale toString

Introduction

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

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string representation of this Locale object, consisting of language, country, variant, script, and extensions as below:
language + "_" + country + "_" + (variant + "_#" | "#") + script + "_" + extensions
Language is always lower case, country is always upper case, script is always title case, and extensions are always lower case.

Usage

From source file:org.freeplane.features.format.ScannerController.java

private Scanner createScanner(Locale loc) {
    final Scanner s = new Scanner(new String[] { loc.toString() }, false);
    s.setFirstChars("+-0123456789,.");
    final String tNumber = IFormattedObject.TYPE_NUMBER;
    final String tDate = IFormattedObject.TYPE_DATETIME;
    final DateFormat shortDateTimeFormat = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT,
            DateFormat.SHORT, loc);
    if (shortDateTimeFormat instanceof SimpleDateFormat) {
        s.addParser(Parser.createParser(Parser.STYLE_DATE, tDate,
                ((SimpleDateFormat) shortDateTimeFormat).toPattern(), loc, "short datetime format"));
    }//from w  ww. j ava 2 s .  c o  m
    final DateFormat shortDateFormat = SimpleDateFormat.getDateInstance(DateFormat.SHORT, loc);
    if (shortDateFormat instanceof SimpleDateFormat) {
        s.addParser(Parser.createParser(Parser.STYLE_DATE, tDate,
                ((SimpleDateFormat) shortDateFormat).toPattern(), loc, "short date format"));
    }
    s.addParser(Parser.createParser(Parser.STYLE_DECIMAL, tNumber, null, loc, "number format"));
    s.addParser(
            Parser.createParser(Parser.STYLE_ISODATE, tDate, null, loc, "ISO reader for date and date/time"));
    s.addParser(Parser.createParser(Parser.STYLE_NUMBERLITERAL, tNumber, null, loc,
            "support dot as decimal separator (if nothing else matches)"));
    return s;
}

From source file:org.jahia.bin.Action.java

protected JSONObject getJSONConstraintError(ConstraintViolationException e) throws RepositoryException {
    Map<String, String> m = new HashMap<String, String>();
    m.put("message", e.getMessage());
    if (e instanceof NodeConstraintViolationException) {
        m.put("constraintMessage", ((NodeConstraintViolationException) e).getConstraintMessage());
        Locale locale = ((NodeConstraintViolationException) e).getLocale();
        if (locale != null) {
            m.put("locale", locale.toString());
        }/* w  w w  .j a  v  a2 s . c om*/
        m.put("path", ((NodeConstraintViolationException) e).getPath());
    }
    if (e instanceof PropertyConstraintViolationException) {
        ExtendedPropertyDefinition definition = ((PropertyConstraintViolationException) e).getDefinition();
        m.put("propertyName", definition.getName());
        m.put("propertyLabel",
                definition.getLabel(LocaleContextHolder.getLocale(), definition.getDeclaringNodeType()));
    }
    return new JSONObject(m);
}

From source file:info.magnolia.cms.i18n.AbstractI18nContentSupport.java

protected boolean isLocaleSupported(Locale locale) {
    return locale != null && locales.containsKey(locale.toString());
}

From source file:com.example.locale.MainActivity.java

@Override
public void onLocale(final Locale locale) {
    if (Locale.getDefault().equals(locale)) {
        Toast.makeText(MainActivity.this, getString(R.string.app_widget_set_locale, locale.toString()),
                Toast.LENGTH_SHORT).show();
        return;/*from w w w . j  a  va 2s  .  c o m*/
    }

    mLoading.show();
    mFilter = null;
    Intent intent = new Intent(this, LocaleService.class);
    intent.putExtra(LocaleService.EXTRA_LOCALE, locale);
    startService(intent);
}

From source file:org.kitodo.production.forms.LanguageForm.java

/**
 * The function getSupportedLocales() returns a list of maps, each
 * representing one locale configured in the faces-config.xml file. Each of
 * the maps will contain the fields. id  the locales ID String, e.g. fr?
 * or en_GB? displayLanguageSelf  the name of the language in the language
 * itself, e.g. English?, Deutsch?, franais?, espaol?, ???,
 * ?, /*from  w w w .j  ava 2  s.c  o  m*/
 *
 * <p>
 * Its a good practice to identify a language in its own spelling, since
 * this will be most likely what a speaker of that language will recognize.
 * See also: http://www.cs.tut.fi/~jkorpela/flags.html Note that
 * capitalisation is subject to the respective language. If the language is
 * unknown, the id will be returned. displayLanguageTranslated  the name of
 * the language in the currently selected language, e.g., if the current
 * language is English: English?, German?, French?, 
 * </p>
 *
 * <p>
 * This is just a nice feature because the language names are provided by
 * Java; and its used in the mouse-over titles, so you can find out what
 * e.g. ? means, even if you dont have a clue of the glyphs used. If
 * no translations are available, this will fall back to English. selected 
 * whether this is the current language
 * </p>
 *
 * <p>
 * This can be used for a sophisticated layout.
 * </p>
 *
 * @return a list of maps, each with the fields id?, displayName? and
 *         selected?
 */
public List<Map<String, Object>> getSupportedLocales() {
    List<Map<String, Object>> result = new ArrayList<>();
    Locale currentDisplayLanguage = FacesContext.getCurrentInstance().getViewRoot().getLocale();
    // It seems we have an old Faces API, Faces 2.1s getSupportedLocales()
    // returns Iterator<Locale>
    // TODO: Update JSF API
    Iterator<Locale> localesIterator = FacesContext.getCurrentInstance().getApplication().getSupportedLocales();
    while (localesIterator.hasNext()) {
        Locale supportedLocale = localesIterator.next();
        if (supportedLocale.getLanguage().length() > 0) {
            Map<String, Object> translation = new HashMap<>();
            translation.put("id", supportedLocale.toString());
            translation.put("displayLanguageSelf", supportedLocale.getDisplayLanguage(supportedLocale));
            translation.put("displayLanguageTranslated",
                    supportedLocale.getDisplayLanguage(currentDisplayLanguage));
            translation.put("selected", supportedLocale.equals(currentDisplayLanguage));
            translation.put("flag", "javax.faces.resource/images/" + supportedLocale.toString() + ".svg.jsf");
            result.add(translation);
        }
    }
    return result;
}

From source file:com.balero.models.BlogDAO.java

@Transactional
public void addPost(String postitle, String postbody, String postslug, Locale postlocale, String postauthor,
        String poststatus) {/*  w  w w  .j av  a 2  s. c om*/
    Session session = sessionFactory.openSession();
    Blog Blog = new Blog();
    Blog.setPosttitle(postitle);
    Blog.setPostbody(postbody);
    Blog.setPostslug(postslug);
    Blog.setPostlocale(postlocale.toString());
    Blog.setPostauthor(postauthor);
    Blog.setPoststatus(poststatus);
    session.save(Blog);
    session.flush();
    session.close();
}

From source file:controller.setup.Setup.java

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }, value = "/install")
public ModelAndView install(HttpServletRequest request, HttpServletResponse response) {

    ModelAndView mav = new ModelAndView();
    String step = null;/*from ww w.  j a  v a 2 s.c  om*/

    List<String> steps = new ArrayList<String>();
    steps.add("install");
    steps.add("choixLangue");
    steps.add("precheck");
    steps.add("license");
    steps.add("infosBD");
    steps.add("adminInfos");
    steps.add("installSuccess");

    boolean pass = true;

    if (request.getParameter("step") != null) {
        step = request.getParameter("step");
        mav.addObject("step", step);
    }

    Locale locale = (RequestContextUtils.getLocaleResolver(request)).resolveLocale(request);
    mav.addObject("lang", locale.toString());

    if (request.getParameter("lang") != null) {
        String lang = request.getParameter("lang");
        mav.addObject("lang", lang);
    }

    if ((request.getParameter("precheckServerInfoState") != null
            && request.getParameter("precheckServerInfoState").equals("notOK"))
            || (request.getParameter("precheckServerVersionState") != null
                    && request.getParameter("precheckServerVersionState").equals("notOK"))
            || (request.getParameter("precheckJavaVersionState") != null
                    && request.getParameter("precheckJavaVersionState").equals("notOK"))) {
        pass = false;
        mav.addObject("precheckErrorMsg", "precheckErrorMsg");
    }

    if (request.getParameter("bd") != null) {

        String bd = request.getParameter("bd");
        mav.addObject("bd", bd);

        if ((request.getParameter("bdHost") == null || request.getParameter("bdHost").equals("")
                || request.getParameter("bdUser") == null || request.getParameter("bdUser").equals("")
                || request.getParameter("bdName") == null || request.getParameter("bdName").equals("")
                || request.getParameter("bdPort") == null || request.getParameter("bdPort").equals(""))
                && (step.equals("infosBD")))
            pass = false;

        else {

            String bdUser = request.getParameter("bdUser");
            mav.addObject("bdUser", bdUser);
            String bdHost = request.getParameter("bdHost");
            mav.addObject("bdHost", bdHost);
            String bdPort = request.getParameter("bdPort");
            mav.addObject("bdPort", bdPort);
            String bdName = request.getParameter("bdName");
            mav.addObject("bdName", bdName);
            String bdUserMdp = request.getParameter("bdUserMdp");
            mav.addObject("bdUserMdp", bdUserMdp);

            if (step.equals("infosBD")) {
                updateHibernateCfgFile(bd, bdHost, bdPort, bdName, bdUser, bdUserMdp);
                Session s = HibernateSessionFactory.getSession();
                if (s.isConnected()) {
                    System.out.println("--- Connexion reussie ---");
                    s.close();
                } else
                    System.out.println("--- Connexion echouee ---");
            }
        }

        /*         if (request.getParameter("bdHost")!=null)
                    mav.addObject("bdHost", request.getParameter("bdHost"));
                         
                 if (request.getParameter("bdUser")!=null) 
                    mav.addObject("bdUser", request.getParameter("bdUser"));
                
                 if (request.getParameter("bdUserMdp")!=null)
                    mav.addObject("bdUserMdp", request.getParameter("bdUserMdp"));
        */
    }

    if (request.getParameter("action") != null) {
        //         step = request.getParameter("step");

        if (request.getParameter("action").equals("next") || request.getParameter("action").equals("accept")) {
            step = pass == true ? steps.get(steps.indexOf(step) + 1) : steps.get(steps.indexOf(step));
            //            System.out.println(pass);
        }
        if (request.getParameter("action").equals("previous")) {
            step = steps.get(steps.indexOf(step) - 1);
        }
        if (request.getParameter("action").equals("not_accept")) {
            mav.addObject("erreur_licence", "erreur_licence");
        }
        if (request.getParameter("action").equals("end")) {
            step = steps.get(steps.indexOf(step) + 1);
        }
        mav.addObject("step", step);
    }

    if (request.getParameter("theme") != null) {
        mav.addObject("theme", request.getParameter("theme"));
        System.out.println("---> " + request.getParameter("theme"));
    }

    mav.setViewName("install");
    return mav;
}

From source file:org.apache.jmeter.util.JMeterUtils.java

/**
 * Changes the current locale: re-reads resource strings and notifies
 * listeners./*  w  w  w .jav  a 2 s.c  om*/
 *
 * @param loc -
 *            new locale
 */
public static void setLocale(Locale loc) {
    log.info("Setting Locale to " + loc.toString());
    /*
     * See bug 29920. getBundle() defaults to the property file for the
     * default Locale before it defaults to the base property file, so we
     * need to change the default Locale to ensure the base property file is
     * found.
     */
    Locale def = null;
    boolean isDefault = false; // Are we the default language?
    if (loc.getLanguage().equals(ENGLISH_LANGUAGE)) {
        isDefault = true;
        def = Locale.getDefault();
        // Don't change locale from en_GB to en
        if (!def.getLanguage().equals(ENGLISH_LANGUAGE)) {
            Locale.setDefault(Locale.ENGLISH);
        } else {
            def = null; // no need to reset Locale
        }
    }
    if (loc.toString().equals("ignoreResources")) { // $NON-NLS-1$
        log.warn("Resource bundles will be ignored");
        ignoreResorces = true;
        // Keep existing settings
    } else {
        ignoreResorces = false;
        ResourceBundle resBund = ResourceBundle.getBundle("org.apache.jmeter.resources.messages", loc); // $NON-NLS-1$
        resources = resBund;
        locale = loc;
        final Locale resBundLocale = resBund.getLocale();
        if (isDefault || resBundLocale.equals(loc)) {// language change worked
            // Check if we at least found the correct language:
        } else if (resBundLocale.getLanguage().equals(loc.getLanguage())) {
            log.info("Could not find resources for '" + loc.toString() + "', using '" + resBundLocale.toString()
                    + "'");
        } else {
            log.error("Could not find resources for '" + loc.toString() + "'");
        }
    }
    notifyLocaleChangeListeners();
    /*
     * Reset Locale if necessary so other locales are properly handled
     */
    if (def != null) {
        Locale.setDefault(def);
    }
}

From source file:net.sf.nmedit.nomad.core.NomadLoader.java

private void initLocale() {
    SystemProperties properties = SystemPropertyFactory.getProperties(NomadLoader.class);

    properties.defineStringProperty(NOMAD_CURRENT_LOCALE, null);
    String locale = properties.stringValue(NOMAD_CURRENT_LOCALE);
    if (locale != null) {
        for (Locale l : Locale.getAvailableLocales()) {
            if (locale.equals(l.toString())) {
                LocaleConfiguration conf = LocaleConfiguration.getLocaleConfiguration();
                if (!conf.getCurrentLocale().equals(l))
                    conf.setCurrentLocale(l);

                break;
            }//from  w ww.ja  v  a 2s .  c o  m
        }
    }
}

From source file:org.opencastproject.serviceregistry.remote.IncidentServiceRemoteImpl.java

@Override
public IncidentL10n getLocalization(long id, Locale locale) throws IncidentServiceException, NotFoundException {
    HttpGet get = new HttpGet(
            UrlSupport.concat("localization", Long.toString(id)) + "?locale=" + locale.toString());
    HttpResponse response = getResponse(get, SC_OK);
    try {//from w w  w .  jav  a  2  s  .c o m
        if (response != null) {
            if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
                throw new NotFoundException("No localization found for the job incident with id " + id);
            } else if (SC_OK == response.getStatusLine().getStatusCode()) {
                String json = IOUtils.toString(response.getEntity().getContent(), "UTF-8");
                final JSONObject obj = (JSONObject) JSONValue.parse(json);
                logger.debug(
                        "Successfully received localization from job incident id {} with the locale {} from the remote incident service",
                        id, locale.toString());
                return new IncidentL10n() {
                    @Override
                    public String getTitle() {
                        return (String) obj.get("title");
                    }

                    @Override
                    public String getDescription() {
                        return (String) obj.get("description");
                    }
                };
            }
        }
    } catch (Exception e) {
        throw new IncidentServiceException(
                "Unable to get localization of job incident from remote incident service: " + e);
    } finally {
        closeConnection(response);
    }
    throw new IncidentServiceException(
            "Unable to get localization of job incident from remote incident service");
}