2001-09-26 04:40:45 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-08-01 11:37:54 +04:00
|
|
|
|
2011-02-03 09:31:36 +03:00
|
|
|
#ifdef MOZ_WIDGET_QT
|
|
|
|
#include <QString>
|
|
|
|
#include <QtCore/QLocale>
|
2010-09-17 22:56:48 +04:00
|
|
|
#endif
|
|
|
|
|
1999-08-01 11:37:54 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2011-01-06 01:17:09 +03:00
|
|
|
#include "nsAutoPtr.h"
|
1999-08-01 11:37:54 +04:00
|
|
|
#include "nsILocale.h"
|
|
|
|
#include "nsILocaleService.h"
|
|
|
|
#include "nsLocale.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2003-03-19 09:26:49 +03:00
|
|
|
#include "prprf.h"
|
2007-09-19 03:12:06 +04:00
|
|
|
#include "nsTArray.h"
|
2013-09-27 20:45:04 +04:00
|
|
|
#include "nsString.h"
|
1999-08-01 11:37:54 +04:00
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2000-11-30 02:28:04 +03:00
|
|
|
#if defined(XP_WIN)
|
2011-05-02 12:49:11 +04:00
|
|
|
# include "nsWin32Locale.h"
|
2006-12-26 23:18:15 +03:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
# include <Carbon/Carbon.h>
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 22:10:24 +03:00
|
|
|
#elif defined(XP_UNIX)
|
2001-08-17 09:52:48 +04:00
|
|
|
# include <locale.h>
|
|
|
|
# include <stdlib.h>
|
2011-06-22 11:34:27 +04:00
|
|
|
# include "nsPosixLocale.h"
|
1999-08-02 06:45:34 +04:00
|
|
|
#endif
|
1999-08-01 11:37:54 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// implementation constants
|
|
|
|
const int LocaleListLength = 6;
|
|
|
|
const char* LocaleList[LocaleListLength] =
|
|
|
|
{
|
|
|
|
NSILOCALE_COLLATE,
|
|
|
|
NSILOCALE_CTYPE,
|
|
|
|
NSILOCALE_MONETARY,
|
|
|
|
NSILOCALE_NUMERIC,
|
|
|
|
NSILOCALE_TIME,
|
|
|
|
NSILOCALE_MESSAGE
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NSILOCALE_MAX_ACCEPT_LANGUAGE 16
|
|
|
|
#define NSILOCALE_MAX_ACCEPT_LENGTH 18
|
|
|
|
|
2014-02-11 02:57:01 +04:00
|
|
|
#if (defined(XP_UNIX) && !defined(XP_MACOSX))
|
1999-08-02 06:03:53 +04:00
|
|
|
static int posix_locale_category[LocaleListLength] =
|
|
|
|
{
|
|
|
|
LC_COLLATE,
|
|
|
|
LC_CTYPE,
|
|
|
|
LC_MONETARY,
|
|
|
|
LC_NUMERIC,
|
2000-08-24 04:50:13 +04:00
|
|
|
LC_TIME,
|
1999-08-02 06:03:53 +04:00
|
|
|
#ifdef HAVE_I18N_LC_MESSAGES
|
|
|
|
LC_MESSAGES
|
|
|
|
#else
|
|
|
|
LC_CTYPE
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#endif
|
1999-08-01 11:37:54 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsILocaleService implementation
|
|
|
|
//
|
|
|
|
class nsLocaleService: public nsILocaleService {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsISupports
|
|
|
|
//
|
2013-07-19 06:23:32 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
1999-08-01 11:37:54 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsILocaleService
|
|
|
|
//
|
1999-08-21 12:54:47 +04:00
|
|
|
NS_DECL_NSILOCALESERVICE
|
|
|
|
|
1999-08-01 11:37:54 +04:00
|
|
|
|
|
|
|
nsLocaleService(void);
|
|
|
|
|
2000-01-04 23:36:30 +03:00
|
|
|
protected:
|
|
|
|
|
1999-08-01 11:37:54 +04:00
|
|
|
nsresult SetSystemLocale(void);
|
|
|
|
nsresult SetApplicationLocale(void);
|
|
|
|
|
2003-10-30 08:04:45 +03:00
|
|
|
nsCOMPtr<nsILocale> mSystemLocale;
|
|
|
|
nsCOMPtr<nsILocale> mApplicationLocale;
|
1999-08-01 11:37:54 +04:00
|
|
|
|
2014-06-24 02:40:02 +04:00
|
|
|
virtual ~nsLocaleService(void);
|
1999-08-01 11:37:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsLocaleService methods
|
|
|
|
//
|
2003-10-30 08:04:45 +03:00
|
|
|
nsLocaleService::nsLocaleService(void)
|
1999-08-01 11:37:54 +04:00
|
|
|
{
|
2006-12-26 23:18:15 +03:00
|
|
|
#ifdef XP_WIN
|
2003-10-30 08:04:45 +03:00
|
|
|
nsAutoString xpLocale;
|
2011-05-02 12:49:11 +04:00
|
|
|
//
|
|
|
|
// get the system LCID
|
|
|
|
//
|
|
|
|
LCID win_lcid = GetSystemDefaultLCID();
|
2012-09-14 14:00:31 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(win_lcid);
|
2011-05-02 12:49:11 +04:00
|
|
|
nsWin32Locale::GetXPLocale(win_lcid, xpLocale);
|
|
|
|
nsresult rv = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));
|
2012-09-14 14:00:31 +04:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2011-05-02 12:49:11 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// get the application LCID
|
|
|
|
//
|
|
|
|
win_lcid = GetUserDefaultLCID();
|
2012-09-14 14:00:31 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(win_lcid);
|
2011-05-02 12:49:11 +04:00
|
|
|
nsWin32Locale::GetXPLocale(win_lcid, xpLocale);
|
|
|
|
rv = NewLocale(xpLocale, getter_AddRefs(mApplicationLocale));
|
2012-09-14 14:00:31 +04:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2000-02-16 13:01:26 +03:00
|
|
|
#endif
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 22:10:24 +03:00
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
2011-06-22 11:34:27 +04:00
|
|
|
nsRefPtr<nsLocale> resultLocale(new nsLocale());
|
2012-09-14 14:00:31 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(resultLocale);
|
2011-02-03 09:31:36 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_QT
|
2013-02-26 00:25:16 +04:00
|
|
|
const char* lang = QLocale::system().name().toUtf8();
|
2011-02-03 09:31:36 +03:00
|
|
|
#else
|
2011-06-22 11:34:27 +04:00
|
|
|
// Get system configuration
|
|
|
|
const char* lang = getenv("LANG");
|
2011-02-03 09:31:36 +03:00
|
|
|
#endif
|
|
|
|
|
2011-06-22 11:34:27 +04:00
|
|
|
nsAutoString xpLocale, platformLocale;
|
|
|
|
nsAutoString category, category_platform;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for( i = 0; i < LocaleListLength; i++ ) {
|
|
|
|
nsresult result;
|
|
|
|
// setlocale( , "") evaluates LC_* and LANG
|
|
|
|
char* lc_temp = setlocale(posix_locale_category[i], "");
|
|
|
|
CopyASCIItoUTF16(LocaleList[i], category);
|
|
|
|
category_platform = category;
|
|
|
|
category_platform.AppendLiteral("##PLATFORM");
|
2014-11-12 19:52:19 +03:00
|
|
|
|
|
|
|
bool lc_temp_valid = lc_temp != nullptr;
|
|
|
|
|
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
// Treat the "C" env as nothing useful. See Bug 1095298.
|
|
|
|
lc_temp_valid = lc_temp_valid && strcmp(lc_temp, "C") != 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (lc_temp_valid) {
|
2011-06-22 11:34:27 +04:00
|
|
|
result = nsPosixLocale::GetXPLocale(lc_temp, xpLocale);
|
|
|
|
CopyASCIItoUTF16(lc_temp, platformLocale);
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
if ( lang == nullptr ) {
|
2011-06-22 11:34:27 +04:00
|
|
|
platformLocale.AssignLiteral("en_US");
|
|
|
|
result = nsPosixLocale::GetXPLocale("en-US", xpLocale);
|
2001-03-01 03:58:35 +03:00
|
|
|
} else {
|
2011-06-22 11:34:27 +04:00
|
|
|
CopyASCIItoUTF16(lang, platformLocale);
|
|
|
|
result = nsPosixLocale::GetXPLocale(lang, xpLocale);
|
2000-08-24 04:50:13 +04:00
|
|
|
}
|
1999-08-02 06:03:53 +04:00
|
|
|
}
|
2011-06-22 11:34:27 +04:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resultLocale->AddCategory(category, xpLocale);
|
|
|
|
resultLocale->AddCategory(category_platform, platformLocale);
|
|
|
|
}
|
|
|
|
mSystemLocale = do_QueryInterface(resultLocale);
|
|
|
|
mApplicationLocale = do_QueryInterface(resultLocale);
|
2000-08-24 04:50:13 +04:00
|
|
|
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 22:10:24 +03:00
|
|
|
#endif // XP_UNIX
|
2000-10-05 00:11:55 +04:00
|
|
|
|
2006-12-26 23:18:15 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Get string representation of user's current locale
|
|
|
|
CFLocaleRef userLocaleRef = ::CFLocaleCopyCurrent();
|
|
|
|
CFStringRef userLocaleStr = ::CFLocaleGetIdentifier(userLocaleRef);
|
|
|
|
::CFRetain(userLocaleStr);
|
|
|
|
|
2007-09-19 03:12:06 +04:00
|
|
|
nsAutoTArray<UniChar, 32> buffer;
|
2006-12-26 23:18:15 +03:00
|
|
|
int size = ::CFStringGetLength(userLocaleStr);
|
2014-02-11 17:52:30 +04:00
|
|
|
buffer.SetLength(size + 1);
|
|
|
|
CFRange range = ::CFRangeMake(0, size);
|
|
|
|
::CFStringGetCharacters(userLocaleStr, range, buffer.Elements());
|
|
|
|
buffer[size] = 0;
|
|
|
|
|
|
|
|
// Convert the locale string to the format that Mozilla expects
|
|
|
|
nsAutoString xpLocale(reinterpret_cast<char16_t*>(buffer.Elements()));
|
|
|
|
xpLocale.ReplaceChar('_', '-');
|
|
|
|
|
|
|
|
nsresult rv = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mApplicationLocale = mSystemLocale;
|
2004-08-18 19:35:36 +04:00
|
|
|
}
|
|
|
|
|
2006-12-26 23:18:15 +03:00
|
|
|
::CFRelease(userLocaleStr);
|
|
|
|
::CFRelease(userLocaleRef);
|
2004-08-18 19:35:36 +04:00
|
|
|
|
2006-12-26 23:18:15 +03:00
|
|
|
NS_ASSERTION(mApplicationLocale, "Failed to create locale objects");
|
|
|
|
#endif // XP_MACOSX
|
1999-08-01 11:37:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsLocaleService::~nsLocaleService(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsLocaleService, nsILocaleService)
|
1999-08-01 11:37:54 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-10-30 08:04:45 +03:00
|
|
|
nsLocaleService::NewLocale(const nsAString &aLocale, nsILocale **_retval)
|
1999-08-01 11:37:54 +04:00
|
|
|
{
|
2007-08-15 07:54:16 +04:00
|
|
|
nsresult result;
|
1999-08-01 11:37:54 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
1999-08-01 11:37:54 +04:00
|
|
|
|
2011-01-06 01:17:09 +03:00
|
|
|
nsRefPtr<nsLocale> resultLocale(new nsLocale());
|
2007-08-15 07:54:16 +04:00
|
|
|
if (!resultLocale) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < LocaleListLength; i++) {
|
2011-11-01 11:16:48 +04:00
|
|
|
NS_ConvertASCIItoUTF16 category(LocaleList[i]);
|
2007-08-15 07:54:16 +04:00
|
|
|
result = resultLocale->AddCategory(category, aLocale);
|
2011-01-06 01:17:09 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 22:10:24 +03:00
|
|
|
#if defined(XP_UNIX) && !defined(XP_MACOSX)
|
2007-08-15 07:54:16 +04:00
|
|
|
category.AppendLiteral("##PLATFORM");
|
|
|
|
result = resultLocale->AddCategory(category, aLocale);
|
2011-01-06 01:17:09 +03:00
|
|
|
if (NS_FAILED(result)) return result;
|
2007-08-15 07:54:16 +04:00
|
|
|
#endif
|
|
|
|
}
|
1999-08-01 11:37:54 +04:00
|
|
|
|
2007-08-15 07:54:16 +04:00
|
|
|
NS_ADDREF(*_retval = resultLocale);
|
|
|
|
return NS_OK;
|
1999-08-01 11:37:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocaleService::GetSystemLocale(nsILocale **_retval)
|
|
|
|
{
|
|
|
|
if (mSystemLocale) {
|
2003-10-30 08:04:45 +03:00
|
|
|
NS_ADDREF(*_retval = mSystemLocale);
|
1999-08-01 11:37:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = (nsILocale*)nullptr;
|
1999-08-01 11:37:54 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocaleService::GetApplicationLocale(nsILocale **_retval)
|
|
|
|
{
|
|
|
|
if (mApplicationLocale) {
|
2003-10-30 08:04:45 +03:00
|
|
|
NS_ADDREF(*_retval = mApplicationLocale);
|
1999-08-01 11:37:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval=(nsILocale*)nullptr;
|
1999-08-01 11:37:54 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLocaleService::GetLocaleFromAcceptLanguage(const char *acceptLanguage, nsILocale **_retval)
|
|
|
|
{
|
|
|
|
char* cPtr;
|
|
|
|
char* cPtr1;
|
|
|
|
char* cPtr2;
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
int countLang = 0;
|
|
|
|
char acceptLanguageList[NSILOCALE_MAX_ACCEPT_LANGUAGE][NSILOCALE_MAX_ACCEPT_LENGTH];
|
|
|
|
nsresult result;
|
|
|
|
|
2012-08-24 11:49:00 +04:00
|
|
|
nsAutoArrayPtr<char> input(new char[strlen(acceptLanguage)+1]);
|
1999-08-01 11:37:54 +04:00
|
|
|
|
|
|
|
strcpy(input, acceptLanguage);
|
|
|
|
cPtr1 = input-1;
|
|
|
|
cPtr2 = input;
|
|
|
|
|
|
|
|
/* put in standard form */
|
|
|
|
while (*(++cPtr1)) {
|
|
|
|
if (isalpha(*cPtr1)) *cPtr2++ = tolower(*cPtr1); /* force lower case */
|
1999-09-27 05:27:15 +04:00
|
|
|
else if (isspace(*cPtr1)) ; /* ignore any space */
|
1999-08-01 11:37:54 +04:00
|
|
|
else if (*cPtr1=='-') *cPtr2++ = '_'; /* "-" -> "_" */
|
1999-09-27 05:27:15 +04:00
|
|
|
else if (*cPtr1=='*') ; /* ignore "*" */
|
1999-08-01 11:37:54 +04:00
|
|
|
else *cPtr2++ = *cPtr1; /* else unchanged */
|
|
|
|
}
|
|
|
|
*cPtr2 = '\0';
|
|
|
|
|
|
|
|
countLang = 0;
|
|
|
|
|
|
|
|
if (strchr(input,';')) {
|
|
|
|
/* deal with the quality values */
|
|
|
|
|
|
|
|
float qvalue[NSILOCALE_MAX_ACCEPT_LANGUAGE];
|
|
|
|
float qSwap;
|
|
|
|
float bias = 0.0f;
|
|
|
|
char* ptrLanguage[NSILOCALE_MAX_ACCEPT_LANGUAGE];
|
|
|
|
char* ptrSwap;
|
|
|
|
|
2001-05-19 01:41:48 +04:00
|
|
|
cPtr = nsCRT::strtok(input,",",&cPtr2);
|
1999-08-01 11:37:54 +04:00
|
|
|
while (cPtr) {
|
|
|
|
qvalue[countLang] = 1.0f;
|
|
|
|
/* add extra parens to get rid of warning */
|
2012-07-30 18:20:58 +04:00
|
|
|
if ((cPtr1 = strchr(cPtr,';')) != nullptr) {
|
2003-03-19 09:26:49 +03:00
|
|
|
PR_sscanf(cPtr1,";q=%f",&qvalue[countLang]);
|
1999-08-01 11:37:54 +04:00
|
|
|
*cPtr1 = '\0';
|
|
|
|
}
|
|
|
|
if (strlen(cPtr)<NSILOCALE_MAX_ACCEPT_LANGUAGE) { /* ignore if too long */
|
|
|
|
qvalue[countLang] -= (bias += 0.0001f); /* to insure original order */
|
|
|
|
ptrLanguage[countLang++] = cPtr;
|
|
|
|
if (countLang>=NSILOCALE_MAX_ACCEPT_LANGUAGE) break; /* quit if too many */
|
|
|
|
}
|
2001-05-19 01:41:48 +04:00
|
|
|
cPtr = nsCRT::strtok(cPtr2,",",&cPtr2);
|
1999-08-01 11:37:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* sort according to decending qvalue */
|
|
|
|
/* not a very good algorithm, but count is not likely large */
|
|
|
|
for ( i=0 ; i<countLang-1 ; i++ ) {
|
|
|
|
for ( j=i+1 ; j<countLang ; j++ ) {
|
|
|
|
if (qvalue[i]<qvalue[j]) {
|
|
|
|
qSwap = qvalue[i];
|
|
|
|
qvalue[i] = qvalue[j];
|
|
|
|
qvalue[j] = qSwap;
|
|
|
|
ptrSwap = ptrLanguage[i];
|
|
|
|
ptrLanguage[i] = ptrLanguage[j];
|
|
|
|
ptrLanguage[j] = ptrSwap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for ( i=0 ; i<countLang ; i++ ) {
|
2002-11-09 03:45:53 +03:00
|
|
|
PL_strncpyz(acceptLanguageList[i],ptrLanguage[i],NSILOCALE_MAX_ACCEPT_LENGTH);
|
1999-08-01 11:37:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* simple case: no quality values */
|
|
|
|
|
2001-05-19 01:41:48 +04:00
|
|
|
cPtr = nsCRT::strtok(input,",",&cPtr2);
|
1999-08-01 11:37:54 +04:00
|
|
|
while (cPtr) {
|
|
|
|
if (strlen(cPtr)<NSILOCALE_MAX_ACCEPT_LENGTH) { /* ignore if too long */
|
2002-11-09 03:45:53 +03:00
|
|
|
PL_strncpyz(acceptLanguageList[countLang++],cPtr,NSILOCALE_MAX_ACCEPT_LENGTH);
|
1999-08-01 11:37:54 +04:00
|
|
|
if (countLang>=NSILOCALE_MAX_ACCEPT_LENGTH) break; /* quit if too many */
|
|
|
|
}
|
2001-05-19 01:41:48 +04:00
|
|
|
cPtr = nsCRT::strtok(cPtr2,",",&cPtr2);
|
1999-08-01 11:37:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// now create the locale
|
|
|
|
//
|
|
|
|
result = NS_ERROR_FAILURE;
|
|
|
|
if (countLang>0) {
|
2003-10-30 08:04:45 +03:00
|
|
|
result = NewLocale(NS_ConvertASCIItoUTF16(acceptLanguageList[0]), _retval);
|
1999-08-01 11:37:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// clean up
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-21 03:47:27 +04:00
|
|
|
nsresult
|
2003-10-30 08:04:45 +03:00
|
|
|
nsLocaleService::GetLocaleComponentForUserAgent(nsAString& retval)
|
1999-08-21 03:47:27 +04:00
|
|
|
{
|
2003-10-30 08:04:45 +03:00
|
|
|
nsCOMPtr<nsILocale> system_locale;
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
result = GetSystemLocale(getter_AddRefs(system_locale));
|
|
|
|
if (NS_SUCCEEDED(result))
|
|
|
|
{
|
|
|
|
result = system_locale->
|
|
|
|
GetCategory(NS_LITERAL_STRING(NSILOCALE_MESSAGE), retval);
|
|
|
|
return result;
|
|
|
|
}
|
1999-08-21 03:47:27 +04:00
|
|
|
|
2003-10-30 08:04:45 +03:00
|
|
|
return result;
|
1999-08-21 03:47:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-08-01 11:37:54 +04:00
|
|
|
nsresult
|
|
|
|
NS_NewLocaleService(nsILocaleService** result)
|
|
|
|
{
|
2000-01-04 23:36:30 +03:00
|
|
|
if(!result)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
*result = new nsLocaleService();
|
2001-08-17 09:52:48 +04:00
|
|
|
if (! *result)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*result);
|
|
|
|
return NS_OK;
|
1999-08-01 11:37:54 +04:00
|
|
|
}
|