AliceWonderMiscreations Posted October 1, 2015 Share Posted October 1, 2015 Hello, I am writing a program that makes use of strftime() to produce localized results related to date and time. The output is XML sent as UTF-8 so I need to make sure the locale is a UTF-8 locale. setlocale(LC_TIME, 'ru_RU.UTF8') for example works beautifully and does exactly what I need it to do, but detecting that is the locale to use is where I am having a problem. For example, there are two Russian locales that FireFox in CentOS 7 can report - one is just ru and the second is ru-md Appending a .UTF8 to either of those doesn't work. I guess what I'm looking for, and I hope there is already a pear or PECL library, is some way to take the locale the browser reports and get a UTF8 safe locale I can use with setlocale for the purpose of strftime. Any suggestions? Quote Link to comment Share on other sites More sharing options...
AliceWonderMiscreations Posted October 1, 2015 Author Share Posted October 1, 2015 Oh and yes UTF8 is a must. The php script creates an XML file that is then translated via XSLT into another XML format. UTF8 is the only way to do that with sanity. Quote Link to comment Share on other sites More sharing options...
AliceWonderMiscreations Posted October 1, 2015 Author Share Posted October 1, 2015 okay I think I found a solution On the server - locale -a |grep "\.utf8$" > whatever.txt Then from a php script I can read whatever.txt and parse it into an two dimensional array, e.g. $foo[ru] is an array that contains ru_RU and ru_UA When the language array only has one entry, that's the default for any browser reported locale for the language, When the language array has two or more entries, I am doing some manual work on the script that turns it into an array so that the proper default is the first listed - e.g. en_GB should be the first in $foo[en] I wish there was a cleaner way to do it, but this will work to solve my problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.