Jump to content

UTF8 locales


Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.