简体   繁体   English

在Liferay主题中添加语言支持

[英]Add language support in liferay theme

I am creating theme using liferay 6.2. 我正在使用liferay 6.2创建主题。 I need to add language support in my theme. 我需要在主题中添加语言支持。 For this I try to add language portlet by using 为此,我尝试通过使用添加语言portlet

$theme.language()

in portal_normal.vm. 在portal_normal.vm中。 By this portlet is added to theme but it did not work. 通过此Portlet被添加到主题中,但是没有起作用。 Also I tried by 我也尝试过

     $velocityPortletPreferences.setValue("portletSetupShowBorders","false")
     <menu class="nav-horizontal" id="language-navigation">
         <ul>
             <li>$theme.runtime("82", "", $velocityPortletPreferences.toString())</li>
         </ul>
     </menu>
     $velocityPortletPreferences.reset()

Also I noticed that language portlet does not work for guest (unauthorized) user. 我还注意到语言portlet不适用于来宾(未经授权)用户。 The issue has been logged here . 该问题已记录在此处

My requirement is whenever guest user comes to site he can change the language and accordingly Theme/site pages/admin/web content should change to the respective language. 我的要求是,只要访客用户来到站点,他就可以更改语言,因此主题/站点页面/管理员/网站内容应更改为相应的语言。

Can anyone suggest a workaround to develop this functionality? 谁能建议一种解决方法来开发此功能?

You can add the desired language as part of the URL: Eg view one page on liferay.com in english: http://www.liferay.com/en/radio . 您可以在URL中添加所需的语言:例如,在liferay.com上以英语查看一页: http : //www.liferay.com/cn/radio Same page in german (well, the content is non-localized, but the navigation elements are): http://www.liferay.com/de/radio . 德语的同一页面(当然,内容未本地化,但导航元素为): http : //www.liferay.com/de/radio This works also if you have more narrow definitions, eg with en_GB for british english. 如果您定义的范围更窄,也可以使用此方法,例如,使用en_GB表示英国英语。

In addendum to Olaf solution, you can add javascript snippet to the theme, something like this 在Olaf解决方案的附录中,您可以向主题添加javascript代码段,如下所示

var deutsch = "<a href='/de" + Liferay.currentURL + "'>De</a>";
var spain = "<a href='/es" + Liferay.currentURL + "'>Es</a>";
languagesDiv.html(deutsch + spain);

I have achieved this by adding 我通过添加实现了这一点

             <ul>
                <li><a href="/en"+$theme_display.getURLCurrent() title="UK">UK</a></li>
                <li><a href="/de"+$theme_display.getURLCurrent() title="Germen">Germen</a></li>
              </ul>

in portal_normal.vm file. 在portal_normal.vm文件中。 For localizing footer, I created the Web content with german translation and add it in footer like this 为了对页脚进行本地化,我用德语翻译创建了Web内容,并将其添加到页脚中,如下所示

<footer id="footer" role="contentinfo">
        #set ($VOID = $velocityPortletPreferences.setValue('portletSetupShowBorders', 'false'))
        #set ($portlet_id = '56')
        #set ($instance_id = "lw8tVGo0NyCB")
        #set ($my_portlet_id = "${portlet_id}_INSTANCE_${instance_id}")
        $theme.runtime($my_portlet_id, "", $velocityPortletPreferences.toString())
        $velocityPortletPreferences.reset() </footer>

Below code work for me in liferay 6.2 community edition. 下面的代码在liferay 6.2社区版中为我工作。 I change then it in configuration show dropdown and added require language from settings. 我在配置显示下拉列表中更改了它,并从设置中添加了要求的语言。

<div >
$velocityPortletPreferences.setValue("portletSetupShowBorders", "false")
$velocityPortletPreferences.setValue("languageIds", "pt_BR,en_US")
$velocityPortletPreferences.setValue("displayStyle", "1")
$theme.runtime("82", "", $velocityPortletPreferences.toString())
$velocityPortletPreferences.reset()
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM