Search code examples
internationalizationalpacajs

How to translate the country field in AlpacaJS forms?


Although the official documentation of the country field in AlpacaJS states that "The names of the countries are read from the I18N bundle for the current locale," I can't make the translation work.

I have tried to set the locale using the following two ways described on their internalization documentation without success:

  1. $.alpaca.setDefaultLocale('pt_BR');
  2. "view": {"locale": 'pt_BR'}

In the first case, I set it up while loading all "webapp" configurations while the second is part of the form configuration and should be set when alpaca builds the form. In both cases, all the other functionalities work, except the translation of the country names.

What am I missing?


Solution

  • Sadly they didn't do it, they put only common validation and date messages in the locale bundles and they didn't translate the country field values!

    You did it well setting the view locale though, your code works normally except in locale files you will not find any translation for country names so alpaca do like a fallback to base locale file... so unfortunately you should do it yourself by extending the country field values in the view like the following:

    "messages": {
      "es_ES": {
        "countries": {
          "tun": "Tunísia"
          ...
        }
    
      }
    }
    

    And you should complete all the list or you will get a country field with only the values you put in the previous view code

    here's a fiddle for this.