<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Custom Language-Selection Liferay 7 Theme</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=106905123" />
  <subtitle>Custom Language-Selection Liferay 7 Theme</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=106905123</id>
  <updated>2026-04-05T03:14:29Z</updated>
  <dc:date>2026-04-05T03:14:29Z</dc:date>
  <entry>
    <title>RE: Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113542718" />
    <author>
      <name>Swathy R</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=113542718</id>
    <updated>2019-05-06T15:36:12Z</updated>
    <published>2019-05-06T15:36:12Z</published>
    <summary type="html">Hi I used the same method to display languages as long text in header and  it&amp;#39;s working well. &lt;br /&gt;&lt;br /&gt;But the only issue is it&amp;#39;s only translating the portlet content. Theme content is not translated. How to resolve this issue?</summary>
    <dc:creator>Swathy R</dc:creator>
    <dc:date>2019-05-06T15:36:12Z</dc:date>
  </entry>
  <entry>
    <title>RE: Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110724538" />
    <author>
      <name>Pasi Kössi</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=110724538</id>
    <updated>2018-08-17T07:13:26Z</updated>
    <published>2018-08-17T07:13:26Z</published>
    <summary type="html">&lt;p&gt;I guess the standard way to do this is to use a custom ADT for the
  language selector portlet. This works in Liferay 7.1 GA1, using one of
  the stabdard ADTs built in.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre&gt;
&amp;lt;#assign VOID = freeMarkerPortletPreferences.setValue(&amp;quot;displayStyle&amp;quot;, &amp;quot;ddmTemplate_LANGUAGE-SHORT-TEXT-FTL&amp;quot;)&amp;gt;
&amp;lt;#assign VOID = freeMarkerPortletPreferences.setValue(&amp;quot;languageIds&amp;quot;, &amp;quot;fr_FR,en_GB,ru_RU&amp;quot;)&amp;gt;
&amp;lt;@liferay_portlet[&amp;quot;runtime&amp;quot;]
        defaultPreferences=&amp;quot;${freeMarkerPortletPreferences}&amp;quot;
        portletProviderAction=portletProviderAction.VIEW
        portletProviderClassName=&amp;quot;com.liferay.portal.kernel.servlet.taglib.ui.LanguageEntry&amp;quot;
/&amp;gt;
&amp;lt;#assign VOID = freeMarkerPortletPreferences.reset()&amp;gt;&lt;/pre&gt;
&lt;p&gt;Note that the display template name is prefixed with &amp;quot;ddmTemplate&amp;quot;.&lt;/p&gt;
&lt;p&gt;Also, this only sets the preferences the first time the language
  selector portlet is loaded in a certain scope. During testing, you may
  need to remove the preferences from database every now and then.&lt;/p&gt;</summary>
    <dc:creator>Pasi Kössi</dc:creator>
    <dc:date>2018-08-17T07:13:26Z</dc:date>
  </entry>
  <entry>
    <title>RE: Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=107173637" />
    <author>
      <name>Jan Wallitschek</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=107173637</id>
    <updated>2018-04-25T09:33:08Z</updated>
    <published>2018-04-25T09:33:08Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;My current Solution is the following (which feels very squishy to be honest):&lt;br&gt;&lt;br&gt;in my &lt;strong&gt;header.ftl&lt;/strong&gt; i have the following:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;
&amp;lt;div class="language"&amp;gt;&amp;lt;ul id="languages"&amp;gt;&amp;lt;/ul&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;in my &lt;strong&gt;main.js&lt;/strong&gt; i have:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;
AUI().ready(

	/*
	This function gets loaded when all the HTML, not including the portlets, is
	loaded.
	*/

	function() {
		var languagesList = document.getElementById('languages');
		var availableLanguages = Object.keys(Liferay.Language.available);
		for(var i = 0; i &amp;amp;lt; availableLanguages.length; i++) {
			var languageKey = availableLanguages[i];
			var shortLanguageKey = languageKey.substring(0,2);
			var languageItem = document.createElement('li');
			var languageLink = document.createElement('a');
			if( languageKey === themeDisplay.getLanguageId()) {
				languageLink.setAttribute('class', 'active language-link')
			} else {
				languageLink.setAttribute('class', 'language-link')
			}
			languageLink.innerText = shortLanguageKey.toUpperCase();
			languageLink.href = getNewUrlFromLanguageKey(shortLanguageKey.toLowerCase());
			languageItem.appendChild(languageLink);
			languagesList.appendChild(languageItem);
			
			var separatorItem = document.createElement('li');
			separatorItem.setAttribute('class', 'language-separator');
			separatorItem.innerText = '|';
			if(i !== availableLanguages.length - 1) {
				languagesList.appendChild(separatorItem);
			}
		}
	}
);

