Bug #15839
ikiwiki po switches language environment for building pages
0%
Description
For having localized numbers and dates po plugin should switch the complete languages envionment.
An example would be, that we can “just” use “%x” for dates for prettydate plugin.
But I’m not sure how much work this is and if it is worth invest time. As workaround we use YYYY-MM-DD for dates.
I think this will get more an issue if we have more not European languages.
Subtasks
Related issues
Related to Tails - |
Resolved | 2017-11-22 |
History
#1 Updated by hefee 2018-08-25 09:51:51
- related to
Feature #14996: Show creation date for blog posts when accessed directly added
#2 Updated by intrigeri 2018-08-26 06:02:59
- Assignee changed from intrigeri to hefee
Can you please point me to a couple example pieces of code that should ideally be executed in a different language env?
#3 Updated by hefee 2018-08-26 17:49:39
intrigeri wrote:
> Can you please point me to a couple example pieces of code that should ideally be executed in a different language env?
like I said - the complete prettydate plugin should have the correct languages settings, so that you can use %x or the localized month names in dates. At least for python format string %x tells to format the date like you expect for you localization. This is so far the only place I know we would benefit from it now. At the moment prettydate don’t know about the actualy localization, when rendering the date.
#4 Updated by hefee 2018-08-26 17:50:00
- Assignee changed from hefee to intrigeri
- QA Check changed from Info Needed to Dev Needed
#5 Updated by Anonymous 2018-09-03 08:08:05
- Assignee changed from intrigeri to hefee
- QA Check changed from Dev Needed to Info Needed
@hefee: is this an upstream issue then or is this related to how we use the plugin in Tails and when yes where?
#6 Updated by intrigeri 2018-09-19 16:07:31
> like I said - the complete prettydate plugin should have the correct languages settings, so that you can use %x or the localized month names in dates.
OK, I think I understood: you would like the ikiwiki (Perl) process to switch its current locale on the fly, depending on the language of the page it’s building, so that things like %x
honor this locale.
It seems to be doable but only when using POSIX::strftime
, or at least I did not manage to make it work with Date::Format
’s strftime
which is used by the prettydate plugin.
<code class="perl">
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use 5.10.1;
use Date::Format;
use POSIX ();
my @t = localtime(time);
for my $locale (qw{de_DE.UTF-8 fr_FR.UTF-8 en_US.UTF-8}) {
say "locale: $locale";
my $orig_lc_time=POSIX::setlocale(&POSIX::LC_TIME);
POSIX::setlocale(&POSIX::LC_TIME, $locale);
$ENV{LC_TIME} = $locale;
say 'with Date::Format::strftime: ', strftime('%x', @t);
say 'with POSIX::strftime: ', POSIX::strftime('%x', @t);
POSIX::setlocale(&POSIX::LC_TIME, $orig_lc_time);
}
</code>
Output:
locale: de_DE.UTF-8
with Date::Format::strftime: 09/19/18
with POSIX::strftime: 19.09.2018
locale: fr_FR.UTF-8
with Date::Format::strftime: 09/19/18
with POSIX::strftime: 19/09/2018
locale: en_US.UTF-8
with Date::Format::strftime: 09/19/18
with POSIX::strftime: 09/19/2018
Now, the prettydate plugin has no clue about the po plugin, so to achieve that, I think the po plugin needs to monkeypatch prettydate’s version of IkiWiki::formattime
to wrap it with the env mangling back’n’forth. The inject
facility might be enough. Could be relatively easy, could be hard.
> At least for python format string %x tells to format the date like you expect for you localization.
Sounds interesting! Just curious and mostly OT (except it could possibly suggest a nice, field-tested API): any example of how this works for switching between multiple locales in the same process?
#7 Updated by mercedes508 2019-01-27 15:12:32
- Status changed from New to Confirmed
#8 Updated by intrigeri 2019-03-08 14:56:50
- Assignee deleted (
hefee) - QA Check deleted (
Info Needed)