List of usage examples for java.util Locale getISOLanguages
public static String[] getISOLanguages()
From source file:org.entrystore.repository.impl.converters.OAI_DC2RDFGraphConverter.java
private String getISO2Language(String iso3Language) { if (localeMap == null) { String[] languages = Locale.getISOLanguages(); localeMap = new HashMap<String, Locale>(languages.length); for (String language : languages) { Locale locale = new Locale(language); localeMap.put(locale.getISO3Language(), locale); }//from w w w .j a v a 2s. c o m } Locale locale = localeMap.get(iso3Language); if (locale != null) { return locale.getLanguage(); } return null; }
From source file:org.mifosplatform.infrastructure.core.serialization.JsonParserHelper.java
private static Locale localeFrom(final String languageCode, final String courntryCode, final String variantCode) { final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>(); final List<String> allowedLanguages = Arrays.asList(Locale.getISOLanguages()); if (!allowedLanguages.contains(languageCode.toLowerCase())) { final ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.locale.format", "The parameter locale has an invalid language value " + languageCode + " .", "locale", languageCode);//w w w . j a v a 2 s .c om dataValidationErrors.add(error); } if (StringUtils.isNotBlank(courntryCode.toUpperCase())) { final List<String> allowedCountries = Arrays.asList(Locale.getISOCountries()); if (!allowedCountries.contains(courntryCode)) { final ApiParameterError error = ApiParameterError.parameterError( "validation.msg.invalid.locale.format", "The parameter locale has an invalid country value " + courntryCode + " .", "locale", courntryCode); dataValidationErrors.add(error); } } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } return new Locale(languageCode.toLowerCase(), courntryCode.toUpperCase(), variantCode); }
From source file:org.obiba.onyx.quartz.editor.questionnaire.QuestionnairePanel.java
public QuestionnairePanel(String id, final IModel<Questionnaire> model, boolean newQuestionnaire) { super(id, model); final Questionnaire questionnaire = model.getObject(); add(CSSPackageResource.getHeaderContribution(QuestionnairePanel.class, "QuestionnairePanel.css")); feedbackPanel = new FeedbackPanel("content"); feedbackWindow = new FeedbackWindow("feedback"); feedbackWindow.setOutputMarkupId(true); add(feedbackWindow);//from w ww . j a va2 s. co m Form<Questionnaire> form = new Form<Questionnaire>("form", model); add(form); TextField<String> name = new TextField<String>("name", new PropertyModel<String>(form.getModel(), "name")); name.setLabel(new ResourceModel("Name")); name.setEnabled(newQuestionnaire); name.add(new RequiredFormFieldBehavior()); name.add(new PatternValidator(QuartzEditorPanel.ELEMENT_NAME_PATTERN)); name.add(new AbstractValidator<String>() { @Override protected void onValidate(final IValidatable<String> validatable) { boolean isNewName = Iterables.all(questionnaireBundleManager.bundles(), new Predicate<QuestionnaireBundle>() { @Override public boolean apply(QuestionnaireBundle input) { return !input.getName().equals(validatable.getValue()); } }); if (!isNewName && !validatable.getValue().equals(questionnaire.getName())) { error(validatable, "NameAlreadyExist"); } } }); form.add(name).add(new SimpleFormComponentLabel("nameLabel", name)) .add(new HelpTooltipPanel("nameHelp", new ResourceModel("Name.Tooltip"))); TextField<String> version = new TextField<String>("version", new PropertyModel<String>(form.getModel(), "version")); version.setLabel(new ResourceModel("Version")); version.add(new RequiredFormFieldBehavior()); form.add(version).add(new SimpleFormComponentLabel("versionLabel", version)); CheckBox commentable = new CheckBox("commentable", new PropertyModel<Boolean>(questionnaire, "commentable")); commentable.setLabel(new ResourceModel("Commentable")); form.add(commentable); form.add(new SimpleFormComponentLabel("commentableLabel", commentable)); form.add(new HelpTooltipPanel("commentableHelp", new ResourceModel("Commentable.Tooltip"))); QuestionnaireFinder.getInstance(questionnaire).buildQuestionnaireCache(); guessUIType(questionnaire); RadioGroup<String> uiType = new RadioGroup<String>("uiType", new PropertyModel<String>(form.getModel(), "uiType")); uiType.setLabel(new ResourceModel("UIType")); uiType.setRequired(true); form.add(uiType); Radio<String> standardUiType = new Radio<String>("standard", new Model<String>(Questionnaire.STANDARD_UI)); standardUiType.setLabel(new ResourceModel("UIType.standard")); uiType.add(standardUiType).add(new SimpleFormComponentLabel("standardLabel", standardUiType)); Radio<String> simplifiedUiType = new Radio<String>("simplified", new Model<String>(Questionnaire.SIMPLIFIED_UI)); simplifiedUiType.setLabel(new ResourceModel("UIType.simplified")); uiType.add(simplifiedUiType).add(new SimpleFormComponentLabel("simplifiedLabel", simplifiedUiType)); form.add(new HelpTooltipPanel("uiHelp", new ResourceModel("UIType.Tooltip"))); form.add(new HelpTooltipPanel("labelsHelp", new ResourceModel("LanguagesProperties.Tooltip"))); Map<String, IModel<String>> labelsTooltips = new HashMap<String, IModel<String>>(); labelsTooltips.put("label", new ResourceModel("Questionnaire.Tooltip.label")); labelsTooltips.put("description", new ResourceModel("Questionnaire.Tooltip.description")); labelsTooltips.put("labelNext", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelPrevious", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelStart", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelFinish", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelInterrupt", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelResume", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); labelsTooltips.put("labelCancel", new ResourceModel("Questionnaire.Tooltip.otherNavigation")); localePropertiesModel = new Model<LocaleProperties>( newQuestionnaire ? LocaleProperties.createForNewQuestionnaire(questionnaire) : localePropertiesUtils.load(questionnaire, questionnaire)); final LabelsPanel labelsPanel = new LabelsPanel("labels", localePropertiesModel, model, feedbackPanel, feedbackWindow, labelsTooltips, null); form.add(labelsPanel); final Locale userLocale = Session.get().getLocale(); IChoiceRenderer<Locale> renderer = new IChoiceRenderer<Locale>() { @Override public String getIdValue(Locale locale, int index) { return locale.toString(); } @Override public Object getDisplayValue(Locale locale) { return locale.getDisplayLanguage(userLocale); } }; IModel<List<Locale>> localeChoices = new LoadableDetachableModel<List<Locale>>() { @Override protected List<Locale> load() { List<Locale> locales = new ArrayList<Locale>(); for (String language : Locale.getISOLanguages()) { locales.add(new Locale(language)); } Collections.sort(locales, new Comparator<Locale>() { @Override public int compare(Locale locale1, Locale locale2) { return locale1.getDisplayLanguage(userLocale) .compareTo(locale2.getDisplayLanguage(userLocale)); } }); return locales; } }; Palette<Locale> localesPalette = new Palette<Locale>("languages", new PropertyModel<List<Locale>>(model.getObject(), "locales"), localeChoices, renderer, 5, false) { @Override protected Recorder<Locale> newRecorderComponent() { Recorder<Locale> recorder = super.newRecorderComponent(); recorder.setLabel(new ResourceModel("Languages")); recorder.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { LocaleProperties localeProperties = localePropertiesModel.getObject(); Collection<Locale> selectedLocales = getModelCollection(); @SuppressWarnings("unchecked") Collection<Locale> removedLocales = CollectionUtils.subtract(localeProperties.getLocales(), selectedLocales); for (Locale locale : removedLocales) { localeProperties.removeLocale(questionnaire, locale); } for (Locale locale : selectedLocales) { if (!localeProperties.getLocales().contains(locale)) { localeProperties.addLocale(questionnaire, locale); } } labelsPanel.onModelChange(target); } }); return recorder; } }; form.add(localesPalette); form.add(new SaveCancelPanel("saveCancel", form) { @Override protected void onSave(AjaxRequestTarget target, Form<?> form1) { try { if (questionnaire.getLocales().isEmpty()) { error(new StringResourceModel("LanguagesRequired", QuestionnairePanel.this, null) .getString()); feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); return; } prepareSave(target, questionnaire); questionnairePersistenceUtils.persist(questionnaire, localePropertiesModel.getObject()); QuestionnairePanel.this.onSave(target, questionnaire); } catch (Exception e) { log.error("Cannot persist questionnaire", e); error("Cannot persist questionnaire: " + e.getMessage()); feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); } } @Override protected void onCancel(AjaxRequestTarget target, @SuppressWarnings("hiding") Form<?> form) { QuestionnairePanel.this.onCancel(target); } @Override protected void onError(AjaxRequestTarget target, @SuppressWarnings("hiding") Form<?> form) { feedbackWindow.setContent(feedbackPanel); feedbackWindow.show(target); } }); }
From source file:org.sisto.jeeplate.jsf.Oracle.java
private void populateLanguages() { String[] allLanguages = Locale.getISOLanguages(); for (String languageCode : allLanguages) { Locale l = new Locale(languageCode); this.languages.put(l.getLanguage(), languageCode); }//from w w w.j a v a 2 s. c o m }
From source file:org.talend.dataquality.statistics.datetime.utils.PatternListGenerator.java
private static void processAdditionalDateTimePatternsByLocales() { for (FormatStyle style : FORMAT_STYLES) { if (PRINT_DETAILED_RESULTS) { System.out.println("--------------------Date Style: " + style + "-----------------------"); }/*from w w w . j av a 2 s. c o m*/ for (String lang : Locale.getISOLanguages()) { getFormatByStyle(style, style, true, false, new Locale(lang), false);// Date Only } } for (FormatStyle style : FORMAT_STYLES) { if (PRINT_DETAILED_RESULTS) { System.out.println("--------------------DateTime Style: " + style + "-----------------------"); } for (String lang : Locale.getISOLanguages()) { getFormatByStyle(style, style, true, true, new Locale(lang), false);// DateTime } } }
From source file:org.xwiki.test.rest.PageResourceTest.java
@Test public void testPUTGETTranslation() throws Exception { createPageIfDoesntExist(TestConstants.TEST_SPACE_NAME, TestConstants.TRANSLATIONS_PAGE_NAME, "Translations"); // PUT//from w ww . ja va2 s. c om String[] languages = Locale.getISOLanguages(); final String languageId = languages[random.nextInt(languages.length)]; Page page = objectFactory.createPage(); page.setContent(languageId); PutMethod putMethod = executePutXml( buildURI(PageTranslationResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TRANSLATIONS_PAGE_NAME, languageId).toString(), page, TestUtils.ADMIN_CREDENTIALS.getUserName(), TestUtils.ADMIN_CREDENTIALS.getPassword()); Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_CREATED, putMethod.getStatusCode()); // GET GetMethod getMethod = executeGet(buildURI(PageTranslationResource.class, getWiki(), TestConstants.TEST_SPACE_NAME, TestConstants.TRANSLATIONS_PAGE_NAME, languageId).toString()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); Page modifiedPage = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); // Some of the language codes returned by Locale#getISOLanguages() are deprecated and Locale's constructors map // the new codes to the old ones which means the language code we have submitted can be different than the // actual language code used when the Locale object is created on the server side. Let's go through the Locale // constructor to be safe. String expectedLanguage = LocaleUtils.toLocale(languageId).getLanguage(); Assert.assertEquals(expectedLanguage, modifiedPage.getLanguage()); Assert.assertTrue(modifiedPage.getTranslations().getTranslations().size() > 0); for (Translation translation : modifiedPage.getTranslations().getTranslations()) { getMethod = executeGet(getFirstLinkByRelation(translation, Relations.PAGE).getHref()); Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode()); modifiedPage = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream()); Assert.assertEquals(modifiedPage.getLanguage(), translation.getLanguage()); checkLinks(translation); } }