Name of the day with I18n

Without a translation, this would get me this afternoon:

Date.today.strftime("%A") 

How do I localize it?

those. "Mardi" if I18n.locale set to fr .

+5
source share
2 answers

You probably have the following in your locale file (s):

 # example with fr fr: date: day_names: [Dimanche, Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi] 

To get today's name, you can do:

 week_day = Date.today.wday # Returns the day of week (0-6, Sunday is zero) I18n.t('date.day_names')[week_day] 

or ultimately

 I18n.l(Date.today, format: '%A') 
+13
source
 l Date.today, format: "%A" 

Will work if you have day_names in your translation file.

+4
source

Source: https://habr.com/ru/post/1235797/


All Articles