0

I work with liferay 5.2

I want to display same message related to the current language of liferay

the code of this message is in the velocity lnaguage

this is the source code navigation.vm

<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>

my message is in this balise

<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 want to displya this message ralated to the current language of liferay

meaning when the language is french the message will be displayed in the french

I try without succes with this 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 varlang = "$themeDisplay.getLocale()";

        if( varlang == '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>

I make my test in the javascript code I add this line var varlang = "$themeDisplay.getLocale()";

but when I test I have this error :

Uncaught SyntaxError: Unexpected token ILLEGAL 

I only changes the code in this section

#if ($show_sign_out)

franco
  • 1,829
  • 6
  • 42
  • 75

1 Answers1

0

Your error is javascript error inside your script tag.

This is not valid

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>');

for two reasons.

Problem number one is that strings cannot span acros multiple lines.

Second problem is that you have single quotes inside your string that you started with single quotes, you must escape inner single quotes.

You should rewrite it as

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>');

or at least as

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>');

But why do you do it with script tag?

I would rather have somthing like

#if ($show_sign_out)

    #if ($themeDisplay.getLocale() == "en_US")
        #set($logoutLabel = "Logout")
        #set($logoutConfirm = "Are you sure you want to log out")
    #else
        #set($logoutLabel = "Déconnexion")
        #set($logoutConfirm = "Etes-vous sur que vous voulez vous déconnecter")
    #end    

    <li class="$nav_child_class">
        <A HREF="$sign_out_url" onCLick="return confirm('$logoutConfirm')"> <font color="FF0000">
            $logoutLabel
        </font></A>
    </li>

#end 
Martin Gamulin
  • 3,855
  • 21
  • 25