Some items are not translated in magnolia

94 Views Asked by At

I added a local to my project in the sites app and can display translated content properly when using the /locale/path. The problem I have is with a custom content app which displays in English (the default locale) and the navigation menu bar also appears in English although there is a translated navigation title for every page.

What could be the reason?

The code to retrieve the custom content app is:

<div class="row-fluid foo-content">
  [#assign articles = cmsfn.contentByPath("/", "articles") ]
  [#assign article = cmsfn.children(articles, "lib:article")?sort_by("publish_date")?first ]
  <div class="span4 newsroom">
    <h4>${i18n.get('footer.newsroom')}</h4>
    <section class="foo-container clearfix">
      <div class="news-date"> 
        <span class="date">${article.publish_date?string.dd}</span> 
        <span class="month">${article.publish_date?string.MMMM}</span> 
        <span class="year">${article.publish_date?string.yyyy}</span>
      </div>
      <div class="content">
        <p class="upper">${article.title}</p>
        <div class="fsize-12">
          ${article.description?substring(0, 170)}...
        </div>
        <p>            
          <a class="link-readmore" href="${cmsfn.link(cmsfn.siteRoot(content))}client/articles/view-article~${article.@name}~.html">${i18n.get('footer.readMore')}</a>
        </p>
      </div>
    </section>
    [#assign rootNode = cmsfn.contentByPath("/alqasemi/articles")]
    [#if rootNode??]
      <a class="btn-blue" href="${cmsfn.link(rootNode)}">${i18n.get('footer.viewAlqaswmiNews')}</a>
    [/#if]
  </div>
2

There are 2 best solutions below

3
Jan On

The problem you are facing is due to the fact that you are creating links manually to your articles here:

  <a class="link-readmore" href="${cmsfn.link(cmsfn.siteRoot(content))}client/articles/view-article~${article.@name}~.html">${i18n.get('footer.readMore')}</a>

Same way as you translate text of the link, you also need to provide locale to the view-article page/template so it knows what to translate to. You can look for details in the link.ftl of the demo project. Copied from there (should therefore work in 6.2.x), try to change the link to something like:

  [#assign target = cmsfn.contentByPath("/client/articles/view-article")!]
  [#assign link = cmsfn.link(target)!]
  [#assign articleName = article.@name!]

  <a href="${getDynamicLink(link, articleName)}">${i18n.get('footer.readMore')}</a>

where getDynamicLink() function would look like:

[#function getDynamicLink link itemName omitExtension=false]
    [#local dynamicLink = ""]
    [#if link?ends_with(".html")]
        [#local dynamicLink = link?replace(".html", "~"+itemName+"~")]
    [#else]
        [#local dynamicLink = link+"~"itemName+"~"]
    [/#if]        [#if !omitExtension]
        [#local dynamicLink += ".html"]
    [/#if]        [#return dynamicLink]
[/#function]

(Disclaimer: didn't check if the above code actually runs, there might be typos, but should give you the direction of the solution)

0
Patriot On

The reason for the content not being localized is that the content from the custom content app is not wrapped for translation be default.

The solution is to add cmsfn.wrapForI18n(content) to the content and then the output will match the applied locale.

So this line:

 [#assign article = cmsfn.children(articles, "lib:article")?first]

Should be:

 [#assign article = cmsfn.wrapForI18n(cmsfn.children(articles, "lib:article")?first)]