cancel
Showing results for 
Search instead for 
Did you mean: 

Localize label from custom model

h_deselys
Champ in-the-making
Champ in-the-making
Hello,

I have tried for a moment to change the localization of my custom labels.

I have a custom model defined in customModel.xml placed alfresco/extension/model/. In alfresco/extension/messages/, I have set my labels in different languages. So I have several files: custom-model.properties (default), custom-model_fr_FR.properties and custom-model_en_GB.properties with this kind of expression:

custom_model.property.custom_property.title=Ma propriété
custom_model.aspect.custom_aspect.title=Mon aspect


I use Alfresco for another web application through OpenCMIS. Is there a way to tell to Alfresco which .properties file takes into account?

I tried some localization parameter when I initialize the sessions CMIS but with no results:

//Localization parameter
Map<String, String> parameter = new HashMap<String, String>();
parameter.put(SessionParameter.LOCALE_ISO3166_COUNTRY, "FR");
parameter.put(SessionParameter.LOCALE_ISO639_LANGUAGE, "fr");
parameter.put(SessionParameter.LOCALE_VARIANT, "");


I succeed to switch between these languages only when I delete one of them, but I want to be able to switch to each other without having the need to reboot my Alfresco instance.

Thanks in advance.
7 REPLIES 7

kaynezhang
World-Class Innovator
World-Class Innovator
What do you want to do with these localization labels in opencmis? I'm afraid you can't get it using opencmis.

h_deselys
Champ in-the-making
Champ in-the-making
I use OpenCMIS to retrieve document and their metadata. Some of my documents have custom aspects with custom properties and I want to be able to display these metadata (especially their labels) in different languages.

It's possible because I have already succeed to switch between en_US and fr_FR but only when I delete one of the two .properties in my alfresco/extension/messages. When Alfresco proposes different languages at the login page, it changes labels accordingly (even custom labels) and I want to be able to do the same in my web application.

It's maybe in function of the language of the server that hosts the Alfresco instance? It is possible?

kaynezhang
World-Class Innovator
World-Class Innovator
As far as I know custom model i18n messages only works in alfresco web interface(web-client and share).It did not expose to cmis,so I guess you can't get it using opencmis api,correct me if I'm wrong.
But you can get custom properties using opencmis.

h_deselys
Champ in-the-making
Champ in-the-making
Actually, I can retrieve custom aspects and custom properties using openCMIS thanks to Secondary Types:

<java>
CmisObject cmisObj = getCmisObject(id);
for (SecondaryType sec :cmisObj.getSecondaryTypes()) {
   String query = sec.getQueryName();
   String displayName = sec.getDisplayName();
   System.out.println("Sec Type: query = " + query + " / displayName = " + displayName);
}
</java>

This displays:

 Sec Type: query = cm:customAspect / displayName = Aspect personnalisé 


This french traduction appears when I have only my custom-model.properties (which contains label definitions in french) in alfresco/extension/messages/.

If I add custom-model_en.properties, it will return:

 Sec Type: query = cm:customAspect / displayName = Custom aspect 


So I guess that it is possible to retrieve localized label through OpenCMIS but like you suggest, it is not possible to choose the desired language via OpenCMIS, that's right?.

kaynezhang
World-Class Innovator
World-Class Innovator
Alfresco itself support Internationalization .
In alfresco web interface(share/webclient),alfresco try to get browser language preference settings first  and use it as locale.If no language preference is detected,then alfresco use the server locale as default locale.
Since there is no way in opencmis to set locale ,alfresco will always use the server locale.
I guess your server default locale is en,so when you add custom-model_en.properties,it matches your server locale and override the default i18n properties(custom-model.properties)

h_deselys
Champ in-the-making
Champ in-the-making
You said that there is no way to set locale in OpenCMIS. So these lines are not supposed to work:

<java>//Localization parameter
Map<String, String> parameter = new HashMap<String, String>();
parameter.put(SessionParameter.LOCALE_ISO3166_COUNTRY, "FR");
parameter.put(SessionParameter.LOCALE_ISO639_LANGUAGE, "fr");
parameter.put(SessionParameter.LOCALE_VARIANT, ""); </java>

I saw that this configuration may not work (https://issues.alfresco.com/jira/browse/MNT-10631).

So I presume that I have no more options than translating labels by myself.

Thank you for your concern.

kaynezhang
World-Class Innovator
World-Class Innovator
Yes ,I guess there is no way to set locale in OpenCMIS in current version ,it will use alfresco server's locale.