3 Replies Latest reply on May 26, 2008 6:26 PM by Andrew A

    automatic bidi according to locale?

    Elhanan Maayan Novice

      hi..


      what is the way to hande loacle of forms with right-to-left left-to-right..
      do i need to right to form versions? can i write one form and will it be alinged right or left according to loacle? if i write to forms, will the correct one be send
      accordingto locale (like xxxlang.properties standard)


        • 1. Re: automatic bidi according to locale?
          Andrew A Newbie

          My approach has been to have two css files, one for ltr and the other for rtl locales for each page that requires bidi formatting.  Unfortunately, a Locale does not tell you the direction of a language.  Additionally, some variants have rtl and ltr versions for the same language.  The direction is embedded in the character sets, so in a bidi text, they will display correctly.  But to support the layout of a page, I'm not aware of any way to do that dynamically, so the application needs to have knowledge of the direction of the locales it supports and programmatically set the direction accordingly.


          I would be more than happy for someone else to provide a better approach, but that has been the method that I have used.


          Cheers,


          Andy




          • 2. Re: automatic bidi according to locale?
            Elhanan Maayan Novice

            thanks, but how would you set the direction in the first place, by using the css? (not sure how to do that)

            • 3. Re: automatic bidi according to locale?
              Andrew A Newbie

              You can do something like:


              <html xmlns="http://www.w3.org/1999/xhtml"
                    dir="#{myLocaleBean.languageScript.direction}"
                    lang="#{myLocaleBean.locale}">
              <head>
              ...
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                    <s:div rendered="#{myLocaleBean.languageScript.direction=='ltr'}">
                       <link href="stylesheet/style_ltr.css" rel="stylesheet" type="text/css" />
                  </s:div>
                  <s:div rendered="#{myLocaleBean.languageScript.direction=='rtl'}">
                       <link href="stylesheet/style_rtl.css" rel="stylesheet" type="text/css" />
                  </s:div>
              ...
              </head>
              <body >
              ...
              


              or


              <html xmlns="http://www.w3.org/1999/xhtml">
              <head>
              ...
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                    <s:div rendered="#{myLocaleBean.languageScript.direction=='ltr'}">
                       <link href="stylesheet/style_ltr.css" rel="stylesheet" type="text/css" />
                  </s:div>
                  <s:div rendered="#{myLocaleBean.languageScript.direction=='rtl'}">
                       <link href="stylesheet/style_rtl.css" rel="stylesheet" type="text/css" />
                  </s:div>
              ...
              </head>
              <body lang="#{myLocaleBean.locale}" dir="#{myLocaleBean.languageScript.direction}">     
              ...
              



              See Microsofts article on Authoring HTML for Middle Eastern Content for some differences in behaviour setting the dir on the html vs the body.  You might also want to check what W3C says on the subject as well.


              Setting the direction will ensure that the list boxes, etc are presented correctly.  But if you have any float: left; type code in your inline styles or style sheets, your positioning will still be all wrong.  So you need to reverse them as well, hence the two style sheets.


              Unfortunately, html does not support top to bottom, rtl Asian layouts as yet.  So East Asian layouts are generally compromises where they have alternate flows.


              The language can be handled for most scenarios by the Seam LocaleSelector which can return the language and the country variant from a locale string.  However, the language does not necessarily tell you what script to use. For instance, a number of ex-Soviet nations used to use a Cyrillic based script, but now some have moved their writing across to a Latin based script, such as Azerbaijan for example, which before it became Cyrillic used to be Arabic in the pre-Soviet era, and is now Latin in the post-Soviet era. Also languages such as Serbian can be presented in either a Latin or a Cyrillic script. It is not always evident which script is appropriate just from the locale string if the script variant is not included.    


              Additionally, the LocaleSelector does not return the direction.  So if you need to layout your screen to support the locale, then you will also need to develop a solution that can map the locale to a direction.  However, even this can be problematic. As one example, Syriac is a rtl script spoken by a small number of people scattered around the world, but in Russia there are a small number of users who use a ltr based Syriac script.  There are other examples along those lines as well.  Though for all practical purposes if translating based on economical value, it is unlikely that you will need to cater for these edge cases, but you still should be aware of them.


              Cheers,


              Andy