setlocale

Is it feasible to rely on setlocale, and rely on locales being installed?

巧了我就是萌 提交于 2019-11-28 03:29:43
问题 I was trying to generate a localized date string with strftime , the placeholder I use is %x . The language/locale is setlocale(LC_ALL, array('jp','japanese')) , however neither locale was available so it generated a string with improper characters. I then installed the ja_JP.utf8 locale and specified that as the first element in the array and the date formatting issue I had was resolved. My question is, should I always rely on locales being installed? I'm aware of how to install them on

Is setlocale thread-safe function?

做~自己de王妃 提交于 2019-11-28 03:16:59
问题 I need to change locale in the thread to parse a double with strtod() correctly, I'm using setlocale() for this (C++). Is it thread safe? Update: Another problem. When I invoke setlocale() in my main() function it doesn't affect in other routines deeper. Why??? There is a lot of code, so it's problematic to write the chunk. 回答1: You need to consult the documentation for whatever implementation you're using. C++ doesn't currently specify anything about threads so it comes down to the

setlocale(LC_ALL, 'en_GB.UTF8') not working on windows

纵饮孤独 提交于 2019-11-28 01:49:16
问题 Why does setlocale(LC_ALL, 'en_GB.UTF8'); return false on Windows Server 2003 R2 - Zend CE PHP 5.3.5 ? Function in question: setlocale. 回答1: From the PHP Manual: The return value of setlocale() depends on the system that PHP is running. It returns exactly what the system setlocale function returns. So in your case it returns false because the system returns false. It is likely that the locale you're using is not available on your system. A list of setlocale strings supported by Windows is

How to set JSTL locale from Java code?

末鹿安然 提交于 2019-11-27 20:14:12
问题 I want to set the JSTL locale which is used by <fmt:formatNumber> and friends. I know this is possible with <fmt:setLocale> , but I need to do it dynamically (depending on user data retrieved from my DB) and would prefer Java code - a filter class, to be precise. I thought setting the session attribute javax.servlet.jsp.jstl.fmt.locale to my desired Locale instance would do the trick, but it is ignored: The JSTL tags keep using the browser locale. I verified there are no page context or

PHP/Gettext Problems

左心房为你撑大大i 提交于 2019-11-27 14:00:33
I remember running some tests a some months ago with gettext and the following code worked perfectly: putenv('LANG=l33t'); putenv('LANGUAGE=l33t'); putenv('LC_MESSAGES=l33t'); if (defined('LC_MESSAGES')) // available if PHP was compiled with libintl { setlocale(LC_MESSAGES, 'l33t'); } else { setlocale(LC_ALL, 'l33t'); } bindtextdomain('default', './locale'); // ./locale/l33t/LC_MESSAGES/default.mo bind_textdomain_codeset('default', 'UTF-8'); textdomain('default'); echo _('Hello World!'); // h3110 w0r1d! This worked perfectly (under Windows XP and CentOS if I remember correctly), which was good

How do I strftime a date object in a different locale?

♀尐吖头ヾ 提交于 2019-11-27 04:22:54
I have a date object in python and I need to generate a time stamp in the C locale for a legacy system, using the %a (weekday) and %b (month) codes. However I do not wish to change the application's locale, since other parts need to respect the user's current locale. Is there a way to call strftime() with a certain locale? The example given by Rob is great, but isn't threadsafe. Here's a version that works with threads: import locale import threading from datetime import datetime from contextlib import contextmanager LOCALE_LOCK = threading.Lock() @contextmanager def setlocale(name): with

Sort an array with special characters in PHP

这一生的挚爱 提交于 2019-11-26 20:57:17
问题 I have an array that holds the names of languages in spanish: $lang["ko"] = "coreano"; //korean $lang["ar"] = "árabe"; //arabic $lang["es"] = "español"; //spanish $lang["fr"] = "francés"; //french I need to order the array and maintain index association, so I use asort() with the SORT_LOCALE_STRING setlocale(LC_ALL,'es_ES.UTF-8'); //this is at the beginning (config file) asort($lang,SORT_LOCALE_STRING); print_r($lang); The expected output would be in this order: Array ( [ar] => árabe [ko] =>

PHP/Gettext Problems

ぐ巨炮叔叔 提交于 2019-11-26 16:34:47
问题 I remember running some tests a some months ago with gettext and the following code worked perfectly: putenv('LANG=l33t'); putenv('LANGUAGE=l33t'); putenv('LC_MESSAGES=l33t'); if (defined('LC_MESSAGES')) // available if PHP was compiled with libintl { setlocale(LC_MESSAGES, 'l33t'); } else { setlocale(LC_ALL, 'l33t'); } bindtextdomain('default', './locale'); // ./locale/l33t/LC_MESSAGES/default.mo bind_textdomain_codeset('default', 'UTF-8'); textdomain('default'); echo _('Hello World!'); //

PHP setlocale has no effect

徘徊边缘 提交于 2019-11-26 13:22:29
The setlocale() function doesn't set the desired language (German). The goal is to output month names. This is my test code with trials so far: <?php date_default_timezone_set('Europe/Berlin'); setlocale(LC_ALL, 'de_DE.utf8'); // Or setlocale(LC_ALL, 'de_DE@euro'); // Or setlocale(LC_ALL, 'de_DE'); // Or setlocale(LC_ALL, 'de'); // Or setlocale(LC_ALL, 'ge'); echo strftime('%B'); Output: June instead of Juni Any suggestions? I don't have ssh or other shell access. The script is running on a linux server. PHP version 5.6 Benjamin Seiller Is is quite likely that the German locale is not

How do I strftime a date object in a different locale?

旧时模样 提交于 2019-11-26 12:43:03
问题 I have a date object in python and I need to generate a time stamp in the C locale for a legacy system, using the %a (weekday) and %b (month) codes. However I do not wish to change the application\'s locale, since other parts need to respect the user\'s current locale. Is there a way to call strftime() with a certain locale? 回答1: The example given by Rob is great, but isn't threadsafe. Here's a version that works with threads: import locale import threading from datetime import datetime from