EyeDentify

Warning about Server Locale after update from 3.0.52 > 3.0.53 - Help!

18 posts in this topic

Hello All PW gurus.

I just wanted your help with how i should handle the following problem.

I just recently (15 min ago) updated my website from 3.0.52 to 3.0.53, and in my admin i get a Warning:

Quote

Warning: your server locale is undefined and may cause issues. Please add this to /site/config.php file (adjust “en_US.UTF-8” as needed): setlocale(LC_ALL,'en_US.UTF-8');

My server is in Sweden, and does that mean i should set a Swedish locale in my Config.php or should it be what the warning says?

This warning gets me a little worried that something is going to break?

Thank you for all your help.

p.s: I have never before gotten this warning, just now after the update.


/EyeDentify
 

Warning in pw_admin_about_server_locale.png

Share this post


Link to post
Share on other sites
1 hour ago, matjazp said:

https://github.com/processwire/processwire-issues/issues/184

If your server has Sweden locale installed (check with locale -a in shell), then you can use that, if not, try with what warning says. If you use ML put setlocale() in /site/init.php 

 

I Thank you for the answer.

I was wondering why this warning comes up now that i update to 3.0.53 when i before that never had the same warning?

So if i change to swedish locale in the top of my Config.php, what could happen? could i screw something up with my site?

Share this post


Link to post
Share on other sites

If you would upload an image named "Ö.jpg", upload would fail. setlocale() solves this issue. This warning is echoed just in PW 3.0.53. You won't screw up your site, but it's possible that date/currency (and other locale aware) functions would produce different output. 

1 person likes this

Share this post


Link to post
Share on other sites
Just now, matjazp said:

If you would upload an image named "Ö.jpg", upload would fail. setlocale() solves this issue. This warning is echoed just in PW 3.0.53. You won't screw up your site, but it's possible that date/currency (and other locale aware) functions would produce different output. 

 

Oki :) i see now.

That makes sense. Thank you for your help.

So if i set the locale in my config.php it will work for my whole PW site then ?

Where is the best place? my config.php or init.php in my site dir?

Share this post


Link to post
Share on other sites

As adrian pointed out, in multilanguage environment you have to put setlocale() in init.php, ready.php or admin.php since language support module will overwrite locale settings in config.php. Still waiting for response from Ryan about that.

4 people like this

Share this post


Link to post
Share on other sites

Hello Everyone. I Would like to thank everyone that pitch in on this question and try to help me.

I would like to wait for a definitive answer from Ryan on where he thinks one should put this locale setting.

If anyone of you has connections to Ryan and could ask him to check this post and give his insight to what i should do, it would be very appreciated. 

Share this post


Link to post
Share on other sites

I also get this error and adding that line to config.php doesn't get rid of it. Where in the config.php file should I add it? Does the location matter?

I have also added it at the top of my functions.php file. Makes no difference either.

Where is init.php? Aren't those other files core files that you are not supposed to edit?

Share this post


Link to post
Share on other sites

Location of setlocale() in /site/config.php is not important. What locales are installed on the system? What locale are you trying to set? PW version you are using? Please upgrade to latest dev (3.0.55). Is Language Support module installed? init.php is located at /site/ folder, create it if needed.

 

1 person likes this

Share this post


Link to post
Share on other sites
15 hours ago, matjazp said:

Location of setlocale() in /site/config.php is not important. What locales are installed on the system? What locale are you trying to set? PW version you are using? Please upgrade to latest dev (3.0.55). Is Language Support module installed? init.php is located at /site/ folder, create it if needed.

 

 
 

Hello Again Matjazp.

Thank you for the input.

So to summarize:
1. i Should put the set_locale() setting in my init.php file?

2. Should i install language support module even if I do not use multi-language fields?

3. What setting should i use for Swedish?, or should i stick with US UTF-8?

4. Is there some easy php code i could run to get a list of installed locales?

 

Thank you again for all your help. :)

Edited by EyeDentify
PS. i am running PW 3.0.55 at the point of posting this.

Share this post


Link to post
Share on other sites

1. No. 

2. Why would you install language support if you don't need it?

3. sv_SE.UTF-8

4. echo exec ('locale -a');

Have to go now, will post more information/clarification of my brief answers later, stay tuned.

1 person likes this

Share this post


Link to post
Share on other sites
1 minute ago, matjazp said:

1. No. 

2. Why would you install language support if you don't need it?

3. sv_SE.UTF-8

4. echo exec ('locale -a');

Have to go now, will post more information/clarification of my brief answers later, stay tuned.

 

Thank You. Looking forward to the answers.

 

 

Share this post


Link to post
Share on other sites

First, some background to lit a light. There are some functions in PHP that may produce unexpected results in special situations. This functions are used by PW core files and in user contributed modules. Some users may have problems with file upload (pdf, zip, image, whatever) if filename has non-ascii character at the first place. For example, if user upload a file named "år.jpg" (year in Swedish language), it is expected that PW would transliterate (transform) the filename to "ar.jpg", but because of the bug in basename() PHP function, the filename would become just "r.jpg". Nevertheless the file would upload successfully. But if the filename is "привет.jpg" (Hi in Russian language) the upload would fail.

There are two ways how to handle this:

  1. Write and use custom functions instead of builtin functions
  2. Let end user fix that with proper locale

Option 1. is used in some CMS/CMF (like Drupal), PW (Ryan) opted for option 2. After successful login PW perform a test and warning is issued in case of test failure. It is now your responsibility to set proper system locale. The locale is a model and definition of a native-language environment. A locale defines its code sets, date and time formatting conventions, string conversions, monetary conventions, decimal formatting conventions, and collation (sort) order. Those "problematic" builtin PHP functions are locale aware, that means they work as expected, if locale is configured appropriately. 

Locale can be set by the underlying operating system or in PHP. Because on shared hosting you don't usually have root access to the OS, the only option to set the locale is by using the builtin setlocale() PHP function. But, before you can use/set the locale, it must first be installed on the OS. On most unix systems at least some basic locales are already there, they are just not used. To check what locale are you currently using and what locales are available for you to use, create the file testlocale.php at the root of your website with the following content:

<?php
    echo "<pre>Current locale:\n"
    var_dump(setlocale(LC_ALL, '0'));
    echo "\n\nAvailable locales:\n";
    echo exec('locale -a'); 

Then point your browser to http://yourwebsite/testlocale.php

If your current locale is "C" (and you are on unix), then you will probably get warning after login to the PW admin. What you want to do is change the locale to something that has "UTF-8" or "utf8" in the name of the available locales. In your case you would be looking for something like "sv_SE.UTF-8" or "sv_SE.utf8". Now, there is a chance that Swedish locale is not installed. You can ask your hosting provider to install it for you or use some other UTF-8 locale. On most unix systems I have seen, at least "en_US.UTF-8" or "en_US.utf8" is installed. If even that English locale is not available, then look for "C.UTF-8" or "C.utf8". And this is what you have to use as parameter in the setlocale() call:

setlocale(LC_ALL, "sv_SE.utf8");

You could actually "stack up" multiple locales and one will eventually work:

setlocale(LC_ALL, "sv_SE.utf8", "sv_SE.UTF-8", "en_US.UTF-8", "en_US.utf8", "C.UTF-8", "C.utf8");

