2 Replies Latest reply on Jan 9, 2013 2:56 PM by eric.wittmann

    Errai UI + Internationalization

    eric.wittmann

      Apologies if this has been discussed here or elsewhere already (I searched the forum and JIRA without success, but you know how that goes).  Are there any features planned around internationalization and Errai UI?

       

      It can be tricky supporting something like that in a UI framework, particularly one like Errai (templates, GWT based).  I've never been particularly fond of GWT's solutions to this problem [https://developers.google.com/web-toolkit/doc/latest/DevGuideI18n].  I prefer the dynamic string i18n approach to the static one (who wants to create permutations for every language?).  But that doesn't really help me if I'm using a template framework like Errai's.

       

      My thought is that it would be ideal if the template could be augmented with the i18n keys where appropriate, which result in dynamic replacement at runtime based on a message bundle pulled down from the server.  The template would continue to have the default language strings in it, but those strings would be replaced at runtime with localized values.  The primary benefits of this approach:

       

      1) Doesn't add to the # of permutations during compile

      2) Templates continue to work as Live Preview in the local language

       

      I can imagine something like this in the template:

       

      <form>
        <legend>Log in to your account</legend>
      
        <label for="username" i18n-key="login.username.label">Username</label>
        <input id="username" type="text" placeholder="Username">
        <label for="password" i18n-key="login.password.label">Password</label>
        <input id="password" type="password" placeholder="Password">
      
        <button>Log in</button>
        <button>Cancel</button>
      </form>
      

       

      The only addition is the i18n-key attribute on the label elements.  Errai would need to pull down the message bundle appropriate for the current locale (or it could be included in the host file as suggested by GWT docs).  The Errai template engine would then need to replace the text of the labels with the values found at the appropriate i18n keys in the message bundle.

       

      Is there already a best practice for this?  Should Errai UI support something like this?

        • 1. Re: Errai UI + Internationalization
          edewit

          Hi Eric,

           

          I must say that I like your proposal and agree with you that the standard way that GWT handles i18n is not very nice. But there is a way to make messages dynamic even with standard GWT there is a Dictionary that one can use to create dynamic messages. This togheter with a server call to get all the text of you application and you template proposal shouldn't be very hard to implement.

           

          Cheers,

               Erik Jan

          • 2. Re: Errai UI + Internationalization
            eric.wittmann

            Thanks.  And you're right - the GWT Dictionary is likely the way to go for pulling in the message bundle.  I took a stab at implementing my proposal and am in the middle of discussing the right solution here (in case you're interested):

             

              https://github.com/errai/errai/pull/24

             

            In fact, I used the Dictionary in the proposed implementation, and it worked out quite nicely.