List of usage examples for com.liferay.portal.kernel.language LanguageUtil getLanguageId
public static String getLanguageId(PortletRequest portletRequest)
From source file:com.liferay.dynamic.data.mapping.storage.impl.LinkToPageFieldRenderer.java
License:Open Source License
protected String handleJSON(String value, Locale locale) { JSONObject jsonObject = null;//from w ww . ja va 2 s . co m try { jsonObject = JSONFactoryUtil.createJSONObject(value); } catch (JSONException jsone) { if (_log.isDebugEnabled()) { _log.debug("Unable to parse JSON", jsone); } return StringPool.BLANK; } long groupId = jsonObject.getLong("groupId"); boolean privateLayout = jsonObject.getBoolean("privateLayout"); long layoutId = jsonObject.getLong("layoutId"); try { return LayoutServiceUtil.getLayoutName(groupId, privateLayout, layoutId, LanguageUtil.getLanguageId(locale)); } catch (Exception e) { if (e instanceof NoSuchLayoutException || e instanceof PrincipalException) { return LanguageUtil.format(locale, "is-temporarily-unavailable", "content"); } } return StringPool.BLANK; }
From source file:com.liferay.exportimport.test.LayoutPrototypePropagationTest.java
License:Open Source License
@Test public void testAddLayoutFromLayoutPrototypeWithLinkDisabled() throws Exception { layout = LayoutTestUtil.addLayout(group, false, layoutPrototype, false); Locale locale = LocaleUtil.getDefault(); LayoutFriendlyURL layoutFriendlyURL = LayoutFriendlyURLLocalServiceUtil .getLayoutFriendlyURL(layout.getPlid(), LanguageUtil.getLanguageId(locale)); Assert.assertEquals(layoutFriendlyURL.getFriendlyURL(), layout.getFriendlyURL()); }
From source file:com.liferay.frontend.editor.lang.FrontEndEditorResourceBundleUtil.java
License:Open Source License
public static ResourceBundle getResourceBundle(Locale locale) { ResourceBundleLoader resourceBundleLoader = ResourceBundleLoaderUtil .getResourceBundleLoaderByBundleSymbolicName("com.liferay.frontend.editor.lang"); ResourceBundleLoader aggregateResourceBundleLoader = new AggregateResourceBundleLoader(resourceBundleLoader, LanguageUtil.getPortalResourceBundleLoader()); return aggregateResourceBundleLoader.loadResourceBundle(LanguageUtil.getLanguageId(locale)); }
From source file:com.liferay.journal.content.web.internal.portlet.JournalContentPortlet.java
License:Open Source License
@Override public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { PortletPreferences portletPreferences = renderRequest.getPreferences(); ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); long articleGroupId = PrefsParamUtil.getLong(portletPreferences, renderRequest, "groupId", themeDisplay.getScopeGroupId()); String articleId = PrefsParamUtil.getString(portletPreferences, renderRequest, "articleId"); String ddmTemplateKey = PrefsParamUtil.getString(portletPreferences, renderRequest, "ddmTemplateKey"); JournalArticle article = null;/*from w w w . j av a 2 s . co m*/ JournalArticleDisplay articleDisplay = null; if ((articleGroupId > 0) && Validator.isNotNull(articleId)) { String viewMode = ParamUtil.getString(renderRequest, "viewMode"); String languageId = LanguageUtil.getLanguageId(renderRequest); int page = ParamUtil.getInteger(renderRequest, "page", 1); article = _journalArticleLocalService.fetchLatestArticle(articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED); try { if (article == null) { article = _journalArticleLocalService.getLatestArticle(articleGroupId, articleId, WorkflowConstants.STATUS_ANY); } if (Validator.isNull(ddmTemplateKey)) { ddmTemplateKey = article.getDDMTemplateKey(); } articleDisplay = _journalContent.getDisplay(article, ddmTemplateKey, viewMode, languageId, page, new PortletRequestModel(renderRequest, renderResponse), themeDisplay); } catch (Exception e) { renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE); } } if (article != null) { renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE, article); } if (articleDisplay != null) { renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY, articleDisplay); } else { renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY); } super.doView(renderRequest, renderResponse); }
From source file:com.liferay.journal.internal.upgrade.v0_0_5.UpgradeJournal.java
License:Open Source License
private String _getDefaultLanguageId() { Locale defaultLocale = LocaleUtil.getSiteDefault(); return LanguageUtil.getLanguageId(defaultLocale); }
From source file:com.liferay.journal.search.test.JournalIndexerTest.java
License:Open Source License
@Test public void testUpdateArticleTranslation() throws Exception { ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); SearchContext searchContext1 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext1.setKeywords("Arquitectura"); searchContext1.setLocale(LocaleUtil.SPAIN); assertSearchCount(0, _group.getGroupId(), searchContext1); SearchContext searchContext2 = SearchContextTestUtil.getSearchContext(_group.getGroupId()); searchContext2.setKeywords("Apple"); searchContext2.setLocale(LocaleUtil.SPAIN); assertSearchCount(0, _group.getGroupId(), searchContext2); Map<Locale, String> titleMap = new HashMap<>(); titleMap.put(LocaleUtil.GERMANY, "Titel"); titleMap.put(LocaleUtil.SPAIN, "Titulo"); titleMap.put(LocaleUtil.US, "Title"); Map<Locale, String> contentMap = new HashMap<>(); contentMap.put(LocaleUtil.GERMANY, "Liferay Architektur Ansatz"); contentMap.put(LocaleUtil.SPAIN, "Liferay Arquitectura Aproximacion"); contentMap.put(LocaleUtil.US, "Liferay Architectural Approach"); JournalArticle article = JournalTestUtil.addArticleWithWorkflow(_group.getGroupId(), titleMap, titleMap, contentMap, true);//from www .ja v a2 s.c o m assertSearchCount(1, _group.getGroupId(), searchContext1); contentMap.put(LocaleUtil.SPAIN, "Apple manzana tablet"); String defaultLanguageId = LanguageUtil.getLanguageId(LocaleUtil.getDefault()); String content = DDMStructureTestUtil.getSampleStructuredContent(contentMap, defaultLanguageId); article = JournalArticleLocalServiceUtil.updateArticleTranslation(_group.getGroupId(), article.getArticleId(), article.getVersion(), LocaleUtil.SPAIN, article.getTitle(LocaleUtil.SPAIN), article.getDescription(LocaleUtil.SPAIN), content, null, serviceContext); assertSearchCount(0, _group.getGroupId(), searchContext2); User user = UserTestUtil.addUser(_group.getGroupId(), LocaleUtil.SPAIN); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); JournalArticleLocalServiceUtil.updateArticle(user.getUserId(), article.getGroupId(), article.getFolderId(), article.getArticleId(), article.getVersion(), article.getContent(), serviceContext); assertSearchCount(1, _group.getGroupId(), searchContext2); }
From source file:com.liferay.journal.taglib.servlet.taglib.JournalArticleTag.java
License:Open Source License
protected String getLanguageId() { if (Validator.isNotNull(_languageId)) { return _languageId; }/*from w w w . ja va2 s.c om*/ return LanguageUtil.getLanguageId(request); }
From source file:com.liferay.journal.transformer.test.JournalTransformerTest.java
License:Open Source License
@Test public void testLocaleTransformerListener() throws Exception { Map<String, String> tokens = getTokens(); Map<Locale, String> contents = new HashMap<>(); contents.put(LocaleUtil.BRAZIL, "Joao da Silva"); contents.put(LocaleUtil.US, "Joe Bloggs"); String xml = DDMStructureTestUtil.getSampleStructuredContent(contents, LanguageUtil.getLanguageId(LocaleUtil.US)); String script = "$name.getData()"; String content = JournalUtil.transform(null, tokens, Constants.VIEW, "en_US", UnsecureSAXReaderUtil.read(xml), null, script, TemplateConstants.LANG_TYPE_VM); Assert.assertEquals("Joe Bloggs", content); content = JournalUtil.transform(null, tokens, Constants.VIEW, "pt_BR", UnsecureSAXReaderUtil.read(xml), null, script, TemplateConstants.LANG_TYPE_VM); Assert.assertEquals("Joao da Silva", content); content = JournalUtil.transform(null, tokens, Constants.VIEW, "fr_CA", UnsecureSAXReaderUtil.read(xml), null, script, TemplateConstants.LANG_TYPE_VM); Assert.assertEquals("Joe Bloggs", content); }
From source file:com.liferay.journal.transformer.test.JournalTransformerTest.java
License:Open Source License
@Test public void testLocaleTransformerListenerNestedFieldWithNoTranslation() throws Exception { Map<String, String> tokens = getTokens(); Map<Locale, String> contents = new HashMap<>(); contents.put(LocaleUtil.US, "Joe Bloggs"); String xml = DDMStructureTestUtil.getSampleStructuredContent(contents, LanguageUtil.getLanguageId(LocaleUtil.US)); Document document = UnsecureSAXReaderUtil.read(xml); Element rootElement = document.getRootElement(); Attribute availableLocalesAttribute = rootElement.attribute("available-locales"); availableLocalesAttribute.setValue("en_US,pt_BR"); Element dynamicElement = (Element) document.selectSingleNode("//dynamic-element"); dynamicElement.addElement("nestedElement"); String script = "$name.getData()"; String content = JournalUtil.transform(null, tokens, Constants.VIEW, "en_US", document, null, script, TemplateConstants.LANG_TYPE_VM); Assert.assertEquals("Joe Bloggs", content); content = JournalUtil.transform(null, tokens, Constants.VIEW, "pt_BR", document, null, script, TemplateConstants.LANG_TYPE_VM); Assert.assertEquals("Joe Bloggs", content); }
From source file:com.liferay.journal.util.test.JournalTestUtilTest.java
License:Open Source License
@Test public void testAddDynamicContent() throws Exception { Map<Locale, String> contents = new HashMap<>(); contents.put(LocaleUtil.BRAZIL, "Joe Bloggs"); contents.put(LocaleUtil.US, "Joe Bloggs"); String xml = DDMStructureTestUtil.getSampleStructuredContent(contents, LanguageUtil.getLanguageId(LocaleUtil.US)); String content = JournalUtil.transform(null, getTokens(), Constants.VIEW, "en_US", UnsecureSAXReaderUtil.read(xml), null, JournalTestUtil.getSampleTemplateXSL(), TemplateConstants.LANG_TYPE_VM); Assert.assertEquals("Joe Bloggs", content); }