Opened 14 years ago
Closed 13 years ago
#7495 closed enhancement (fixed)
program to get locale settings
Reported by: | mmadia | Owned by: | leavengood |
---|---|---|---|
Priority: | normal | Milestone: | R1 |
Component: | Applications/Command Line Tools | Version: | R1/Development |
Keywords: | Cc: | zooey | |
Blocked By: | Blocking: | #7412 | |
Platform: | All |
Description
Paraphrasing from ticket:7412#comment:10
We need a command line tool that:
- fetches the current locale settings (via the locale kit)
- returns a corresponding POSIX locale string.
- set the locale environment variable(s) in /etc/profile
Note: having that variable in SetupEnvironment would not be the best place. (SetupEnvironment is executed only on boot-up, so it cannot work for multi-user and locale settings changes wouldn't take effect until reboot.)
Change History (7)
comment:1 by , 14 years ago
Type: | bug → enhancement |
---|
comment:2 by , 14 years ago
follow-up: 4 comment:3 by , 14 years ago
If that data were written to B_COMMON_ETC_DIRECTORY/locale_type, this would conditionally execute it.
Index: data/etc/profile =================================================================== --- data/etc/profile (revision 41373) +++ data/etc/profile (working copy) @@ -5,6 +5,10 @@ echo -e "\nWelcome to the Haiku shell.\n" +if [ -f locale_type ]; then + . /etc/locale_type +fi + export USER=`id -un` export GROUP=`id -gn`
... and yes, I don't know how to output the text to a file using C++.
comment:4 by , 14 years ago
Replying to mmadia:
If that data were written to B_COMMON_ETC_DIRECTORY/locale_type, this would conditionally execute it.
I was rather thinking of something like this:
export LANG=`haiku_locale -l` export LC_TIME=`haiku_locale -t` export LC_MONETARY=`haiku_locale -m` ...
There's a whole bunch of LC_*
variables. Not sure, which we want to set. Possibly all, save LC_ALL
(which overrides all) and LC_CTYPE
probably won't be necessary since it only specifies the character encoding. LANG
is a general fallback for all unset variables, so only setting this one (from what the ReadOnlyBootPrompt
snippet yields) would be a start. The string for the formatting specific ones will probably be the same for all. Looking at the API, I guess one would construct it like this:
BFormattingConventions conventions; BLocale::Default()->GetFormattingConventions(&conventions); printf("%s_%s.UTF-8\n", conventions.LanguageCode(), conventions.CountryCode());
Don't know, if there's a way to encode the "12/24 clock" and the "month/day names from preferred language" settings into the string.
... and yes, I don't know how to output the text to a file using C++.
Printing to stdout is fine. Though FYI to print to a file in C one would use fprintf()
after opening the file with fopen()
(close with fclose()
). Cf. the Open Group Base Specs for the exact semantics of the functions.
comment:5 by , 14 years ago
Cc: | added |
---|---|
Version: | R1/alpha2 → R1/Development |
comment:6 by , 14 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Sounds fun and fairly easy. Taking ownership.
comment:7 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
The following snippet from ReadOnlyBootPrompt will get the preferred language.
A little snippet for additional motivation ...
printf("export LC_CTYPE=%s.UTF-8\n", firstPreferredLanguage);