Socket
Book a DemoInstallSign in
Socket

ruby-i18n-months

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ruby-i18n-months

bundlerRubygems
Version
1.0.0
Version published
Maintainers
1
Created
Source

ruby-i18n-months

You may use this gem with rails-i18n (although, it's not required).

To install, add to your Gemfile:

gem 'ruby-i18n-months'

This gem add directives %O and %o for month names that are useful in such formats:

FormatEnglishRussian
%O %YMarch 2022Март 2022
%d/%o/%Y23/Mar/202223/март/2022

Compare with these results (using existing directives %B and %b in Ruby and gem rails-i18n):

FormatEnglishRussian
%B %YMarch 2022марта 2022 (this result is incorrect for native speakers)
%d/%b/%Y23/Mar/202223/марта/2022 (sounds odd but is acceptable)

The languages listed below use different words for dates in long format(day, month, year: %d %B %Y) and for month and year only (month, year: %O %Y):

  • Belorussian
  • Greek
  • Polish
  • Russian
  • Ukrainian

This gem adds directives %O and %o in I18n::Backend::Base (used internally in gem ruby-i18n), and adds month names for all languages listed above for these directives.

For Slavic languages these month names are in nominative case, and gem rails-i18n provides month names in genitive case (for directives %B and %b).

Other languages & locales will fallback these directives to %B and %b respectively. In this case you should have gem rails-i18n installed.

Usage

You may use localize method (shorted to l), as usual:

I18n.l(Time.new(2022, 3, 1), locale: :ru, format: '%O %Y')
# => "Март 2022" (provided by this gem, `ruby-i18n-months`)

I18n.l(Time.new(2022, 3, 1), locale: :ru, format: '%-e %B %Y')
# => "1 марта 2022" (provided by gem `rails-i18n`)

I18n.l(Time.new(2022, 3, 1), locale: :en, format: '%O %Y')
# => "March 2022" (provided by this gem, `ruby-i18n-months`,
#    with fallback to `%B`, so you need `rails-i18n` also)

I18n.l(Time.new(2022, 3, 1), locale: :en, format: '%-e %B %Y')
# => "1 March 2022" (provided by gem `rails-i18n`)

Using strftime is not supported:

Time.new(2022, 3, 1).strftime('%O %Y')
# => "%O 2022"

Development

To release a new version: bundle exec rake release

Contributing

Bug reports and pull requests are welcome on GitHub at github.com/crosspath/ruby-i18n-months.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 20 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts