2 * Copyright 2011, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
6 * Ryan Leavengood, leavengood@gmail.com
10 #include <FormattingConventions.h>
12 #include <LocaleRoster.h>
21 extern const char *__progname
;
22 static const char *kProgramName
= __progname
;
28 BMessage preferredLanguages
;
29 BLocaleRoster::Default()->GetPreferredLanguages(&preferredLanguages
);
30 const char* firstPreferredLanguage
;
31 if (preferredLanguages
.FindString("language", &firstPreferredLanguage
)
34 firstPreferredLanguage
= "en";
37 return firstPreferredLanguage
;
42 print_formatting_conventions()
44 BFormattingConventions conventions
;
45 BLocale::Default()->GetFormattingConventions(&conventions
);
46 if (conventions
.CountryCode() != NULL
) {
47 printf("%s_%s.UTF-8\n", conventions
.LanguageCode(),
48 conventions
.CountryCode());
50 printf("%s.UTF-8\n", conventions
.LanguageCode());
56 print_time_conventions()
58 BFormattingConventions conventions
;
59 BLocale::Default()->GetFormattingConventions(&conventions
);
60 if (conventions
.CountryCode() != NULL
) {
61 printf("%s_%s.UTF-8%s\n", conventions
.LanguageCode(),
62 conventions
.CountryCode(),
63 conventions
.UseStringsFromPreferredLanguage()
64 ? "@strings=messages" : "");
66 printf("%s.UTF-8%s\n", conventions
.LanguageCode(),
67 conventions
.UseStringsFromPreferredLanguage()
68 ? "@strings=messages" : "");
76 printf("Usage: %s [-lftcm]\n"
77 " -l, --language\tPrint the currently set preferred language\n"
78 " -f, --format\t\tPrint the formatting-related locale\n"
79 " -t, --time\t\tPrint the time-related locale\n"
80 " -c, --message\t\tPrint the message-related locale\n"
81 " -m, --charmap\t\tList available character maps\n"
82 " -h, --help\t\tDisplay this help and exit\n",
90 main(int argc
, char **argv
)
92 static struct option
const longopts
[] = {
93 {"language", no_argument
, 0, 'l'},
94 {"format", no_argument
, 0, 'f'},
95 {"time", no_argument
, 0, 't'},
96 {"message", no_argument
, 0, 'c'},
97 {"charmap", no_argument
, 0, 'm'},
98 {"help", no_argument
, 0, 'h'},
103 while ((c
= getopt_long(argc
, argv
, "lcfmth", longopts
, NULL
)) != -1) {
106 printf("%s\n", preferred_language().String());
109 print_formatting_conventions();
111 case 'c': // for compatibility, we used to use 'c' for ctype
112 printf("%s.UTF-8\n", preferred_language().String());
115 print_time_conventions();
118 // POSIX mandatory options
122 // TODO 'a', 'c', 'k'