Adjust code logic to use the new Accpet-Lang file structure.r=jbetak.

This commit is contained in:
tao%netscape.com 2000-05-12 23:50:33 +00:00
Родитель 1bcd83eb2c
Коммит d251a94d73
1 изменённых файлов: 71 добавлений и 58 удалений

Просмотреть файл

@ -69,9 +69,6 @@ nsAcceptLang::~nsAcceptLang()
NS_IMETHODIMP
nsAcceptLang::GetAcceptLangFromLocale(const PRUnichar *aLocale, PRUnichar **_retval)
{
#if DEBUG_tao
printf("\n--> nsAcceptLang::GetAcceptLangFromLocale <--\n");
#endif
nsString lc_name(aLocale);
if (lc_name.Length() <=0) {
printf("nsAcceptLang::GetAcceptLangFromLocale: aLocale is empty!");
@ -88,26 +85,40 @@ nsAcceptLang::GetAcceptLangFromLocale(const PRUnichar *aLocale, PRUnichar **_ret
}
nsIStringBundle *bundle = nsnull;
#if 1
res = sBundleService->CreateBundle("resource:/res/language.properties",
nsnull, &bundle);
#else
res = sBundleService->CreateBundle("chrome://global/locale/languageNames.properties",
nsnull, &bundle);
#endif
PRUnichar *ptrv = nsnull;
if (NS_OK == (res = bundle->GetStringFromName(aLocale, &ptrv))) {
nsString lc_tmp(aLocale);
nsCString sAccept(".accept");
nsCString sTrue("true");
lc_tmp.ToLowerCase();
lc_tmp = lc_tmp + sAccept;
if (NS_OK == (res = bundle->GetStringFromName(lc_tmp.GetUnicode(), &ptrv))) {
nsString tmp(ptrv);
if (tmp.Equals(sTrue)) {
// valid name already
*_retval = copyUnicode(lc_name);
return res;
}
else {
}
/* not in languageNames.properties; lang only?
*/
PRInt32 dash = lc_name.FindCharInSet("-");
PRInt32 dash = lc_tmp.FindCharInSet("-");
nsString lang;
nsString country;
if (dash > 0) {
/* lang-country
*/
PRInt32 count = 0;
count = lc_name.Left(lang, dash);
count = lc_name.Right(country, (lc_name.Length()-dash-1));
count = lc_tmp.Left(lang, dash);
count = lc_tmp.Right(country, (lc_tmp.Length()-dash-1));
/* ja-JP -> ja*/
}
else {
@ -118,16 +129,20 @@ nsAcceptLang::GetAcceptLangFromLocale(const PRUnichar *aLocale, PRUnichar **_ret
lang = lc_name;
}
// lang always in lower case; don't convert
*_retval = copyUnicode(lang);
lang = lang + sAccept;
if (NS_OK == (res = bundle->GetStringFromName(lang.GetUnicode(), &ptrv))) {
nsString tmp(ptrv);
if (tmp.Equals(sTrue)) {
/* lang is accepted */
return res;
}
else {
}
/* unsupported lang */
*_retval = nsnull;
}
}
return NS_ERROR_FAILURE;
}
@ -156,7 +171,6 @@ nsAcceptLang::GetLocaleFromAcceptLang(const PRUnichar *aName, PRUnichar **_retva
*_retval = copyUnicode(acceptLang);
return res;
}
else {
/* lang only
*/
NS_WITH_SERVICE(nsIStringBundleService, sBundleService, kStringBundleServiceCID, &res);
@ -180,7 +194,6 @@ nsAcceptLang::GetLocaleFromAcceptLang(const PRUnichar *aName, PRUnichar **_retva
else {
/* shall we use system locale instead ? */
}
}
/* ja -> ja-JP
* en-JP -> ?