Jump to content

setlocale and multilanguage site


maba
 Share

Recommended Posts

Hi,

in a site with 3 languages (IT - default -, EN and FR) I have date written in english.

So I translate C in

 /wire/modules/LanguageSupport/LanguageSupport.module
 

 for each language but now date are written in IT for EN and FR pages also, logged or guest user.

To change language I use this snippet (with a little problem):

foreach($languages as $language) {
  if(!$page->viewable($language)) continue; // language marked not available
  $url = $page->localUrl($language);
  echo "<a href='$url'>$language->title</a>"; 
}
 

Not possible?

Processwire 2.3 dev

Thanks,

Marco

Link to comment
Share on other sites

Never ever edit anything in wire folder.

You can set that locale in the translation file for the particular language.

The file is: wire--modules--languagesupport--languagesupport-module

Link to comment
Share on other sites

I not edited core file.

I set locale as you suggest, for each language.

Only one locale is setted (of the default language) so I have text in english but date in italian, text in french but date in italian and so on. 

If I change C for IT, eg. fr_FR, I have italian text and french date, english text and french date and so on.

Seems that PW cannot set locale dynamically, like it does for the translated strings, urls, ...

Link to comment
Share on other sites

so I have text in english but date in italian

I don't understand. What you mean with I have? front-end or backend? If you are in backend it will display date in the language your user is set to.

Link to comment
Share on other sites

URL: site.com/eventi (default language is ITA)

 

post-846-0-29133800-1369923392_thumb.png

 

The month (JUN) in correct: GIU

 

then I change the page from switch language menu:

 

URL: site.com/en/events

 

post-846-0-43826100-1369923399_thumb.png

 

The month (JUN) is wrong: it remains GIU but text is translated.

Link to comment
Share on other sites

There seems to be an issue with this how or where this locale gets set. It doesn't seem to recognize the langauge on front end. It always uses the user language set on user profile.

Link to comment
Share on other sites

Well change the language of you user and it will take that locale regardless of the front end language set.

This is more for Ryan to checkout. I have no clue how to make it behave.

Link to comment
Share on other sites

It looks like you have some unnecessary comparison in there (including a == full object comparison), I recommend this instead:

if('en' == $user->language->name) setlocale(LC_ALL, 'en_GB'); 

Generally when comparing one page to another in ProcessWire, you want to compare the IDs: $page1->id == $page2->id; or if you want to compare the objects then use 3 equals so that it's comparing the instance rather than all the properties (per the way PHP works): $page1 === $page2; But in the case above, it wasn't even necessary to compare any objects since all you needed to compare was the name to the string 'en'. 

  • Like 1
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...