Working with Liferay 5.2
I would like to show a message related to the current language of Liferay.
The code for this message is in Velocity language and can be found in navigation.vm file.
<div id="navigation" class="sort-pages modify-pages">
<ul>
#foreach ($nav_item in $nav_items)
#if (($nav_item.getTitle() == 'register_correspondence') )
#if ($nav_item.hasChildren())
#foreach ($nav_child in $nav_item.getChildren())
<li >
<a href="$nav_child.getURL()" $nav_child.getTarget()>
<span >$nav_child.getName()</span>
</a>
</li>
#end
#end
#end
#if (($nav_item.getTitle() == 'reports') )
#if ($nav_item.isSelected())
#set ($nav_item_class = "selected")
#else
#set ($nav_item_class = "")
#end
<li>
#if (($nav_item.getTitle() == 'logout'))
<a href="$sign_out_url" $nav_item.getTarget()>
<span class="$nav_item.getTitle()">$nav_item.getName()</span>
</a>
#else
<a href="$nav_item.getURL()" $nav_item.getTarget()>
<span class="$nav_item.getTitle()">$nav_item.getName()</span>
</a>
#end
#if ($nav_item.hasChildren())
<ul class="child-menu">
#foreach ($nav_child in $nav_item.getChildren())
#if ($nav_child.isSelected())
#set ($nav_child_class = "selected")
#else
#set ($nav_child_class = "")
#end
<li class="$nav_child_class">
<a href="$nav_child.getURL()" $nav_child.getTarget()>$nav_child.getName()</a>
</li>
#end
</ul>
#end
</li>#end
#end
#if ($show_sign_out)
<li class="$nav_child_class">
<A HREF="$sign_out_url" onCLick="return confirm('Are you sure you want to log out')"> <font color="FF0000">
Logout
</font>
</A>
</li>
#end
</ul>
</div>
The message is contained within this element:
<li class="$nav_child_class">
<A HREF="$sign_out_url" onCLick="return confirm('Are you sure you want to log out')"> <font color="FF0000">
Logout
</font>
</A>
</li>
I aim to display this message based on the current language in use by Liferay.
Therefore, when the language is set to French, the message will be shown in French.
My attempt at achieving this behavior was unsuccessful with the following code:
<div id="navigation" class="sort-pages modify-pages">
<ul>
#foreach ($nav_item in $nav_items)
#if (($nav_item.getTitle() == 'register_correspondence') )
#if ($nav_item.hasChildren())
#foreach ($nav_child in $nav_item.getChildren())
<li >
<a href="$nav_child.getURL()" $nav_child.getTarget()>
<span >$nav_child.getName()</span>
</a>
</li>
#end
#end
#end
#if (($nav_item.getTitle() == 'reports') )
#if ($nav_item.isSelected())
#set ($nav_item_class = "selected")
#else
#set ($nav_item_class = "")
#end
<li>
#if (($nav_item.getTitle() == 'logout'))
<a href="$sign_out_url" $nav_item.getTarget()>
<span class="$nav_item.getTitle()">$nav_item.getName()</span>
</a>
#else
<a href="$nav_item.getURL()" $nav_item.getTarget()>
<span class="$nav_item.getTitle()">$nav_item.getName()</span>
</a>
#end
#if ($nav_item.hasChildren())
<ul class="child-menu">
#foreach ($nav_child in $nav_item.getChildren())
#if ($nav_child.isSelected())
#set ($nav_child_class = "selected")
#else
#set ($nav_child_class = "")
#end
<li class="$nav_child_class">
<a href="$nav_child.getURL()" $nav_child.getTarget()>$nav_child.getName()</a>
</li>
#end
</ul>
#end
</li>#end
#end
#if ($show_sign_out)
<script type="text/javascript">
var langVar = "$themeDisplay.getLocale()";
if (langVar == 'en_US') {
document.write('<li class="$nav_child_class">
<A HREF="$sign_out_url" onCLick="return confirm(\'Are you sure you want to log out\')"> <font color="FF0000">
Logout
</font>
</A>
</li>');
}
else
{
document.write('<li class="$nav_child_class">
<A HREF="$sign_out_url" onCLick="return confirm(\'Etes-vous sûr que vous voulez vous déconnecter\')"> <font color="FF0000">
Déconnexion
</font>
</A>
</li>');
}
</script>
#end
</ul>
</div>
While conducting my test within the JavaScript code, I added the line var langVar = "$themeDisplay.getLocale()";
However, upon testing, I encountered the following error:
Uncaught SyntaxError: Unexpected token ILLEGAL
Only modifications were made within the section labeled as #if ($show_sign_out)