Mailinglist Archive: yast-devel (52 mails)

< Previous Next >
Re: [yast-devel] Dates localization in YaST
  • From: Ladislav Slezak <lslezak@xxxxxxx>
  • Date: Wed, 11 Feb 2015 20:19:47 +0100
  • Message-id: <>
Dne 11.2.2015 v 18:18 Ancor Gonzalez Sosa napsal(a):
While writing the YaST Journal module I faced a problem I'm not sure how to
I wanted to format a date here:

I wanted to mimic the format used by journalctl itself, which in plain
would be "%b %d %H:%M:%S". The problem is that using %b is not i18n-friendly.
Obviously the problem goes further, like those crazy US people writing Feb.
1st as
02/01/2015. :-)

The problem is that the Ruby interpreter does not use the standard glibc
function strftime() which does support localization.

E.g. "%c" conversion specification in strftime() is rendered as "The preferred
and time representation for the current locale." (see "man strftime").

Unfortunately, the Ruby implementation uses hardcoded English format for "%c"
does not allow localization, see [1].

It seems that plain Ruby does not support localization much, e.g. even locale
dependent string comparison is missing...

In Rails the i18n gem is used. It offers an "localize" method that deals with

But I don't know how to do it in YaST or if I'm the first one facing the

There are basically two possible solutions:

- Run "date" command and format the time using the external program, e.g.:

SCR.Execute(path(".target.bash_output"), "date +%c -d '2015-01-28

This is suitable just for few date values, starting a new subshell for each
date is
quite ineffective. If you need to format many values then save them to a file
use "-f" date option.

- Use strftime() call in a C Ruby extension. We already do this for locale
string comparison, see Yast.strcoll() implementation in ruby-bindings [2].
Similarly we can add a strftime() wrapper there.

The first solution is simpler but I'd rather prefer the second one as it has
overhead and scales better.



Best Regards

Ladislav Slez√°k
Yast Developer
SUSE LINUX, s.r.o. e-mail: lslezak@xxxxxxx
Lihovarsk√° 1060/12 tel: +420 284 028 960
190 00 Prague 9 fax: +420 284 028 951
Czech Republic
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: yast-devel+owner@xxxxxxxxxxxx

< Previous Next >
Follow Ups