|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 #include "nsIPlatformCharset.h" |
|
6 #include "nsILocaleService.h" |
|
7 #include "nsCOMPtr.h" |
|
8 #include "nsReadableUtils.h" |
|
9 #include "nsIComponentManager.h" |
|
10 #include <stdio.h> |
|
11 |
|
12 int |
|
13 main(int argc, const char** argv) |
|
14 { |
|
15 |
|
16 nsCOMPtr<nsIPlatformCharset> platform_charset = |
|
17 do_CreateInstance(NS_PLATFORMCHARSET_CONTRACTID); |
|
18 if (!platform_charset) return -1; |
|
19 |
|
20 nsCOMPtr<nsILocaleService> locale_service = |
|
21 do_CreateInstance(NS_LOCALESERVICE_CONTRACTID); |
|
22 if (!locale_service) return -1; |
|
23 |
|
24 nsCOMPtr<nsILocale> locale; |
|
25 nsAutoCString charset; |
|
26 nsAutoString category; |
|
27 |
|
28 nsresult rv = locale_service->GetSystemLocale(getter_AddRefs(locale)); |
|
29 if (NS_FAILED(rv)) return -1; |
|
30 |
|
31 rv = locale->GetCategory(NS_LITERAL_STRING("NSILOCALE_MESSAGES"), category); |
|
32 if (NS_FAILED(rv)) return -1; |
|
33 |
|
34 rv = platform_charset->GetDefaultCharsetForLocale(category, charset); |
|
35 if (NS_FAILED(rv)) return -1; |
|
36 |
|
37 printf("DefaultCharset for %s is %s\n", NS_LossyConvertUTF16toASCII(category).get(), charset.get()); |
|
38 |
|
39 category.AssignLiteral("en-US"); |
|
40 rv = platform_charset->GetDefaultCharsetForLocale(category, charset); |
|
41 if (NS_FAILED(rv)) return -1; |
|
42 |
|
43 printf("DefaultCharset for %s is %s\n", NS_LossyConvertUTF16toASCII(category).get(), charset.get()); |
|
44 |
|
45 return 0; |
|
46 } |