How to set various locales with setlocale()?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to set various locales with setlocale()?

Lee D
Hi,

I have a C program that needs to print the date in the correct form
for the appropriate locale.

Unfortunately, setlocale() will not accept  any of the locale names in
/usr/share/locale/, (which is documented in the man page for
setlocale()).

This is an embedded program running on custom arm hardware, not a
normal user system, so I am trying to do everything from within the C
program.  Setting an environment variable and rebooting would be
cumbersome.

Do you folks have any suggestions on how to accomplish this goal, or
how to make setlocale accept the locales listed on the system?

Thanks.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: How to set various locales with setlocale()?

Lee Brown
On Fri, Feb 16, 2018 at 3:08 AM, Lee D <[hidden email]> wrote:

> Hi,
>
> I have a C program that needs to print the date in the correct form
> for the appropriate locale.
>
> Unfortunately, setlocale() will not accept  any of the locale names in
> /usr/share/locale/, (which is documented in the man page for
> setlocale()).
>
> This is an embedded program running on custom arm hardware, not a
> normal user system, so I am trying to do everything from within the C
> program.  Setting an environment variable and rebooting would be
> cumbersome.
>
> Do you folks have any suggestions on how to accomplish this goal, or
> how to make setlocale accept the locales listed on the system?
>
>
> Different architecture, it works as advertised.  Maybe ask the arm folks?

$ cat a.c
#include <time.h>
#include <stdio.h>
#include <locale.h>

int main() {
 time_t now;
 char *s;
 s = setlocale(LC_ALL,"en_US.US-ASCII");
 char buf[100];
 time(&now);

 strftime(buf,99,"%c",localtime(&now));
 printf("%s\n", buf);

 s = setlocale(LC_ALL,"zh_TW.UTF-8");
 strftime(buf,99,"%c",localtime(&now));
 printf("%s\n", buf);

}
$ cc a.c
$ ./a.out
Fri Feb 16 11:26:58 2018
週五  2月/16 11:26:58 2018

FreeBSD apron.ad.nyingma.org 11.1-RELEASE-p6 FreeBSD 11.1-RELEASE-p6 #0
r328506M: Sat Jan 27 23:09:57 PST 2018
[hidden email]:/usr/obj/usr/src/sys/GENERIC
amd64
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: How to set various locales with setlocale()?

Lee D
On Fri, Feb 16, 2018 at 2:29 PM, Lee Brown <[hidden email]> wrote:
> On Fri, Feb 16, 2018 at 3:08 AM, Lee D <[hidden email]> wrote:
>
>> Do you folks have any suggestions on how to accomplish this goal, or
>> how to make setlocale accept the locales listed on the system?
>>
>>
> Different architecture, it works as advertised.  Maybe ask the arm folks?
>

Thanks for the example.

The problem ended up being my own fault.  Months ago I had disabled
installation of locales in the src.conf file in attempt to make my
installation image smaller.

Putting the locales back into the installation made it work.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: How to set various locales with setlocale()?

Lee Brown
On Sun, Feb 25, 2018 at 6:53 AM, Lee D <[hidden email]> wrote:

> On Fri, Feb 16, 2018 at 2:29 PM, Lee Brown <[hidden email]> wrote:
> > On Fri, Feb 16, 2018 at 3:08 AM, Lee D <[hidden email]> wrote:
> >
> >> Do you folks have any suggestions on how to accomplish this goal, or
> >> how to make setlocale accept the locales listed on the system?
> >>
> >>
> > Different architecture, it works as advertised.  Maybe ask the arm folks?
> >
>
> Thanks for the example.
>
> The problem ended up being my own fault.  Months ago I had disabled
> installation of locales in the src.conf file in attempt to make my
> installation image smaller.
>
> Putting the locales back into the installation made it work.
>
Don't ya hate it when you shoot yourself in the foot.  I'm surprised I can
stand at this point.
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[hidden email]"