[opencms-dev] multi-language pages in 5.3.4

Alexander Kandzior alex at opencms.org
Thu May 13 12:55:02 CEST 2004


> I have the LocaleHandler 
> nearly finished, the last piece missing is how I can find 
> which language versions are available for a given page ? The 
> method 
> org.opencms.i18n.CmsLocaleManager.getAvailableLocales(CmsObject cms, 
> String resourceName)
> 
> despite its name doesn't provide this, it only searches for 
> property "locale" on the resource and its parents. Defining 
> that property for every page is not (I think) a viable way, 
> because that is redundant information to what's already in 
> the page itself.
> 
> I would need to get the list locales of page body elements 
> defined for the page. What is the right way to get them ?

Maybe you don't really need this. The xmlPage mechanism supports "fallback"
to default locales in case a requested locale is not available. This works
like standard Java locales at first, so if you request an "en_US" locale but
there is only content for "en" available, this is used instead. 

What's a bit different from the Java standard is the handling in case there
is no matching locale found at all.We found the concept of the "empty"
locale creates some issues, like you don't really know what the default is
etc. So we have a set of configured default locales in opencms-system.xml:

<localesdefault>
	<locale>en</locale>
	<locale>de</locale>		
</localesdefault>

This means if no content with a matching locale was found on a requested
page, the page is checked for content in the provided default locales, and
the first matching content that is available in the page is delivered. 

So instead of checking the content of the page, you should consider using
that default fallback mechanism. 

If you really must check the content from the page, you should try it like
this:

-----------
CmsObject cms; // needs to be initialized somehow
String filenmae = "/some/opencms/file/uri.html";
CmsFile file = cms.readFile(filename)
CmsXmlPage xmlpage = CmsXmlPage.read(cms, filename);
List supportedLocales = xmlpage.getLocales();
...
------------

Note: I didn't really try this but it should work.

Disclaimer: Please be aware that as of today the API for the CmsXmlPage is
not yet fixed, so there might be changes in names or package structure. E.g.
we will soon move CmsXmlPage from package org.opencms.page to
org.opencms.xml.page. The API will be finalized when we reach Beta stadium
for OpenCms 6, and currently we are in pre-Aplha so this is still some time
away. Most upcoming changes will be simple rename operations. 

Best Regards,
Alex.

Alexander Kandzior
Alkacon Software - The OpenCms Experts
http://www.alkacon.com





More information about the opencms-dev mailing list