Java Code Examples for org.springframework.extensions.surf.util.I18NUtil#parseLocale()
The following examples show how to use
org.springframework.extensions.surf.util.I18NUtil#parseLocale() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalLocalizationFilter.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Apply Client and Repository language locale based on the 'Accept-Language' request header * * @param req HttpServletRequest */ public void setLanguageFromRequestHeader(HttpServletRequest req) { Locale locale = null; String acceptLang = req.getHeader("Accept-Language"); if (acceptLang != null && acceptLang.length() > 0) { StringTokenizer tokenizer = new StringTokenizer(acceptLang, ",; "); // get language and convert to java locale format String language = tokenizer.nextToken().replace('-', '_'); locale = I18NUtil.parseLocale(language); I18NUtil.setLocale(locale); } else { I18NUtil.setLocale(Locale.getDefault()); } }
Example 2
Source File: TypedPropertyValueGetter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private Serializable processLocaleValue(Object value) { if (value instanceof String) { return I18NUtil.parseLocale((String) value); } else { throw new FormException("Locale property values must be represented as a String! Value is of type: " + value.getClass()); } }
Example 3
Source File: ImporterBootstrap.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Sets the Locale * * @param locale (language_country_variant) */ public void setLocale(String locale) { // construct locale this.locale = I18NUtil.parseLocale(locale); // store original strLocale = locale; }
Example 4
Source File: EmailHelper.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the user's locale. * * @param userId the user id * @return the default locale or the user's preferred locale, if available */ public Locale getUserLocaleOrDefault(String userId) { if (userId != null && personService.personExists(userId)) { String localeString = AuthenticationUtil.runAsSystem(() -> (String) preferenceService.getPreference(userId, "locale")); if (localeString != null) { return I18NUtil.parseLocale(localeString); } } return I18NUtil.getLocale(); }
Example 5
Source File: SetLocaleComponent.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void prepare(ResponseBuilder rb) throws IOException { SolrQueryRequest req = rb.req; SolrParams params = req.getParams(); String localeStr = params.get("locale"); Locale locale = I18NUtil.parseLocale(localeStr); I18NUtil.setLocale(locale); log.info("Set locale to " + localeStr); }
Example 6
Source File: ScriptUtils.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Sets current Locale from string */ public void setLocale(String localeStr) { Locale newLocale = I18NUtil.parseLocale(localeStr); I18NUtil.setLocale(newLocale); }
Example 7
Source File: MessageServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public Locale parseLocale(String localeStr) { return I18NUtil.parseLocale(localeStr); }
Example 8
Source File: MultilingualContentServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void testGetMissingTranslation() throws Exception { List<String> langList = contentFilterLanguagesService.getFilterLanguages(); int langListSize = langList.size(); // make sure that it exists at least tree language filter assertFalse("The testGetMissingTranslation test case needs at least three language", langListSize < 3); // get the first tree locale of the content filter language list Locale loc1 = I18NUtil.parseLocale(langList.get(0)); Locale loc2 = I18NUtil.parseLocale(langList.get(1)); Locale loc3 = I18NUtil.parseLocale(langList.get(2)); // create three content NodeRef nodeRef1 = createContent(); NodeRef nodeRef2 = createContent(); NodeRef nodeRef3 = createContent(); multilingualContentService.makeTranslation(nodeRef1, loc1); List<Locale> missing = multilingualContentService.getMissingTranslations(nodeRef1, false); // make sure that the missing language list size is correct assertFalse("Missing Translation Size false. " + "Real size : " + missing.size() + ". Normal Size " + (langListSize - 1), missing.size() != (langListSize - 1)); // make sure that the missing language list is correct assertFalse("Missing Translation List false. Locale " + loc1 + " found", missing.contains(loc1.toString())); multilingualContentService.addTranslation(nodeRef2, nodeRef1, loc2); multilingualContentService.addTranslation(nodeRef3, nodeRef1, loc3); // Add the missing translations in missing = multilingualContentService.getMissingTranslations(nodeRef1, false); // Make sure that the missing language list size is correct assertFalse("Missing Translation Size false. " + "Real size : " + missing.size() + ". Normal Size " + (langListSize - 3), missing.size() != (langListSize - 3)); // make sure that the missing language list is correct assertFalse("Missing Translation List false. Locale " + loc2.toString() + " or " + loc3.toString() + " found", missing.contains(loc2) || missing.contains(loc3)); }
Example 9
Source File: ContentData.java From alfresco-data-model with GNU Lesser General Public License v3.0 | 4 votes |
/** * Construct a content property from a string * * @param contentPropertyStr the string representing the content details * @return Returns a bean version of the string */ public static ContentData createContentProperty(String contentPropertyStr) { String contentUrl = null; String mimetype = null; long size = 0L; String encoding = null; Locale locale = null; // now parse the string StringTokenizer tokenizer = new StringTokenizer(contentPropertyStr, "|"); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.startsWith("contentUrl=")) { contentUrl = token.substring(11); if (contentUrl.length() == 0) { contentUrl = null; } } else if (token.startsWith("mimetype=")) { mimetype = token.substring(9); if (mimetype.length() == 0) { mimetype = null; } } else if (token.startsWith("size=")) { String sizeStr = token.substring(5); if (sizeStr.length() > 0) { size = Long.parseLong(sizeStr); } } else if (token.startsWith("encoding=")) { encoding = token.substring(9); if (encoding.length() == 0) { encoding = null; } } else if (token.startsWith("locale=")) { String localeStr = token.substring(7); if (localeStr.length() > 0) { locale = I18NUtil.parseLocale(localeStr); } } } ContentData property = new ContentData(contentUrl, mimetype, size, encoding, locale); // done return property; }