Forum Discussion

marin's avatar
marin
Frequent Contributor
13 years ago

Table check in different locales

Hello all,



I wonder if it is possible to make table check evaluate correctly in different locales?



My test has a following scenario:

a table is stored in Stores -> Tables. Table has a column with a decimal value (e.g. 1.005).

The problem I am encountering is that table check will pass if browser's language is set to en-US, but it will fail if language is set to e.g. de-DE (because value in the table in browser will be 1,005 and not 1.005 (as in stored table) as decimal separator in de-DE is a comma).

What I would like to achieve is to have stored value check pass in both cases (in both locales)  - as the value in the column is actually equal.

I really hope there is an elegant way to achieve this without having to store a separate table for each locale...



Many thanks for any hints,



Marin

2 Replies

  • ArtemS's avatar
    ArtemS
    SmartBear Alumni (Retired)
    Hello,



    Currently, table checkpoints cannot automatically compare values in the locale-concerned manner. However, to perform such a comparison, there is no need to keep several locale-dependent variants of the baseline table. Using the Table.Values property, you can modify values read from the baseline table and then use the modified table during the comparison. For instance, the script substituting decimal separators in one of the columns would be as follows:







    function CompareWithReplacing()

    {



      var Table, FloatColumnIdx, SDec;

     

      ...

     

      // Obtain the Table object

      Table = Tables.Table1;

     

     

      // Obtain the current value of the decimal separator

      SDec = aqEnvironment.GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL)

     

      // Once the separator differs from "."

      if (SDec!=".")

        {

         // Substitute the values in the column with floating-point data

         Table.Values(i, FloatColumnIdx)=ReplaceChr(Table.Values(i, FloatColumnIdx), ".", SDec);        

        }         



      // Perform the comparison  

      Table.Compare();

     

      ...

    }



    // Helper routine that replaces all occurrences

    // of one character with another character.

    function ReplaceChr(Str, InChr, OutChr)

    {

    var Result, I, C;

      Result = "";

      for (I = 0; I < Str.length; I++)

      {               

        C = Str.substring(I, I + 1);

        if (C == InChr) C = OutChr;

        Result = Result + C;

      }

      return Result;

    }





    Regards, Artem.
  • marin's avatar
    marin
    Frequent Contributor
    Hello Artem,



    many thanks for an excellent suggestion! Works perfectly...

    The only thing I had to do was to modify the locale check to be checking the locale of the browser (set browser language), and not the system (host) locale - apologies for not being explicit in my question.

    Here the snippet for checking browser locale in IE and FF, might be useful for others as well:





    //Determine browser language settings

      if(strBrowser == "IEXPLORE")

      {

         var key = Storages.Registry("Software\\Microsoft\\Internet Explorer\\International", HKEY_CURRENT_USER);

         tempLang = key.GetOption("AcceptLanguage", "undefined").split(",", 1);

         

         //Language value determined in previous step is an array, hence tempLang[0]

         strBrowserLanguage = tempLang[0];

         Log.Message("IE language: " + strBrowserLanguage);

      }

     

      if(strBrowser == "firefox")

      {

         var UIPage = objBrowser.UIPage("chrome://browser/content/browser.xul");

         

         //Language determined in FF is a string

         strBrowserLanguage = UIPage.navigator.language;

         Log.Message("Firefox language: " + strBrowserLanguage);

      }



    //Value in strBrowserLanguage would be e.g. 'en-US', 'de-DE', 'en-AU'... etc. depending on set browser language.







    Many thanks again,



    Marin