Now, regarding where to put that setlocale() call. If you are not using PW multi language capabilities (you don't have Languge Support module installed), then you place setlocale to /site/config.php. That's it. If Language Support module is installed (PW checks for that), you have two options:

  1. Translate the string "C" in LanguageSupport.module for each installed language
  2. Put setlocale() call in /site/init.php

My preferred method is option 1 and this is what PW (Ryan) recommends. See https://processwire.com/api/multi-language-support/code-i18n/ for more info on translating files. Option 1 allows you to set different locale for each of the installed language, while  option 2 allows setting of one locale for all languages. PW will also provide links for the files that needs to be translated in the warning message.

Ryan just pushed an update that makes it use the locale setting on the frontend when using LanguageSupportPageNames module (until now just language was changed, but not locale). Also setLocale() and getLocale() methods are added to the $languages API var. ^-^

Edited by matjazp
Info on locale on frontend
5 people like this

Share this post


Link to post
Share on other sites
1 hour ago, matjazp said:

First, some background to lit a light. There are some functions in PHP that may produce unexpected results in special situations. This functions are used by PW core files and in user contributed modules. Some users may have problems with file upload (pdf, zip, image, whatever) if filename has non-ascii character at the first place. For example, if user upload a file named "år.jpg" (year in Swedish language), it is expected that PW would transliterate (transform) the filename to "ar.jpg", but because of the bug in basename() PHP function, the filename would become just "r.jpg". Nevertheless the file would upload successfully. But if the filename is "привет.jpg" (Hi in Russian language) the upload would fail.

There are two ways how to handle this:

  1. Write and use custom functions instead of builtin functions
  2. Let end user fix that with proper locale

Option 1. is used in some CMS/CMF (like Drupal), PW (Ryan) opted for option 2. After successful login PW perform a test and warning is issued in case of test failure. It is now your responsibility to set proper system locale. The locale is a model and definition of a native-language environment. A locale defines its code sets, date and time formatting conventions, string conversions, monetary conventions, decimal formatting conventions, and collation (sort) order. Those "problematic" builtin PHP functions are locale aware, that means they work as expected, if locale is configured appropriately. 

Locale can be set by the underlying operating system or in PHP. Because on shared hosting you don't usually have root access to the OS, the only option to set the locale is by using the builtin setlocale() PHP function. But, before you can use/set the locale, it must first be installed on the OS. On most unix systems at least some basic locales are already there, they are just not used. To check what locale are you currently using and what locales are available for you to use, create the file testlocale.php at the root of your website with the following content:


<?php
    echo "<pre>Current locale:\n"
    var_dump(setlocale(LC_ALL, '0'));
    echo "\n\nAvailable locales:\n";
    echo exec('locale -a'); 

Then point your browser to http://yourwebsite/testlocale.php

If your current locale is "C" (and you are on unix), then you will probably get warning after login to the PW admin. What you want to do is change the locale to something that has "UTF-8" or "utf8" in the name of the available locales. In your case you would be looking for something like "sv_SE.UTF-8" or "sv_SE.utf8". Now, there is a chance that Swedish locale is not installed. You can ask your hosting provider to install it for you or use some other UTF-8 locale. On most unix systems I have seen, at least "en_US.UTF-8" or "en_US.utf8" is installed. If even that English locale is not available, then look for "C.UTF-8" or "C.utf8". And this is what you have to use as parameter in the setlocale() call:


setlocale(LC_ALL, "sv_SE.utf8");

You could actually "stack up" multiple locales and one will eventually work:


setlocale(LC_ALL, "sv_SE.utf8", "sv_SE.UTF-8", "en_US.UTF-8", "en_US.utf8", "C.UTF-8", "C.utf8");

Now, regarding where to put that setlocale() call. If you are not using PW multi language capabilities (you don't have Languge Support module installed), then you place setlocale to /site/config.php. That's it. If Language Support module is installed (PW checks for that), you have two options:

  1. Translate the string "C" in LanguageSupport.module for each installed language
  2. Put setlocale() call in /site/init.php

My preferred method is option 1 and this is what PW (Ryan) recommends. See https://processwire.com/api/multi-language-support/code-i18n/ for more info on translating files. Option 1 allows you to set different locale for each of the installed language, while  option 2 allows setting of one locale for all languages. PW will also provide links for the files that needs to be translated in the warning message.

 

Matjazp Thank you so much for giving me these answers.
And explaining everything why this is.

I think i get it now :)

I hope this thread gets pinned by moderators so others can get some use of the info in here.

Again, thank you for your efforts. Its greatly appreciated.

I know a lot of PW but some things still elude me, and i am looking forward to learning more as time goes on.
I love PW and i feel this is the CMF for me.

 

1 person likes this

Share this post


Link to post
Share on other sites

A Followup

This was an interesting conversation by all parties.  What I didn't get was what actual syntax that was put in the /site/config.php file.  While this may not matter to more experienced users, it makes a difference to others.  My sites don't use Multi-Language and I was still confronted with the error that @EyeDentify noted in the original post when updating an existing site to ProcessWire 3.0.55

This is what I put in the /site/config.php file to make error go away

 

/**
* Installer: SetLocale Setting
*
* This is now needed since ProcessWire 3.0.53 to set local information
*
*/

setlocale(LC_ALL, "en_US.utf8");

As @matjazp stated, it doesn't really matter where in the file this goes.  What was confusing to me is that most other settings in the /site/config.php file started with $config and it wasn't clear whether this setting needed to follow that style.  As I said, it may not be important to experienced PHP users, but knowing what to put when confronted with this warning is helpful.

As an aside,  it would also be helpful to know the exact syntax that is needed if using the init or ready files.  Maybe I have missed something in reading all this that should have been clear to me and excuse me if I have.

If what I have used is incorrect, I ask that someone provide the correct format (styling).  Thanks.

3 people like this

Share this post


Link to post
Share on other sites
20 hours ago, cstevensjr said:

A Followup

This was an interesting conversation by all parties.  What I didn't get was what actual syntax that was put in the /site/config.php file.  While this may not matter to more experienced users, it makes a difference to others.  My sites don't use Multi-Language and I was still confronted with the error that @EyeDentify noted in the original post when updating an existing site to ProcessWire 3.0.55

This is what I put in the /site/config.php file to make error go away

 


/**
* Installer: SetLocale Setting
*
* This is now needed since ProcessWire 3.0.53 to set local information
*
*/

setlocale(LC_ALL, "en_US.utf8");

As @matjazp stated, it doesn't really matter where in the file this goes.  What was confusing to me is that most other settings in the /site/config.php file started with $config and it wasn't clear whether this setting needed to follow that style.  As I said, it may not be important to experienced PHP users, but knowing what to put when confronted with this warning is helpful.

As an aside,  it would also be helpful to know the exact syntax that is needed if using the init or ready files.  Maybe I have missed something in reading all this that should have been clear to me and excuse me if I have.

If what I have used is incorrect, I ask that someone provide the correct format (styling).  Thanks.

 

Hello cstevensjr. I Agree that this was very interesting.

 

I ended up using this line at the beginning of my config.php file of my sites before any config options.

setlocale(LC_ALL, "sv_SE.utf8", "sv_SE.UTF-8", "en_US.UTF-8", "en_US.utf8", "C.UTF-8", "C.utf8");

That made the error message disappear for me and has not come back.

As matjzap explained, this makes PHP try all the locales I designated until it finds one that is installed.

Then it will use that first locale that it finds.

I would like to again thank everyone in the PW community that helps me understand this problem and solve it. You are the best.

/EyeDentify

2 people like this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.