Project

General

Profile

Bug #15839

ikiwiki po switches language environment for building pages

Added by hefee over 1 year ago. Updated 9 months ago.

Status:
Confirmed
Priority:
Normal
Assignee:
-
Category:
Internationalization
Target version:
-
Start date:
08/25/2018
Due date:
% Done:

0%

Feature Branch:
Type of work:
Code
Blueprint:
Starter:
Affected tool:

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.


Related issues

Related to Tails - Feature #14996: Show creation date for blog posts when accessed directly Resolved 11/22/2017

History

#1 Updated by hefee over 1 year ago

  • Related to Feature #14996: Show creation date for blog posts when accessed directly added

#2 Updated by intrigeri over 1 year ago

  • 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 over 1 year ago

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 over 1 year ago

  • Assignee changed from hefee to intrigeri
  • QA Check changed from Info Needed to Dev Needed

#5 Updated by u over 1 year ago

  • 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 about 1 year ago

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.

#!/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);
}

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 10 months ago

  • Status changed from New to Confirmed

#8 Updated by intrigeri 9 months ago

  • Assignee deleted (hefee)
  • QA Check deleted (Info Needed)

Also available in: Atom PDF