AnsweredAssumed Answered

Forms - locale indicator in text fields

Question asked by loftux Moderator on Mar 8, 2012
Latest reply on Mar 8, 2012 by mastro
This is a response to a question ask in the issue tracker https://issues.alfresco.com/jira/browse/ALF-11166, that I think is more approriate to answer here.

The reason to use localeshort?left_pad(5)?substring(3,5)?lower_case rather that localeshort?substring(2,4)?lower_case is that browser locale is sometimes sent as only 2 characters, the padding made sure you worked with 5 always. But that introduced some other problems, so Ihad to fix it for when your language locale for only 2 characters isnt the same as the flag locale (as in my languange/country sweden). So this it what the macro currently looks like:
<#macro renderLocaleImage field>
  <#if field.dataType == "mltext">
     <#assign localeshort=locale>
        <#switch localeshort>
         <#case "sv">
            <#assign localeshort="sv-se">
         <#break>
         <#case "ch">
            <#assign localeshort="ch-cn">
         <#break>
         <#case "ar">
            <#assign localeshort="ar-eg">
         <#break>
         <#case "en">
            <#assign localeshort="en-GB">
         <#break>
         <#case "nb">
            <#assign localeshort="no-no">
         <#break>
         <#case "nn">
            <#assign localeshort="no-no">
         <#break>
         <#case "smj">
            <#assign localeshort="no-no">
         <#break>
         <#case "sma">
            <#assign localeshort="no-no">
         <#break>
         <#case "smn">
            <#assign localeshort="fi-fi">
         <#break>
         <#case "sms">
            <#assign localeshort="fi-fi">
         <#break>
         <#case "da">
            <#assign localeshort="da-dk">
         <#break>
      </#switch>
    <#assign localeshort = localeshort?left_pad(5)?substring(3,5)?lower_case >
<img src="${url.context}/res/components/images/flags/${localeshort}.png" width="16px" height="11px" tabindex="0"/>
  </#if>
</#macro>
You may need to add additional language/country codes.

Outcomes