[yast-devel] Dates localization in YaST
While writing the YaST Journal module I faced a problem I'm not sure how to solve. I wanted to format a date here: https://github.com/ancorgs/yast-journal/blob/master/src/lib/systemd_journal/... I wanted to mimic the format used by journalctl itself, which in plain English 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. :-) In Rails the i18n gem is used. It offers an "localize" method that deals with date formatting http://www.rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/Base:local... But I don't know how to do it in YaST or if I'm the first one facing the problem. Cheers. -- Ancor González Sosa YaST Team at SUSE Linux GmbH -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
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 solve. I wanted to format a date here: https://github.com/ancorgs/yast-journal/blob/master/src/lib/systemd_journal/...
I wanted to mimic the format used by journalctl itself, which in plain English 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 formatting function strftime() which does support localization. E.g. "%c" conversion specification in strftime() is rendered as "The preferred date and time representation for the current locale." (see "man strftime"). Unfortunately, the Ruby implementation uses hardcoded English format for "%c" which 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 date formatting http://www.rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/Base:local...
But I don't know how to do it in YaST or if I'm the first one facing the problem.
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 13:54:42'") 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 and use "-f" date option. - Use strftime() call in a C Ruby extension. We already do this for locale dependent 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 lower overhead and scales better. [1] http://rxr.whitequark.org/mri/source/ext/date/date_strftime.c?v=2.1.2#217 [2] https://github.com/yast/yast-ruby-bindings/blob/master/src/binary/Builtin.cc... -- Best Regards Ladislav Slezák Yast Developer ------------------------------------------------------------------------ SUSE LINUX, s.r.o. e-mail: lslezak@suse.cz Lihovarská 1060/12 tel: +420 284 028 960 190 00 Prague 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/ -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Wed, 11 Feb 2015 20:19:47 +0100
Ladislav Slezak
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 solve. I wanted to format a date here: https://github.com/ancorgs/yast-journal/blob/master/src/lib/systemd_journal/...
I wanted to mimic the format used by journalctl itself, which in plain English 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 formatting function strftime() which does support localization.
E.g. "%c" conversion specification in strftime() is rendered as "The preferred date and time representation for the current locale." (see "man strftime").
Unfortunately, the Ruby implementation uses hardcoded English format for "%c" which 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 date formatting http://www.rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/Base:local...
But I don't know how to do it in YaST or if I'm the first one facing the problem.
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 13:54:42'")
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 and use "-f" date option.
- Use strftime() call in a C Ruby extension. We already do this for locale dependent 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 lower overhead and scales better.
I agree, second solution should be quite easy to do and good solution. So if we agreed, I can add such method to Yast namespace. Josef
[1] http://rxr.whitequark.org/mri/source/ext/date/date_strftime.c?v=2.1.2#217 [2] https://github.com/yast/yast-ruby-bindings/blob/master/src/binary/Builtin.cc...
--
Best Regards
Ladislav Slezák Yast Developer ------------------------------------------------------------------------ SUSE LINUX, s.r.o. e-mail: lslezak@suse.cz Lihovarská 1060/12 tel: +420 284 028 960 190 00 Prague 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/
-- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On 02/12/2015 11:08 AM, Josef Reidinger wrote:
On Wed, 11 Feb 2015 20:19:47 +0100 Ladislav Slezak
wrote: - Use strftime() call in a C Ruby extension. We already do this for locale dependent 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 lower overhead and scales better.
I agree, second solution should be quite easy to do and good solution. So if we agreed, I can add such method to Yast namespace.
Yes, please.
Josef
[1] http://rxr.whitequark.org/mri/source/ext/date/date_strftime.c?v=2.1.2#217 [2] https://github.com/yast/yast-ruby-bindings/blob/master/src/binary/Builtin.cc...
-- Ancor González Sosa YaST Team at SUSE Linux GmbH -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Wed, Feb 11, 2015 at 06:18:02PM +0100, Ancor Gonzalez Sosa wrote:
While writing the YaST Journal module I faced a problem I'm not sure how to solve. I wanted to format a date here: https://github.com/ancorgs/yast-journal/blob/master/src/lib/systemd_journal/...
I wanted to mimic the format used by journalctl itself, which in plain English 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. :-)
In Rails the i18n gem is used. It offers an "localize" method that deals with date formatting http://www.rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/Base:local...
But I don't know how to do it in YaST or if I'm the first one facing the problem.
No, you are not the first one - I had a bug for SLES 12 (bsc
#878613) where the weekday was not translated. Since Ruby is
stuck in the last millennium concerning localization the simply
solution was to use the ISO format (which does not require
translations).
ciao Arvin
--
Arvin Schnell,
participants (4)
-
Ancor Gonzalez Sosa
-
Arvin Schnell
-
Josef Reidinger
-
Ladislav Slezak