List languages in Velocity

38 views
Skip to first unread message

Dave Hess

unread,
Mar 30, 2023, 1:33:45 PM3/30/23
to dotCMS User Group
Is there a velocity function that allows me to get a list of all the configured languages in a dotCMS site or instance? I need to build a language switcher tool in the site header.
Message has been deleted

Scott Wicken

unread,
Mar 30, 2023, 2:49:14 PM3/30/23
to dot...@googlegroups.com
We do have a Velocity Viewtool to deal with languages. Here's a velocity snippet that will list languages:

#set($languages = $text.getLanguages())
Available Languages:
<ul>
#foreach($lang in $languages)
    <li>$lang.getLanguage()</li>
#end
</ul>

And here are the docs about the tool: https://www.dotcms.com/docs/latest/texttool

On Thu, Mar 30, 2023 at 1:33 PM Dave Hess <dave...@svpworldwide.com> wrote:
Is there a velocity function that allows me to get a list of all the configured languages in a dotCMS site or instance? I need to build a language switcher tool in the site header.

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/8d878254-893f-47e5-8dcd-15e6fe641392n%40googlegroups.com.


--


Scott Wicken
Manager of Support

Dave Hess

unread,
Mar 31, 2023, 8:39:28 AM3/31/23
to dotCMS User Group
Thanks, Scott. This is helpful. I didn't read down the page far enough. I found I was able to get all the properties of each configured languages this way:

#set($languages = $text.getLanguages())
Available Languages:
<ul>
#foreach($lang in $languages)
    <li>lang: ${lang}</li>
    <li>
        <ul>
            <li>language_id: $!{lang.id}</li>
            <li>countryCode: $!{lang.getCountryCode()}</li>
            <li>languageCode: $!{lang.getLanguageCode()}</li>
            <li>language: $!{lang.getLanguage()}</li>
        </ul>
    </li>
#end
</ul>

Which produced

Available Languages:
<ul>
    <li>lang: en-us</li>
    <ul>
        <li>language_id: 1</li>
        <li>countryCode: US</li>
        <li>languageCode: en</li>
        <li>languageCode: English</li>
    </ul>
    <li>lang: fr-ca</li>
    <ul>
        <li>language_id: 4600065</li>
        <li>countryCode: CA</li>
        <li>languageCode: fr</li>
        <li>language: French</li>
    </ul>
</ul>


Jameson Mauro

unread,
Mar 31, 2023, 9:15:44 AM3/31/23
to dotCMS User Group
Dave: Nice presentation! I'm going to expand the last example in the doc in line with your snippet, crediting you.
Reply all
Reply to author
Forward
0 new messages