Hi Tom, Success! I'm guessing that I either didn't have the right locales loaded or, had defaulted one as the system locale.
Many thanks to you Tom, and Andrew, for the assistance, very much appreciated!! Craig On Saturday, November 26, 2016 at 6:05:13 PM UTC+1, Tom Keffer wrote: > > It worked for me. Here's my template: > > #errorCatcher Echo > #encoding UTF-8 > <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " > http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml"> > <head profile="http://www.w3.org/2005/10/profile"> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> > </head> > > <body> > > #import locale > > ## Try French: > #set $loc = locale.setlocale(locale.LC_ALL, 'fr_FR.utf8') > <p>Locale is $loc. Current time is $current.dateTime. The day of the week > is $current.dateTime.format("%A")</p> > > ## now try Spanish. > #set $loc = locale.setlocale(locale.LC_ALL, 'es_ES.utf8') > <p>Locale is $loc. Current time is $current.dateTime. The day of the week > is $current.dateTime.format("%A")</p> > > ## ... and US English. > #set $loc = locale.setlocale(locale.LC_ALL, 'en_US.utf8') > <p>Locale is $loc. Current time is $current.dateTime. The day of the week > is $current.dateTime.format("%A")</p> > > </body> > </html> > > This gave the results: > > Locale is fr_FR.utf8. Current time is 24/11/2016 12:05:00. The day of the > week is jeudi > > Locale is es_ES.utf8. Current time is 24/11/16 12:05:00. The day of the > week is jueves > > Locale is en_US.utf8. Current time is 11/24/2016 12:05:00 PM. The day of > the week is Thursday > > > -tk > > > On Sat, Nov 26, 2016 at 7:51 AM, M0GLH <[email protected] <javascript:>> > wrote: > >> Hi Tom, >> >> Many thanks for the suggestion but frustratingly, no luck. I've tried >> this, along with declaring FR, NL and EN locales in the OS as a group, and >> then each individually, however none of the functional language definitions >> or variations declared in the locale.setlocale statement overrides the >> declared global locale (language) as dateTime calls always returned the >> current OS locale values. >> >> For what it's worth, when a locale other than en_US is set as the system >> default, Weewx wouldn't start: >> >> Nov 26 10:54:07 Wx systemd[1]: Starting LSB: weewx weather system... >> >> Nov 26 10:54:08 Wx weewx[3519]: Starting weewx weather system: >> weewxTraceback (most recent call last): >> >> Nov 26 10:54:08 Wx weewx[3519]: File "/usr/bin/weewxd", line 12, in >> <module> >> >> Nov 26 10:54:08 Wx weewx[3519]: import user.extensions >> #@UnusedImport >> >> Nov 26 10:54:08 Wx weewx[3519]: File >> "/usr/share/weewx/user/extensions.py", line 18, in <module> >> >> Nov 26 10:54:08 Wx weewx[3519]: locale.setlocale(locale.LC_ALL, '') >> >> Nov 26 10:54:08 Wx weewx[3519]: File "/usr/lib/python2.7/locale.py", line >> 579, in setlocale >> >> Nov 26 10:54:08 Wx weewx[3519]: return _setlocale(category, locale) >> >> Nov 26 10:54:08 Wx weewx[3519]: locale.Error: unsupported locale setting >> >> Nov 26 10:54:08 Wx weewx[3519]: failed! >> >> Nov 26 10:54:08 Wx systemd[1]: weewx.service: control process exited, >> code=exited status=1 >> >> Nov 26 10:54:08 Wx systemd[1]: Failed to start LSB: weewx weather system. >> Nov 26 10:54:08 Wx systemd[1]: Unit weewx.service entered failed state. >> >> Not sure what to try next, perhaps a separate Pi for each language? >> >> Craig >> >> >> >> >> >> >> >> >> >> >> On Saturday, November 26, 2016 at 2:30:40 AM UTC+1, Tom Keffer wrote: >>> >>> Darned good question, and I'm not sure I know the answer. >>> >>> Because the Cheetah template engine allows you to include Python code, >>> one thing you could try is to set the desired locale at the top of the >>> template. Something like >>> >>> #import locale >>> #locale.setlocale(locale.LC_ALL, 'fr_FR.utf8') >>> >>> ## Hopefully this is in french! >>> $current.dateTime >>> >>> >>> I'm not sure if this will work, because I'm not sure exactly when the >>> binding happens for Python included in the template. I assume (and hope!) >>> that it's early, so this would work. >>> >>> Give it a try. >>> >>> -tk >>> >>> On Fri, Nov 25, 2016 at 3:08 PM, M0GLH <[email protected]> wrote: >>> >>>> I’m running v3.6.1 deb on an RPi 2 with a Vantage Pro 2 and have built >>>> Dutch and English versions of the web pages, but I’m having problems with >>>> default languages (environment locale) and tags that return dateTime >>>> values. >>>> >>>> >>>> The OS environment locale is set to GB English by default, mainly for >>>> my convenience, but I want Weewx to generate web pages in both Dutch and >>>> English, with date related names correct for each language. Localising >>>> text in the templates and skins is dead easy, but how can I separately >>>> define a language variable for tags which return dateTime values (e.g. >>>> week.*****.minTime >>>> or month.*****.maxTime) so that these are correct for the language of >>>> the particular skin and templates it appears in, for example, Monday on >>>> English pages, Maandag on Dutch pages, and Lundi on French pages. >>>> >>>> >>>> I have two different skins, each with a full set of templates. I plan >>>> on adding a third set in French, and I want date presentations in each to >>>> match that page's language. If I change the default environment locale, >>>> *all >>>> *labels which use locale are generated in that language which will be >>>> incorrect for one or more of the three languages. >>>> >>>> >>>> Thanks! >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "weewx-user" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "weewx-user" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "weewx-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
