cancel
Showing results for 
Search instead for 
Did you mean: 

Forms - locale indicator in text fields

loftux
Star Contributor
Star Contributor
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.
3 REPLIES 3

mastro
Champ in-the-making
Champ in-the-making
Thanks for your reply!

Now its clearer and I'll keep in mind I may need some adjustment with some locale thanks!

I'm still curios to know why

localeshort?left_pad(5)?substring(3,5)?lower_case

in place of

localeshort?left_pad(4)?substring(2,4)?lower_case

is the 5 there for some reason?

thank you anyway for your reply.

ps: do you think my comment on the ALF-12602 should also be moved in the forum?

loftux
Star Contributor
Star Contributor
5 since for example "sv_SE" is five characters, and that is what the browser sends, but sometimes only "sv" and therefor padding to make the substring work all the times. But may have it wrong here, as long as it works for you, use whatever you like  Smiley Happy

About the ALF-12602, if you intend for an open discussion about solution it may be more appropriate to start a topic in the forum. If the discussion ends up in a good solution, then add it to the issue (with possibly a link to the discussion that led to the solution)-

mastro
Champ in-the-making
Champ in-the-making
Smiley Surprisedops:
obviously …. Smiley Happy