cancel
Showing results for 
Search instead for 
Did you mean: 

Access to document translations in a webscript

dgenard
Champ on-the-rise
Champ on-the-rise
Hello,

I try to build a webscript displaying documents and their associated translations.
There is no specific Multilingual Content API available in javascript or freemarker, so I tried to navigate the relationships between a document and its translations.

But again, it seems that it is not feasible in javascript or freemarker.
All related translations are modeled as non-primary children of an ml:container node.
And javascript seems to be unable to retrieve non-primary parent associations of a given node.

As a consequence, it is currently not possible to implement a webscript displaying documents and their translations, without writing Java code, which greatly complexifies the task.
This is for my case a serious limitation of the built-in multilingual features of Alfresco 2.2E.

Did I miss something, or does someone have another idea ?

Thanks, Denis
9 REPLIES 9

robain
Champ in-the-making
Champ in-the-making
Hi, You might have already found a solution for this one by now. But posting a small sample code i prepared might be helpful for someone looking into this. basically i am trying to expose multilingualContentService. so here goes.


package com.someco.web.jscript;

import org.alfresco.repo.jscript.ScriptNode;
import org.alfresco.repo.processor.BaseProcessorExtension;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.ml.MultilingualContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Locale;

public final class MultilingualScript extends BaseProcessorExtension
{
    private static final Log logger = LogFactory.getLog(MultilingualScript.class);

   private MultilingualContentService multilingualContentService;
   private ServiceRegistry serviceRegistry;

   public MultilingualScript()
   {
      if (logger.isDebugEnabled()) {
         logger.debug("MultilingualScript Constructor Called");
      }
   }  
   
   //path = path of the original document
   //language = required language
   //returns the noderef for the translation content for the given language  
   public ScriptNode multilingualContent(String path, String language, ScriptNode companyHome) {
      if (logger.isDebugEnabled()) {
         logger.debug("MultilingualScript - parameters - " + path + " , " + language);
      }
      NodeRef nodeRef =  new ScriptNode(companyHome.getNodeRef(), serviceRegistry)
         .childByNamePath(path).getNodeRef();     
      nodeRef = multilingualContentService.getTranslationForLocale(nodeRef, new Locale(language) );     
      return new ScriptNode(nodeRef, serviceRegistry);
   }

   public MultilingualContentService getMultilingualContentService() {
      return multilingualContentService;
   }
   
   public void setMultilingualContentService(
         MultilingualContentService multilingualContentService) {
      this.multilingualContentService = multilingualContentService;
   }
   
   public ServiceRegistry getServiceRegistry() {
      return serviceRegistry;
   }
   
   public void setServiceRegistry(ServiceRegistry serviceRegistry) {
      this.serviceRegistry = serviceRegistry;
   }
}


<bean id="multilingualScript" parent="baseJavaScriptExtension" class="com.someco.web.jscript.MultilingualScript">
       <property name="extensionName">
           <value>multilingual</value>
       </property>
      <property name="serviceRegistry">
         <ref bean="ServiceRegistry" />
      </property>
      <property name="multilingualContentService">
         <ref bean="MultilingualContentService" />
      </property>
   </bean>

hope that was helpful for some atleast.

Thanks
robain

dgenard
Champ on-the-rise
Champ on-the-rise
Hi, thanks for the reply and the code…
This could be usefull indeed…

Denis

robain
Champ in-the-making
Champ in-the-making
glad that the code helps.
just to make it complete here's a snippet of how to use it on the js file.

var multilingualArticle = multilingual.multilingualContent("/myarticle", "es", companyhome);
model.multilingualArticle = multilingualArticle;

thanks
robain

yvinodh
Champ in-the-making
Champ in-the-making
Hi robain,

I am using this in my project. Can you explain this still more… I don't know how to execute this javascript file. What is this script actually means. What is the multilingual refers to,

" var multilingualArticle = multilingual.multilingualContent("/companyhome", "fr", companyhome);
         model.multilingualArticle = multilingualArticle;  "

Kindly help me to solve this problem.


Regards,
yvinodh.

robain
Champ in-the-making
Champ in-the-making
Here I am just exposing some of the functionality of MultilingualContentService (see earlier posts "class MultilingualScript extends BaseProcessorExtension") to be available in the webscript. "multilingual" object will be available on the webscript as defined in the xml configuration file (file in earlier post). You can achieve the same by using java-backed webscripts.

<property name="extensionName">
     <value>multilingual</value>
</property>

thanks
robain

yvinodh
Champ in-the-making
Champ in-the-making
Hi Robain,

Thanks for your reply. One more small clarification in that script is ,

" var multilingualArticle = multilingual.multilingualContent("/myarticle", "es", companyhome); " 

What is the 'myarticle' refers to??


Regards,
yvinodh.

robain
Champ in-the-making
Champ in-the-making
"multilingualContent", this is the method being called - code snippet below (look at the MultilingualScript class file in the earlier post). In this case "myarticle" referes to the full path of the document for which you want the translation in a language defined by the "es" parameters.

//path = path of the original document
   //language = required language
   //returns the noderef for the translation content for the given language  
   public ScriptNode multilingualContent(String path, String language, ScriptNode companyHome) {
      if (logger.isDebugEnabled()) {
         logger.debug("MultilingualScript - parameters - " + path + " , " + language);
      }
      NodeRef nodeRef =  new ScriptNode(companyHome.getNodeRef(), serviceRegistry)
         .childByNamePath(path).getNodeRef();     
      nodeRef = multilingualContentService.getTranslationForLocale(nodeRef, new Locale(language) );     
      return new ScriptNode(nodeRef, serviceRegistry);
   }

yvinodh
Champ in-the-making
Champ in-the-making
Hi robain,

Thank you again for your valuable reply…

Robain i have one more doubt in implementing multilingual….

The scenario is, I have all the documents uploaded seperately in three different folders like , inside CompanyHome i have created one folder named Documents inside that i have 3 different folders English, French , German.

Now my doubt is i have to get that particular documents from that folder in accordance to the user selection of language from our application.

Regards,
yvinodh.

robain
Champ in-the-making
Champ in-the-making
The approach here was to use Multilingual support built into alfresco, I am not sure if you are using that. You can make a content multilingual by using the "Make Multilingual" link in the details page for the content. Thats where the MultilingualService comes in.