dotCMS supports a robust set of multi-lingual features that can be used anywhere on sites served by dotcms by passing a url parameter -
com.dotmarketing.htmlpage.language=2
Using a variable to set the language rather than the folder or site has the benefit of allowing a multi-lingual site to maintain a single information architecture, templates, and assets to deliver a templatized site or experience in the language of the visitors choice.
Even so, dotCMS is a flexible tool, and can support many different multi-lingual approaches. For example, we are often asked how does one set a language based on the folder path or site of the visitor, e.g.
/en/my-page.html
/es/mi-pagina.html
/de/meine-seite.html
or by
http://es.dotcms.com
http://de.dotcms.com
To automatically set your language variables based on your visitor's folder or site is easy using a few URLRewrite rules with dotCMS' built in UrlRewriteFilter. Add the rules in this code to your WEB-INF/urlrewrite.xml and volia, you site-wide language will be set.
(For this to work, you might need to move the UrlRewriteFilter filter-mapping to the top of the filter chain in your WEB-INF/web.xml, right above the CharsetEncodingFilter)
<!-- Example Rules to set dotCMS language by folder --> <rule> <name>English</name> <from>/en/(.*)$</from> <set name="com.dotmarketing.htmlpage.language">1</set> </rule> <rule> <name>Spanish</name> <from>/es/(.*)$</from> <set name="com.dotmarketing.htmlpage.language">2</set> </rule> <rule> <name>German</name> <from>/de/(.*)$</from> <set name="com.dotmarketing.htmlpage.language">3</set> </rule> <!-- Example Rules to set dotCMS language by site --> <rule> <name>site</name> <condition name="host" operator="equal">www.mysite.com</condition> <set name="com.dotmarketing.htmlpage.language">1</set> </rule> <rule> <name>site</name> <condition name="host" operator="equal">es.mysite.com</condition> <set name="com.dotmarketing.htmlpage.language">2</set> </rule> <rule> <name>site</name> <condition name="host" operator="equal">de.mysite.com</condition> <set name="com.dotmarketing.htmlpage.language">3</set> </rule>