mozilla-locale.patch
branchmozilla-1.9.2
changeset 122 4270a8c31485
child 184 e398c79b1668
equal deleted inserted replaced
119:8fea954c3b28 122:4270a8c31485
       
     1 # HG changeset patch
       
     2 # User Wolfgang Rosenauer <wr@rosenauer.org>
       
     3 # Parent a93100d87cc9841c6e3e4b29a47bb7b91f23415f
       
     4 Bug 583793 - Firefox interface language set to LANG, ignores LANGUAGE
       
     5 
       
     6 diff --git a/intl/locale/src/nsLocaleService.cpp b/intl/locale/src/nsLocaleService.cpp
       
     7 --- a/intl/locale/src/nsLocaleService.cpp
       
     8 +++ b/intl/locale/src/nsLocaleService.cpp
       
     9 @@ -55,16 +55,19 @@
       
    10  #  include "nsIOS2Locale.h"
       
    11  #elif defined(XP_MACOSX)
       
    12  #  include <Carbon/Carbon.h>
       
    13  #  include "nsIMacLocale.h"
       
    14  #elif defined(XP_UNIX) || defined(XP_BEOS)
       
    15  #  include <locale.h>
       
    16  #  include <stdlib.h>
       
    17  #  include "nsIPosixLocale.h"
       
    18 +#if (MOZ_PLATFORM_MAEMO >= 6)
       
    19 +#  include "nsIGConfService.h"
       
    20 +#endif
       
    21  #endif
       
    22  
       
    23  //
       
    24  // implementation constants
       
    25  const int LocaleListLength = 6;
       
    26  const char* LocaleList[LocaleListLength] = 
       
    27  {
       
    28  	NSILOCALE_COLLATE,
       
    29 @@ -169,39 +172,66 @@ nsLocaleService::nsLocaleService(void)
       
    30          nsAutoString category, category_platform;
       
    31          nsLocale* resultLocale;
       
    32          int i;
       
    33  
       
    34          resultLocale = new nsLocale();
       
    35          if ( resultLocale == NULL ) { 
       
    36              return; 
       
    37          }
       
    38 +
       
    39 +        // Get system configuration
       
    40 +        char* language = getenv("LANGUAGE");
       
    41 +        char* lang = getenv("LANG");
       
    42 +#if (MOZ_PLATFORM_MAEMO >= 6)
       
    43 +        // GConf key is treated as LANG _and_ LANGUAGE
       
    44 +        nsCAutoString gconfLocaleString;
       
    45 +        nsresult rv;
       
    46 +        nsCOMPtr<nsIGConfService> gconf =
       
    47 +            do_GetService(NS_GCONFSERVICE_CONTRACTID, &rv);
       
    48 +        if (NS_SUCCEEDED(rv)) {
       
    49 +            rv = gconf->GetString(NS_LITERAL_CSTRING("/meegotouch/i18n/language"),
       
    50 +                                  gconfLocaleString);
       
    51 +            if (NS_SUCCEEDED(rv) && !gconfLocaleString.IsEmpty()) {
       
    52 +                lang = gconfLocaleString.get();
       
    53 +                language = gconfLocaleString.get();
       
    54 +                // For setlocale() doing the right thing we need to export
       
    55 +                // this as LANG to the environment
       
    56 +                setenv("LANG", lang, 1);
       
    57 +            }
       
    58 +        }
       
    59 +#endif
       
    60          for( i = 0; i < LocaleListLength; i++ ) {
       
    61              nsresult result;
       
    62 +            // setlocale( , "") evaluates LC_* and LANG
       
    63              char* lc_temp = setlocale(posix_locale_category[i], "");
       
    64              CopyASCIItoUTF16(LocaleList[i], category);
       
    65 -            category_platform = category; 
       
    66 +            category_platform = category;
       
    67              category_platform.AppendLiteral("##PLATFORM");
       
    68              if (lc_temp != nsnull) {
       
    69                  result = posixConverter->GetXPLocale(lc_temp, xpLocale);
       
    70                  CopyASCIItoUTF16(lc_temp, platformLocale);
       
    71              } else {
       
    72 -                char* lang = getenv("LANG");
       
    73                  if ( lang == nsnull ) {
       
    74                      platformLocale.AssignLiteral("en_US");
       
    75                      result = posixConverter->GetXPLocale("en-US", xpLocale);
       
    76                  }
       
    77                  else {
       
    78                      CopyASCIItoUTF16(lang, platformLocale);
       
    79 -                    result = posixConverter->GetXPLocale(lang, xpLocale); 
       
    80 +                    result = posixConverter->GetXPLocale(lang, xpLocale);
       
    81                  }
       
    82              }
       
    83              if (NS_FAILED(result)) {
       
    84                  return;
       
    85              }
       
    86 +            // LANGUAGE is overriding LC_MESSAGES
       
    87 +            if (i == LC_MESSAGES && language) {
       
    88 +                CopyASCIItoUTF16(language, platformLocale);
       
    89 +                result = posixConverter->GetXPLocale(language, xpLocale);
       
    90 +            }
       
    91              resultLocale->AddCategory(category, xpLocale);
       
    92              resultLocale->AddCategory(category_platform, platformLocale);
       
    93          }
       
    94          mSystemLocale = do_QueryInterface(resultLocale);
       
    95          mApplicationLocale = do_QueryInterface(resultLocale);
       
    96      }  // if ( NS_SUCCEEDED )...
       
    97         
       
    98  #endif // XP_UNIX || XP_BEOS