List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:jease.cms.web.servlet.JeaseController.java
public void init(FilterConfig config) throws ServletException { contextPath = config.getServletContext().getContextPath(); dispatcher = config.getServletContext().getInitParameter(Names.JEASE_SITE_DISPATCHER); servlets = Pattern.compile(/*from w w w. ja v a 2 s . c o m*/ String.format("/(%s).*", config.getServletContext().getInitParameter(Names.JEASE_SITE_SERVLETS))); locales = new HashSet<>(); for (Locale locale : Locale.getAvailableLocales()) { locales.add(locale.getLanguage()); } }
From source file:de.sub.goobi.forms.SpracheForm.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 ww . j a v a2s.co 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(); @SuppressWarnings("unchecked") // 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", Boolean.valueOf(supportedLocale.equals(currentDisplayLanguage))); result.add(translation); } } return result; }
From source file:de.gesundkrank.wikipedia.hadoop.io.WikiDumpLoader.java
/** * Adds inputpath to a given hadoop job/*w w w . j ava2 s. c o m*/ * * @param job hadoop job * @param basePathStr * @param locale Language of the wikidump * @throws java.io.IOException */ public void addWikiDump(Job job, String basePathStr, Locale locale) throws IOException { Path basePath = new Path(basePathStr, locale.getLanguage()); FileSystem fs = FileSystem.get(job.getConfiguration()); FileStatus latestLocalDumpStatus = checkLocalDumps(fs, basePath); Path latestDump = null; if (latestLocalDumpStatus != null) { latestDump = latestLocalDumpStatus.getPath(); } else { logger.info("Could not find a valid dump. Loading new version."); } if (checkNew || latestDump == null) { long latestDumpTime = checkNewDump(locale); if (latestLocalDumpStatus == null || latestDumpTime > latestLocalDumpStatus.getModificationTime()) { latestDump = loadNewDump(fs, basePath, latestDumpTime, locale); } else { throw new IOException("failed to get latest dump"); } } FileInputFormat.addInputPath(job, latestDump); }
From source file:org.esco.web.servlet.ServerNameLocaleResolverAdaptor.java
@Override public void setLocale(final HttpServletRequest request, final HttpServletResponse response, final Locale locale) { // Add the server name variant to the locale final String serverName = request.getServerName(); Locale variantLocale = new Locale(locale.getLanguage(), locale.getCountry(), serverName); request.setAttribute(LOCALE_ATTRIBUTE_KEY, variantLocale); if (this.storeLocaleInSession) { // Store the locale in session request.getSession().setAttribute(LOCALE_ATTRIBUTE_KEY, variantLocale); }/*from ww w. j a v a2 s .com*/ }
From source file:org.iti.agrimarket.view.UserController.java
@RequestMapping(value = { "/getUser.htm" }) public String getUser(@RequestParam(value = "id", required = true) int offerId, Locale locale, Model model) { User user = null;//from w ww . j av a 2 s . com String language = locale.getLanguage(); System.out.println("id@@@@@@@@@@@@@@@@@@" + offerId); user = userService.getUserEager(offerId); // for (Object col : user.getUserOfferProductFixeds()) { // UserOfferProductFixed fixed = (UserOfferProductFixed) col; // System.out.println("user offer product fixed" + fixed.getId()); // } if (user != null) { model.addAttribute("userHasOffer", user); } model.addAttribute("lang", locale); return "view_user"; }
From source file:griffon.plugins.i18n.ExtendedResourceBundleMessageSource.java
@Override protected ResourceBundle doGetBundle(String basename, Locale locale) throws MissingResourceException { resolver();//w w w.ja v a2s.c o m List<ResourceBundle> bundles = new ArrayList<ResourceBundle>(); bundles.addAll(loadBundleForFilename(basename + "_" + locale.getLanguage() + "_" + locale.getCountry())); bundles.addAll(loadBundleForFilename(basename + "_" + locale.getLanguage())); bundles.addAll(loadBundleForFilename(basename)); return new CompositeResourceBundle(bundles.toArray(new ResourceBundle[bundles.size()])); }
From source file:be.fedict.trust.service.bean.ConfigurationServiceBean.java
/** * {@inheritDoc}/*from w ww .j a va2 s . c om*/ */ public String findText(String key, Locale locale) { LOG.debug("find text for key=" + key + " language=" + locale.getLanguage()); LocalizationKeyEntity localizationKey = this.localizationDAO.findLocalization(key); for (LocalizationTextEntity text : localizationKey.getTexts()) { if (text.getLanguage().equals(locale.getLanguage())) { return text.getText(); } } return null; }
From source file:de.cosmocode.palava.model.geoplanet.Place.java
/** * Retrieve the preferredAlias for a specified locale. * //from www . j ava2s .co m * @param locale the target locale * @return a preferred alias of this place for the given locale * @throws NoSuchElementException if there is no preferred alias for * the given locale */ public Alias getPreferredAlias(final Locale locale) { final String language = locale.getLanguage(); return Iterables.find(getAliases(), new Predicate<Alias>() { @Override public boolean apply(Alias input) { if (input.getNameType() == NameType.Q) { return StringUtils.equals(input.getLanguageCode(), language); } else { return false; } } }); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.externalServices.AnnouncementBoardExport.java
private boolean hasLanguage(Collection<Locale> allLocales, Locale language) { for (Locale locale : allLocales) { if (locale.getLanguage().equals(language.getLanguage())) { return true; }/*w ww.j av a 2 s.c o m*/ } return false; }
From source file:com.haulmont.chile.core.datatypes.Datatypes.java
private FormatStrings getFormat(Locale locale) { if (useLocaleLanguageOnly) locale = Locale.forLanguageTag(locale.getLanguage()); return formatStringsMap.get(locale); }