List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:es.pode.visualizador.presentacion.agregaSlider.AgregaSliderControllerImpl.java
/** * Metodo que carga los idiomas que van a aparecer en el combo de idiomas de la pantalla * de keywords/*from ww w. j a v a2 s . c om*/ */ public final void cargarIdioma(org.apache.struts.action.ActionMapping mapping, es.pode.visualizador.presentacion.agregaSlider.CargarIdiomaForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception { I18n i18n = I18n.getInstance(); //Recogemos el idioma por defecto para mostrar en ese idioma la lista desplegable de idiomas Locale locale = (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE); //recogemos un array de objetos con la lista de idiomas LocalizacionIdiomaVO[] localizacionArray = i18n.obtenerIdiomasBuscablesLocalizados(locale.getLanguage()); //sacamos los idiomas del array de objetos y lo asignamos al combo form.setIdiomasComboBackingList(Arrays.asList(localizacionArray), "idLocalizacion", "name"); }
From source file:com.android.googlesearch.SuggestionProvider.java
/** * Queries for a given search term and returns a cursor containing * suggestions ordered by best match./*from w w w. j a v a2 s . c o m*/ */ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { String query = selectionArgs[0]; if (TextUtils.isEmpty(query)) { return null; } if (!isNetworkConnected()) { Log.i(LOG_TAG, "Not connected to network."); return null; } try { query = URLEncoder.encode(query, "UTF-8"); // NOTE: This code uses resources to optionally select the search Uri, based on the // MCC value from the SIM. iThe default string will most likely be fine. It is // paramerterized to accept info from the Locale, the language code is the first // parameter (%1$s) and the country code is the second (%2$s). This code *must* // function in the same way as a similar lookup in // com.android.browser.BrowserActivity#onCreate(). If you change // either of these functions, change them both. (The same is true for the underlying // resource strings, which are stored in mcc-specific xml files.) if (mSuggestUri == null) { Locale l = Locale.getDefault(); String language = l.getLanguage(); String country = l.getCountry().toLowerCase(); // Chinese and Portuguese have two langauge variants. if ("zh".equals(language)) { if ("cn".equals(country)) { language = "zh-CN"; } else if ("tw".equals(country)) { language = "zh-TW"; } } else if ("pt".equals(language)) { if ("br".equals(country)) { language = "pt-BR"; } else if ("pt".equals(country)) { language = "pt-PT"; } } mSuggestUri = getContext().getResources().getString(R.string.google_suggest_base, language, country) + "json=true&q="; } HttpPost method = new HttpPost(mSuggestUri + query); StringEntity content = new StringEntity(""); method.setEntity(content); HttpResponse response = mHttpClient.execute(method); if (response.getStatusLine().getStatusCode() == 200) { /* Goto http://www.google.com/complete/search?json=true&q=foo * to see what the data format looks like. It's basically a json * array containing 4 other arrays. We only care about the middle * 2 which contain the suggestions and their popularity. */ JSONArray results = new JSONArray(EntityUtils.toString(response.getEntity())); JSONArray suggestions = results.getJSONArray(1); JSONArray popularity = results.getJSONArray(2); return new SuggestionsCursor(suggestions, popularity); } } catch (UnsupportedEncodingException e) { Log.w(LOG_TAG, "Error", e); } catch (IOException e) { Log.w(LOG_TAG, "Error", e); } catch (JSONException e) { Log.w(LOG_TAG, "Error", e); } return null; }
From source file:edu.ku.brc.af.core.SchemaI18NService.java
/** * Creates a menu with the locate and a property listener. A property event is sent with the property * name set to "locale" with the current locale passed as the old value and the new locale as the new value. * @param frame the frame is passed in so the property listner can push and pop the frame before and after the listener is called. * @return the menu/*from w ww . java 2 s . c o m*/ */ public JMenu createLocaleMenu(final JFrame frame, final PropertyChangeListener pcl) { JMenu localeMenu = createLocaleMenu(new ActionListener() { public void actionPerformed(ActionEvent e) { List<LocaleDlgItem> dlgItems = new ArrayList<LocaleDlgItem>(); for (Locale l : getStdLocaleList(true)) { if (!l.getLanguage().equals("-")) { dlgItems.add(new LocaleDlgItem(l)); } } ChooseFromListDlg<LocaleDlgItem> localeDlg = new ChooseFromListDlg<LocaleDlgItem>(frame, "Choose a Locale", dlgItems); UIHelper.centerAndShow(localeDlg); LocaleDlgItem selected = localeDlg.getSelectedObject(); if (!localeDlg.isCancelled() && selected != null) { Locale newLocale = selected.getLocale(); checkCurrentLocaleMenu(); UIRegistry.pushWindow(frame); pcl.propertyChange(new PropertyChangeEvent(this, "locale", currentLocale, newLocale)); //$NON-NLS-1$ UIRegistry.popWindow(frame); } } }); checkCurrentLocaleMenu(); return localeMenu; }
From source file:com.github.mrstampy.gameboot.messages.context.GameBootContextLookup.java
@Override public ResponseContext lookup(Integer code, Locale locale, Object... parameters) { if (locale == null) { log.warn("Null locale, using root"); return lookup(code); }//from w w w . j a va2 s .c o m if (isNotEmpty(locale.getCountry())) { String suffix = "_" + locale.getLanguage() + "_" + locale.getCountry(); Map<Integer, ResponseContext> map = getForLocale(suffix); if (map != null && map.containsKey(code)) return lookup(code, suffix, map, parameters); } String suffix = "_" + locale.getLanguage(); Map<Integer, ResponseContext> map = getForLocale(suffix); if (map != null && map.containsKey(code)) return lookup(code, suffix, map, parameters); return lookup(code, parameters); }
From source file:com.qcadoo.view.internal.controllers.LoginController.java
@RequestMapping(value = "browserNotSupported", method = RequestMethod.GET) public ModelAndView getBrowserNotSupportedView(final Locale locale) { ModelAndView mav = new ModelAndView(); viewParametersAppender.appendCommonViewObjects(mav); mav.setViewName("qcadooView/browserNotSupported"); mav.addObject("locales", translationService.getLocales()); mav.addObject("currentLanguage", locale.getLanguage()); mav.addObject("translation", translationService.getMessagesGroup("browserNotSupported", locale)); return mav;// ww w . jav a 2s . c o m }
From source file:de.micromata.genome.gwiki.page.impl.wiki.macros.GWikiHelpLinkMacro.java
/** * Gets the lang.// www. j a va 2s . c o m * * @param ctx the ctx * @param ei the ei * @return the lang */ public String getLang(GWikiContext ctx, GWikiElementInfo ei) { if (lang != null) { return lang; } String pageLang = ei.getLang(ctx); if (pageLang != null) { return pageLang; } Locale loc = ctx.getWikiWeb().getAuthorization().getCurrentUserLocale(ctx); if (loc != null) { return loc.getLanguage(); } return null; }
From source file:com.wisemapping.ncontroller.MindmapController.java
@RequestMapping(value = "maps/") public String showListPage(@NotNull Model model) { final Locale locale = LocaleContextHolder.getLocale(); // @Todo: This should be more flexible ... String localeStr = locale.toString().toLowerCase(); if ("es".equals(locale.getLanguage()) || "pt".equals(locale.getLanguage())) { localeStr = locale.getLanguage(); }//from w w w . j a v a2 s . c o m model.addAttribute("locale", localeStr); return "mindmapList"; }
From source file:arena.translation.LocaleInModelInterceptor.java
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { super.postHandle(request, response, handler, modelAndView); if (modelAndView != null) { Locale locale = this.localeResolver.resolveLocale(request); if (this.countryCodeParamName != null) { modelAndView.addObject(this.countryCodeParamName, locale.getCountry()); }/*from w ww . ja v a 2 s . c om*/ if (this.languageCodeParamName != null) { modelAndView.addObject(this.languageCodeParamName, locale.getLanguage()); } if (this.localeParamName != null) { modelAndView.addObject(this.localeParamName, locale); } } }
From source file:net.rrm.ehour.ui.admin.config.MainConfigBackingBean.java
@SuppressWarnings("UnusedDeclaration") public List<Locale> getAvailableLanguages() { Locale[] locales = Locale.getAvailableLocales(); Map<String, Locale> localeMap = new HashMap<>(); // remove all variants for (Locale locale : locales) { if (isTranslationsOnly() && !ArrayUtils.contains(config.getAvailableTranslations(), locale.getLanguage())) { continue; }/*from w w w .ja v a 2 s. c om*/ if (localeMap.containsKey(locale.getLanguage()) && locale.getDisplayName().indexOf('(') != -1) { continue; } localeMap.put(locale.getLanguage(), locale); } SortedSet<Locale> localeSet = new TreeSet<>(new LocaleComparator(LocaleComparator.CompareType.LANGUAGE)); for (Locale locale : localeMap.values()) { localeSet.add(locale); } return new ArrayList<>(localeSet); }
From source file:com.qcadoo.view.internal.controllers.PasswordResetController.java
@RequestMapping(value = "passwordReset", method = RequestMethod.GET) public ModelAndView getForgotPasswordFormView( @RequestParam(required = false, defaultValue = FALSE) final Boolean iframe, @RequestParam(required = false, defaultValue = FALSE) final Boolean popup, final Locale locale) { ModelAndView mav = new ModelAndView(); viewParametersAppender.appendCommonViewObjects(mav); mav.setViewName("qcadooView/passwordReset"); mav.addObject("translation", translationService.getMessagesGroup("security", locale)); mav.addObject("currentLanguage", locale.getLanguage()); mav.addObject("locales", translationService.getLocales()); mav.addObject("iframe", iframe); mav.addObject("popup", popup); return mav;//from ww w .j a va 2s .c o m }