cancel
Showing results for 
Search instead for 
Did you mean: 

I18N in Freemarker template

geert
Champ in-the-making
Champ in-the-making
Hello,

I am trying to make my  webscripts available in different languages.
On the wiki I found some information on the message(String) method, but when I try to use it I always get the following error:


Error during processing of the template 'Expression message('error') is undefined on line 25, column 82 in /webclientextension/imagebrowser/image_upload.post.html.status.ftl.'. Please contact your system administrator.

freemarker.core.InvalidReferenceException - Expression message('error') is undefined on line 25, column 82 in /webclientextension/imagebrowser/image_upload.post.html.status.ftl.
   
   freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
   freemarker.core.Expression.getStringValue(Expression.java:118)
   freemarker.core.Expression.getStringValue(Expression.java:93)
   freemarker.core.DollarVariable.accept(DollarVariable.java:76)
   freemarker.core.Environment.visit(Environment.java:196)
   freemarker.core.MixedContent.accept(MixedContent.java:92)
   freemarker.core.Environment.visit(Environment.java:196)
   freemarker.core.Environment.process(Environment.java:176)
   freemarker.template.Template.process(Template.java:232)
   org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:201)
   org.alfresco.web.scripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:286)
   org.alfresco.web.scripts.AbstractWebScript.sendStatus(AbstractWebScript.java:355)
   org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:193)
   org.alfresco.repo.web.scripts.RepositoryContainer$1.execute(RepositoryContainer.java:311)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:236)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:166)
   org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:322)
   org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:266)
   org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:240)
   org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:139)
   org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:111)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   org.alfresco.web.app.servlet.MTWebScriptAuthenticationFilter.doFilter(MTWebScriptAuthenticationFilter.java:102)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
   org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
   org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
   org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
   org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
   java.lang.Thread.run(Thread.java:595)

I use the message tag as follows in my ftl file:
${message('error')}

When I leave the message methods everything works perfect so normally my webscript configuration is correct.
I am using Alfresco Community 2.9.0C.

If you need more information, feel free to ask.

Thanks in advance!

Geert
11 REPLIES 11

geert
Champ in-the-making
Champ in-the-making
Hello,

Could someone please give me a hint or guide me in the right direction?

Kind regards,

Geert

mikeh
Star Contributor
Star Contributor
Have you defined the message "error" in a properties file anywhere? Try the same test with a message from an existing message.properties file.

Thanks,
Mike

geert
Champ in-the-making
Champ in-the-making
Hey MikeH,

The "error" is defined in webclient.properties. Other values from webclient.properties that I use in the webclient (in jsps that I override) are working fine.
I have tried using a resource key from an existing bundle in my webscript but it returns the same error.

Error during processing of the template 'Expression message('product_name') is undefined on line 43, column 49 in webclientextension/fileandlinkbrowser/externallink_selection.get.html.ftl.'. Please contact your system administrator.

Any idea?

Kind regards,

Geert

wabson
Star Contributor
Star Contributor
Hi Geert,

The error is occurring because the message() function is returning null, which Freemarker does not handle well. As Mike says, this is likely because the function cannot find that resource key.

Have you configured your message file into the application with Spring? You'll need to do this in order to use message bundles with Freemarker, as it uses a different mechanism to the web client JSPs. This also means that the strings defined in web-client.properties will not be available to Freemarker by default.

You can load in your own message bundle files by creating a new Spring config file (call it my-messages-context.xml or something similar) in your extension directory.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

      <bean id="myResourceBundles" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
         <property name="resourceBundles">
              <list>
                   <value>alfresco.extension.my-messages</value>
              </list>
         </property>
      </bean>

</beans>

This example assumes your messages are defined in a file called my-messages.properties within your extension directory, if you change this you will need to update the resourceBundles list value appropriately in the config above.

You may be able to load in the contents of web-client.properties by adding it to the list above, but given it's size I would recommend using your own bundles instead if possible.

Cheers,
Will.

geert
Champ in-the-making
Champ in-the-making
Hey Will,

Thanks for the reply. It works!

Kind regards,

Geert

robain
Champ in-the-making
Champ in-the-making
Hi Geert,
am trying to do something similar. create a web script which supports different languages. I did setup the properties file to pick up the message but how do i switch between the different languages. seems like simply switching the language of the browser does not work. do you have any details on how to do this.

Thanks
robain

joshna
Champ in-the-making
Champ in-the-making
Hi Greet,


I am gonna to try out internationalization in my project.Can u pls send me ur source code of i18n

regards,
joshna

robain
Champ in-the-making
Champ in-the-making
heres how I managed to do it.
create the properties file in the extension directory and then load it.

<bean id="myResourceBundles" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
      <property name="mymessageBundles">
         <list>
            <value>alfresco.extension.mymessage</value>
         </list>
      </property>
   </bean>

now i pass the locale as a request paremeter and then set it using
I18NUtil.setLocale

I then use the following in the freemarker template files.
${message("messagename")}


hope this helps.

thanks
robain

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

Thanks for ur reply..
Are u customising the alfresco webclient , or u are using in ur own webproject. Kindly explain me in detail and also send me the  code in detail.


Regards

joshna