-->

Multilingual documents in Alfresco Share?

2019-06-14 01:58发布

问题:

Alfresco has a MultilingualContentService but unfortunately it is not implemented in the Share UI.

So, how to handle mutilingual content in Share?
(for each document, several files in different languages)

Is there some solution ready?
If I have no choice but to develop, how would you do it?

回答1:

Wrap it in an object that's accessible from your webscripts. Here's an example which already does it:

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;
   }
}

The Spring bean:

<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>

And finally, use it like this:

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


回答2:

I guess showing the actual content shouldn't be to hard, because every content has his own uuid. The difficulty will be in creating a UI to upload a different language.

The first thing I would do is analyze how the action 'upload new version' works. So what we need is a custom action to upload a different language file and a popup to select which language that is. So the 'upload new version' does almost exactly the same, you can browse to a file and fill in versioning comment.

I don't know if there are webscripts available in Explorer to store the multilingual content, if not you should develop those.

Secondly is to create a webscript to return you all the multilingual files (same as above, probably won't exist)

Then define a block, like the workflows or version block, so links will appear of the files.