| ||
![]() |
Initial Language for Visitors | |
|
The homepage defaults to the default language of a publication. The following is about changing the homepage to use the browser's language. Any multi-language website should provide the ability to change languages. This code is a hack because the website I am building has only 2 languages; later are suggestions for creating a more generic solution, but Cocoon does not make it easy.
To control the initial language FILE: publication-sitemap.xmap After: <map:match pattern="**/">
Add: <map:match pattern="**/index.html">
Repeat the map:when clauses for each locale. If some locales include the country, you would need to specify each separately using the second example. Replace the final "index_en.html" with your default language. A (better) universal solution would extract the language code from request:locale, then resource-exists check the correct index_xx.xml, and either redirect to it (if it exists), or use the default language (if not). The code would look like this: THIS CODE DOES NOT WORK!
<map:match pattern="**/index.html">
I could not discover how to call substring() within an XMAP. A workaround would be to send it to a JavaScript function, but that is too complex for such simple functionality. Anybody else know?
|