From 723fd0db48cda6569e074907648be875b0c77d42 Mon Sep 17 00:00:00 2001 From: "tao%netscape.com" Date: Fri, 9 Nov 2001 22:57:30 +0000 Subject: [PATCH] report ui language and country code in test program (not part of client). git-svn-id: svn://10.0.0.236/trunk@107779 18797224-902f-48f8-a5cc-f745e15eee43 --- .../intl/strres/tests/StringBundleTest.cpp | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/mozilla/intl/strres/tests/StringBundleTest.cpp b/mozilla/intl/strres/tests/StringBundleTest.cpp index 4cf91c49cdc..2a02e7cc4e5 100644 --- a/mozilla/intl/strres/tests/StringBundleTest.cpp +++ b/mozilla/intl/strres/tests/StringBundleTest.cpp @@ -91,6 +91,49 @@ static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID); #include "nsILocaleService.h" #include "nsLocaleCID.h" +// +// +// +nsresult +getCountry(PRUnichar *lc_name_unichar, PRUnichar **aCountry) +{ + + nsresult result = NS_OK; + nsAutoString category; category.AssignWithConversion("NSILOCALE_MESSAGES"); + + nsAutoString lc_name; + lc_name.Assign(lc_name_unichar); + // nsMemory::Free(lc_name_unichar); + + PRInt32 dash = lc_name.FindCharInSet("-"); + if (dash > 0) { + /* + */ + nsAutoString lang; + nsAutoString country; + PRInt32 count = 0; + count = lc_name.Left(lang, dash); + count = lc_name.Right(country, (lc_name.Length()-dash-1)); + *aCountry = ToNewUnicode(country); + } + else + result = NS_ERROR_FAILURE; + + return NS_OK; +} + +nsresult +getUILangCountry(PRUnichar** aUILang, PRUnichar** aCountry) +{ + nsresult result; + // get a locale service + nsCOMPtr localeService = do_GetService(NS_LOCALESERVICE_CONTRACTID, &result); + NS_ASSERTION(NS_SUCCEEDED(result),"nsLocaleTest: get locale service failed"); + + result = localeService->GetLocaleComponentForUserAgent(aUILang); + result = getCountry(*aUILang, aCountry); + return result; +} //////////////////////////////////////////////////////////////////////////////////////////////////// // @@ -145,6 +188,16 @@ main(int argc, char *argv[]) return 1; } + PRUnichar *uiLang = nsnull; + PRUnichar *country = nsnull; + ret = getUILangCountry(&uiLang, &country); +#if DEBUG_tao + nsAutoString uaStr(uiLang); // testing only + nsAutoString countryStr(country); // testing only + cout << "\n uaStr=" << ToNewCString(uaStr) + << ", country=" << ToNewCString(countryStr) + << "\n" << endl; +#endif nsIStringBundle* bundle = nsnull;