function getNewUrlFromLanguageKey(languageKey, availableLanguages) {
	if(/\/(.*?)\//.exec(Liferay.currentURL) &amp;amp;amp;&amp;amp;amp; searchStringInArray(/\/(.*?)\//.exec(Liferay.currentURL)[1], Object.keys(Liferay.Language.available)) &amp;amp;gt; -1) {
		return themeDisplay.getPortalURL() + "/" + languageKey + Liferay.currentURL.substring(3, Liferay.currentURL.length);
	} else {
		return themeDisplay.getPortalURL() + "/" + languageKey + Liferay.currentURL;
	}
}

function searchStringInArray (str, strArray) {
	for (var j=0; j&amp;lt;strarray.length; j++) { if (strarray[j].match(str)) return j; } -1; &amp;lt; code&amp;gt;&amp;lt;/strarray.length;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;code&gt;&amp;lt;br&amp;gt;This works just like i want it to be, but as i said... It feels dirty to me.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;I wanted to replace the function &amp;lt;strong&amp;gt;getNewUrlFromLanguageKey&amp;lt;/strong&amp;gt; with some logic which i found in the forum. This logic depends on the Liferay-Javascript object instead of parsing the url with regex.&amp;lt;br&amp;gt;So this variant would be as follow:&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;pre&amp;gt;&amp;lt;code&amp;gt;
function getNewUrlFromLanguageKey(languageKey, availableLanguages) {
	var portletURL = Liferay.PortletURL.createURL(themeDisplay.getURLControlPanel());

	portletURL.setDoAsGroupId('true');
	portletURL.setLifecycle(Liferay.PortletURL.ACTION_PHASE);
	portletURL.setParameter('javax.portlet.action', '/language/view');
	portletURL.setParameter('p_auth', Liferay.authToken);
	portletURL.setPortletId("82");
	portletURL.setParameter('languageId', languageKey);

	return portletUrl;
}
&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;br&amp;gt;But &amp;lt;strong&amp;gt;Liferay.PortletURL&amp;lt;/strong&amp;gt; is null in my Liferay-Context. Cant tell you why...&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;I am open to any improvements / criticisms of this whole thing&lt;/code&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Jan Wallitschek</dc:creator>
    <dc:date>2018-04-25T09:33:08Z</dc:date>
  </entry>
  <entry>
    <title>RE: Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=107173574" />
    <author>
      <name>Jan Wallitschek</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=107173574</id>
    <updated>2018-04-25T09:25:07Z</updated>
    <published>2018-04-25T09:25:07Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi Shahbaz,&lt;br&gt;&lt;br&gt;thank you, i found the Template-Key for Short Text, which is &lt;strong&gt;LANGUAGE-SHORT-TEXT-FTL&lt;/strong&gt;&lt;br&gt;&lt;br&gt;But when i try:&lt;br&gt;&lt;pre&gt;&lt;code&gt;
&amp;amp;lt;#assign VOID = freeMarkerPortletPreferences.setValue("displayStyle", "LANGUAGE-SHORT-TEXT-FTL")&amp;amp;gt;

&amp;amp;lt;@liferay.languages default_preferences="${freeMarkerPortletPreferences}" /&amp;amp;gt;

&amp;amp;lt;#assign VOID = freeMarkerPortletPreferences.reset()&amp;amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;Nothing changes... Unfortunately i cant find anything on how to apply the correct Template-Key to portlet&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Jan Wallitschek</dc:creator>
    <dc:date>2018-04-25T09:25:07Z</dc:date>
  </entry>
  <entry>
    <title>RE: Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=107128859" />
    <author>
      <name>Fernando Fernandez</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=107128859</id>
    <updated>2018-04-24T13:32:27Z</updated>
    <published>2018-04-24T13:32:27Z</published>
    <summary type="html">&lt;div class="quote-title"&gt;Jan Wallitschek:&lt;/div&gt;&lt;blockquote&gt;Requirements : I need to display only the language-keys (EN | DE | HU | RO) and want to adjust some styling to it with css&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;You can define what languages show up by defining the languages available on the site: &amp;#34;Configuration / Site settings / Languages / Define a custom default language and available languages for this site.&amp;#34;&lt;br /&gt;&lt;br /&gt;You can change CSS for the portlet in the portlet instance &amp;#34;Look and Feel configuration&amp;#34; - easier - or in your own theme - harder.&lt;br /&gt;&lt;br /&gt;HTH&lt;br /&gt;&lt;br /&gt;Fernando</summary>
    <dc:creator>Fernando Fernandez</dc:creator>
    <dc:date>2018-04-24T13:32:27Z</dc:date>
  </entry>
  <entry>
    <title>RE: Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=107128325" />
    <author>
      <name>Shahbaz Khan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=107128325</id>
    <updated>2018-04-24T13:20:54Z</updated>
    <published>2018-04-24T13:20:54Z</published>
    <summary type="html">Hi Jan&lt;br /&gt;&lt;br /&gt;You can use &lt;strong&gt;Short Text&lt;/strong&gt; ADT. Which is available in the Global Site -&amp;gt; Configuration -&amp;gt; Application Display Templates.</summary>
    <dc:creator>Shahbaz Khan</dc:creator>
    <dc:date>2018-04-24T13:20:54Z</dc:date>
  </entry>
  <entry>
    <title>RE: Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106963963" />
    <author>
      <name>Jan Wallitschek</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106963963</id>
    <updated>2018-04-20T13:27:03Z</updated>
    <published>2018-04-20T13:27:03Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;I just tried something like that:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;
&amp;amp;lt;#assign VOID = freeMarkerPortletPreferences.setValue("displayStyle", "1")&amp;amp;gt;

&amp;amp;lt;@liferay.languages default_preferences="${freeMarkerPortletPreferences}" /&amp;amp;gt;

&amp;amp;lt;#assign VOID = freeMarkerPortletPreferences.reset()&amp;amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;I hope that i can change the displayStyle-Preference to something valid, that only displays the language text. (Tried 1,2,3, etc.)&lt;br&gt;But I cannot find any documentation on this.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Jan Wallitschek</dc:creator>
    <dc:date>2018-04-20T13:27:03Z</dc:date>
  </entry>
  <entry>
    <title>RE: Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106963350" />
    <author>
      <name>Jan Wallitschek</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106963350</id>
    <updated>2018-04-20T12:36:25Z</updated>
    <published>2018-04-20T12:36:25Z</published>
    <summary type="html">Hi Shahbaz,&lt;br /&gt;&lt;br /&gt;thank you for replying. themeDisplay.getLocale() will give me the current locale.&lt;br /&gt;&lt;br /&gt;But i want alle locales that i have configured in the backend/admin-settings. &lt;br /&gt;&lt;br /&gt;Do you know a way of doing it?&lt;br /&gt;&lt;br /&gt;Thank you!</summary>
    <dc:creator>Jan Wallitschek</dc:creator>
    <dc:date>2018-04-20T12:36:25Z</dc:date>
  </entry>
  <entry>
    <title>RE: Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106962280" />
    <author>
      <name>Shahbaz Khan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106962280</id>
    <updated>2018-04-20T12:19:46Z</updated>
    <published>2018-04-20T12:19:46Z</published>
    <summary type="html">Hi Jan,&lt;br /&gt;&lt;br /&gt;Just use themeDisplay.getLocale() in your theme and change css according locale id.&lt;br /&gt;&lt;br /&gt;Hope this will work for you.</summary>
    <dc:creator>Shahbaz Khan</dc:creator>
    <dc:date>2018-04-20T12:19:46Z</dc:date>
  </entry>
  <entry>
    <title>RE: Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106951172" />
    <author>
      <name>Jan Wallitschek</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106951172</id>
    <updated>2018-04-20T09:47:17Z</updated>
    <published>2018-04-20T09:47:17Z</published>
    <summary type="html">Hi Fernando,&lt;br /&gt;&lt;br /&gt;thank you for the quick reply.&lt;br /&gt;I already considered reusing the language selector  portlet but i cant find any useful informations on how to adjust the look and feel of that portlet.&lt;br /&gt;&lt;br /&gt;Requirements : I need to display only the language-keys (EN | DE | HU | RO) and want to adjust some styling to it with css.&lt;br /&gt;&lt;br /&gt;Is that possible? If yes, could you provide me some informations on how to do this?&lt;br /&gt;&lt;br /&gt;Thank you very much!</summary>
    <dc:creator>Jan Wallitschek</dc:creator>
    <dc:date>2018-04-20T09:47:17Z</dc:date>
  </entry>
  <entry>
    <title>RE: Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106917326" />
    <author>
      <name>Fernando Fernandez</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106917326</id>
    <updated>2018-04-19T17:03:58Z</updated>
    <published>2018-04-19T17:03:58Z</published>
    <summary type="html">&lt;div class="quote-title"&gt;Jan Wallitschek:&lt;/div&gt;&lt;blockquote&gt;i want to create a custom Language-Selection in my custom Liferay-Theme (Version 7, Freemarker)&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Hi Jan,&lt;br /&gt;&lt;br /&gt;I&amp;#39;m not sure what your requirements are but I think you could consider reusing the language selector portlet and maybe embed it on your theme.&lt;br /&gt;&lt;br /&gt;That way you&amp;#39;d avoid the work of redoing the language selection logic that&amp;#39;s already available.&lt;br /&gt;&lt;br /&gt;HTH&lt;br /&gt;&lt;br /&gt;Fernando</summary>
    <dc:creator>Fernando Fernandez</dc:creator>
    <dc:date>2018-04-19T17:03:58Z</dc:date>
  </entry>
  <entry>
    <title>Custom Language-Selection Liferay 7 Theme</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106905122" />
    <author>
      <name>Jan Wallitschek</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=106905122</id>
    <updated>2018-04-19T14:33:36Z</updated>
    <published>2018-04-19T14:33:36Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hey Guys, &lt;br&gt;&lt;br&gt;i want to create a custom Language-Selection in my custom Liferay-Theme (Version 7, Freemarker)&lt;br&gt;&lt;br&gt;My Idea was : looping over all available Languages and echo theme out in some &amp;lt;a href="${language-link}"&amp;gt;${language-text}&amp;lt;/a&amp;gt; Tags.&lt;br&gt;&lt;br&gt;I already tried some versions of the following:&lt;br&gt;&lt;br&gt;in init.ftl&lt;br&gt;&lt;pre&gt;&lt;code&gt;
&amp;amp;lt;#assign languages = languageUtil.getAvailableLocales() /&amp;amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;in header.ftl&lt;br&gt;&lt;pre&gt;&lt;code&gt;
&amp;amp;lt;#list languages as language&amp;amp;gt;
    &amp;lt;a href="/language.getLanguage()theme_display.getURLCurrent()"&amp;gt;
        language.getDisplayName()
    &amp;lt;/a&amp;gt;
 &amp;lt;!--#list--&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;My first Problem is that the assignment to the Variable "languages" is not working. The Variable is always null or missing.&lt;br&gt;&lt;br&gt;Can you help me how i can get access to all available languages that are available in a custom Liferay 7 Freemarker Theme?&lt;br&gt;&lt;br&gt;Thank you!&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Jan Wallitschek</dc:creator>
    <dc:date>2018-04-19T14:33:36Z</dc:date>
  </entry>
</feed>
