ruby-i18n-months 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cd89140992d4cb7931b808f4b2f55ecac48f8b73820ba1032d292339c35fc287
4
+ data.tar.gz: 34dfea6f3027f962aa8a18db088bf210cc3e7aea81d8ddb1f09ed68bd21528c2
5
+ SHA512:
6
+ metadata.gz: 64caeb468aa8a08f5d0c1fac4a7df1b110d381fcca52bc46babfcd752a5b809352a889a26f12730ed762be1d0fe997b640dfa3d675e4677d277e203309fad888
7
+ data.tar.gz: c4b7d1f41e6cc462360eeeda8064426b7e73003ceb3d776f08036fb558833bd04d7d51774a409e28c068fca51b60446713534ff1131f350e5e51734f46eecc90
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [1.0.0] - 2021-08-20
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ruby-i18n-months.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # ruby-i18n-months
2
+
3
+ You may use this gem with `rails-i18n` (although, it's not required).
4
+
5
+ To install, add to your `Gemfile`:
6
+
7
+ ```ruby
8
+ gem 'ruby-i18n-months'
9
+ ```
10
+
11
+ This gem add directives `%O` and `%o` for month names that are useful in such formats:
12
+
13
+ Format | English | Russian
14
+ -----------|-------------|--------
15
+ `%O %Y` | March 2022 | Март 2022
16
+ `%d/%o/%Y` | 23/Mar/2022 | 23/март/2022
17
+
18
+ Compare with these results (using existing directives `%B` and `%b` in Ruby and gem `rails-i18n`):
19
+
20
+ Format | English | Russian
21
+ -----------|-------------|--------
22
+ `%B %Y` | March 2022 | марта 2022 (this result is incorrect for native speakers)
23
+ `%d/%b/%Y` | 23/Mar/2022 | 23/марта/2022 (sounds odd but is acceptable)
24
+
25
+ The languages listed below use different words
26
+ for dates in long format(`day, month, year`: `%d %B %Y`)
27
+ and for month and year only (`month, year`: `%O %Y`):
28
+
29
+ - Belorussian
30
+ - Greek
31
+ - Polish
32
+ - Russian
33
+ - Ukrainian
34
+
35
+ This gem adds directives `%O` and `%o` in `I18n::Backend::Base`
36
+ (used internally in gem `ruby-i18n`), and adds month names for all languages listed
37
+ above for these directives.
38
+
39
+ For Slavic languages these month names are in nominative case,
40
+ and gem `rails-i18n` provides month names in genitive case
41
+ (for directives `%B` and `%b`).
42
+
43
+ Other languages & locales will fallback these directives to `%B` and `%b` respectively.
44
+ In this case you should have gem `rails-i18n` installed.
45
+
46
+ ## Usage
47
+
48
+ You may use `localize` method (shorted to `l`), as usual:
49
+
50
+ ```ruby
51
+ I18n.l(Time.new(2022, 3, 1), locale: :ru, format: '%O %Y')
52
+ # => "Март 2022" (provided by this gem, `ruby-i18n-months`)
53
+
54
+ I18n.l(Time.new(2022, 3, 1), locale: :ru, format: '%-e %B %Y')
55
+ # => "1 марта 2022" (provided by gem `rails-i18n`)
56
+
57
+ I18n.l(Time.new(2022, 3, 1), locale: :en, format: '%O %Y')
58
+ # => "March 2022" (provided by this gem, `ruby-i18n-months`,
59
+ # with fallback to `%B`, so you need `rails-i18n` also)
60
+
61
+ I18n.l(Time.new(2022, 3, 1), locale: :en, format: '%-e %B %Y')
62
+ # => "1 March 2022" (provided by gem `rails-i18n`)
63
+ ```
64
+
65
+ Using `strftime` is not supported:
66
+
67
+ ```ruby
68
+ Time.new(2022, 3, 1).strftime('%O %Y')
69
+ # => "%O 2022"
70
+ ```
71
+
72
+ ## Development
73
+
74
+ To release a new version: `bundle exec rake release`
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at
79
+ [github.com/crosspath/ruby-i18n-months](https://github.com/crosspath/ruby-i18n-months).
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the
84
+ [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "ruby-i18n-months"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'i18n'
4
+
5
+ require_relative 'ruby-i18n-months/i18n-patch'
6
+ require_relative 'ruby-i18n-months/version'
7
+
8
+ if defined?(Rails)
9
+ ActiveSupport::Reloader.to_prepare do
10
+ I18n.load_path << File.expand_path('ruby-i18n-months/translations.yml', __dir__)
11
+ end
12
+ else
13
+ I18n.load_path << File.expand_path('ruby-i18n-months/translations.yml', __dir__)
14
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Sorry, we cannot use `Module#prepend` in `I18n::Backend::Base` because
4
+ # prepended module isn't added to the inheritance chain of `I18n::Backend::Simple`.
5
+ I18n::Backend::Base.module_eval do
6
+ def translate_localization_format_with_months(locale, object, format, options)
7
+ res = format.to_s.gsub(/%[#^]?[Oo]/) do |match|
8
+ case match
9
+ when '%o', '%#o', '%^o'
10
+ begin
11
+ val = I18n.t!(:"date.single_abbr_month_names", locale: locale, format: format)[object.mon]
12
+ case match
13
+ when '%o' then val
14
+ when '%#o' then val.swapcase
15
+ when '%^o' then val.upcase
16
+ end
17
+ rescue I18n::MissingTranslationData => e
18
+ '%b'
19
+ end
20
+ when '%O', '%#O', '%^O'
21
+ begin
22
+ val = I18n.t!(:"date.single_month_names", locale: locale, format: format)[object.mon]
23
+ case match
24
+ when '%O' then val
25
+ when '%#O' then val.swapcase
26
+ when '%^O' then val.upcase
27
+ end
28
+ rescue I18n::MissingTranslationData => e
29
+ '%B'
30
+ end
31
+ end
32
+ end
33
+
34
+ translate_localization_format_without_months(locale, object, res, options)
35
+ end
36
+
37
+ alias_method :translate_localization_format_without_months, :translate_localization_format
38
+ alias_method :translate_localization_format, :translate_localization_format_with_months
39
+ end
@@ -0,0 +1,228 @@
1
+ # TODO: Native speaker's review required (Belorussian)
2
+ be:
3
+ date:
4
+ abbr_month_names:
5
+ -
6
+ - сту
7
+ - лют
8
+ - сак
9
+ - кра
10
+ - тра
11
+ - чэр
12
+ - ліп
13
+ - жні
14
+ - вер
15
+ - кас
16
+ - ліс
17
+ - сне
18
+ # Lower case + changed word endings
19
+ month_names:
20
+ -
21
+ - студзеня
22
+ - лютага
23
+ - сакавіка
24
+ - красавіка
25
+ - травеня
26
+ - чэрвеня
27
+ - ліпеня
28
+ - жніўня
29
+ - верасня
30
+ - кастрычніка
31
+ - лістапада
32
+ - снежня
33
+ # Same as `abbr_month_names` in `rails-i18n`.
34
+ single_abbr_month_names:
35
+ -
36
+ - Сту
37
+ - Лют
38
+ - Сак
39
+ - Кра
40
+ - Тра
41
+ - Чэр
42
+ - Ліп
43
+ - Жні
44
+ - Вер
45
+ - Кас
46
+ - Ліс
47
+ - Сне
48
+ # Same as `month_names` in `rails-i18n`.
49
+ single_month_names:
50
+ -
51
+ - Студзень
52
+ - Люты
53
+ - Сакавік
54
+ - Красавік
55
+ - Травень
56
+ - Чэрвень
57
+ - Ліпень
58
+ - Жнівень
59
+ - Верасень
60
+ - Кастрычнік
61
+ - Лістапад
62
+ - Снежань
63
+
64
+ # TODO: Native speaker's review required (Greek)
65
+ el:
66
+ date:
67
+ # Changed word ending from 'ιος' to 'ίου'.
68
+ month_names:
69
+ -
70
+ - Ιανουαρίου
71
+ - Φεβρουαρίου
72
+ - Μαρτίου
73
+ - Απριλίου
74
+ - Μαΐου
75
+ - Ιουνίου
76
+ - Ιουλίου
77
+ - Αυγούστου
78
+ - Σεπτεμβρίου
79
+ - Οκτωβρίου
80
+ - Νοεμβρίου
81
+ - Δεκεμβρίου
82
+ # Same as `abbr_month_names` in `rails-i18n`.
83
+ single_abbr_month_names:
84
+ -
85
+ - Ιαν
86
+ - Φεβ
87
+ - Μαρ
88
+ - Απρ
89
+ - Μαΐ
90
+ - Ιουν
91
+ - Ιουλ
92
+ - Αυγ
93
+ - Σεπ
94
+ - Οκτ
95
+ - Νοε
96
+ - Δεκ
97
+ # Same as `month_names` in `rails-i18n`.
98
+ single_month_names:
99
+ -
100
+ - Ιανουάριος
101
+ - Φεβρουάριος
102
+ - Μάρτιος
103
+ - Απρίλιος
104
+ - Μάιος
105
+ - Ιούνιος
106
+ - Ιούλιος
107
+ - Αύγουστος
108
+ - Σεπτέμβριος
109
+ - Οκτώβριος
110
+ - Νοέμβριος
111
+ - Δεκέμβριος
112
+
113
+ # TODO: Native speaker's review required (Polish)
114
+ pl:
115
+ date:
116
+ # Same as `abbr_month_names` in `rails-i18n`.
117
+ single_abbr_month_names:
118
+ -
119
+ - sty
120
+ - lut
121
+ - mar
122
+ - kwi
123
+ - maj
124
+ - cze
125
+ - lip
126
+ - sie
127
+ - wrz
128
+ - paź
129
+ - lis
130
+ - gru
131
+ # Nominative case and first letter in upper case
132
+ single_month_names:
133
+ -
134
+ - Styczeń
135
+ - Luty
136
+ - Marzec
137
+ - Kwiecień
138
+ - Maj
139
+ - Czerwiec
140
+ - Lipiec
141
+ - Sierpień
142
+ - Wrzesień
143
+ - Październik
144
+ - Listopad
145
+ - Grudzień
146
+
147
+ # Russian
148
+ ru:
149
+ date:
150
+ # Nominative case and no dot at the end
151
+ single_abbr_month_names:
152
+ -
153
+ - янв
154
+ - фев
155
+ - март
156
+ - апр
157
+ - май
158
+ - июнь
159
+ - июль
160
+ - авг
161
+ - сент
162
+ - окт
163
+ - нояб
164
+ - дек
165
+ # Nominative case and first letter in upper case
166
+ single_month_names:
167
+ -
168
+ - Январь
169
+ - Февраль
170
+ - Март
171
+ - Апрель
172
+ - Май
173
+ - Июнь
174
+ - Июль
175
+ - Август
176
+ - Сентябрь
177
+ - Октябрь
178
+ - Ноябрь
179
+ - Декабрь
180
+
181
+ # TODO: Native speaker's review required (Ukrainian)
182
+ uk:
183
+ date:
184
+ # Lower case
185
+ month_names:
186
+ -
187
+ - січня
188
+ - лютого
189
+ - березня
190
+ - квітня
191
+ - травня
192
+ - червня
193
+ - липня
194
+ - серпня
195
+ - вересня
196
+ - жовтня
197
+ - листопада
198
+ - грудня
199
+ # No dot at the end
200
+ single_abbr_month_names:
201
+ -
202
+ - січ
203
+ - лют
204
+ - бер
205
+ - квіт
206
+ - трав
207
+ - черв
208
+ - лип
209
+ - серп
210
+ - вер
211
+ - жовт
212
+ - лист
213
+ - груд
214
+ # Nominative case + lower case
215
+ single_month_names:
216
+ -
217
+ - Січень
218
+ - Лютий
219
+ - Березень
220
+ - Квітень
221
+ - Травень
222
+ - Червень
223
+ - Липень
224
+ - Серпень
225
+ - Вересень
226
+ - Жовтень
227
+ - Листопад
228
+ - Грудень
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyI18nMonths
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/ruby-i18n-months/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ruby-i18n-months'
7
+ spec.version = RubyI18nMonths::VERSION
8
+ spec.authors = ['Evgeniy Nochevnov']
9
+
10
+ spec.summary = <<~TEXT
11
+ Format dates for that languages that use different words for months in formats like "23rd april of 2022" and "April 2022"'
12
+ TEXT
13
+
14
+ spec.description = <<~TEXT
15
+ Format dates with added directives "%O" and "%o" for months without days. Some languages use different words for month names in formats like "23rd april of 2022" and "April 2022". These languages are Russian, Ukrainian, Greek and others.
16
+ TEXT
17
+
18
+ spec.homepage = 'https://github.com/crosspath/ruby-i18n-months'
19
+ spec.license = 'MIT'
20
+
21
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
22
+
23
+ spec.metadata['homepage_uri'] = spec.homepage
24
+ spec.metadata['source_code_uri'] = spec.homepage
25
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|\.github)/}) }
31
+ end
32
+
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+
37
+ spec.add_dependency('i18n', '>= 0.8.0')
38
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-i18n-months
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Evgeniy Nochevnov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-08-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.0
27
+ description: 'Format dates with added directives "%O" and "%o" for months without
28
+ days. Some languages use different words for month names in formats like "23rd april
29
+ of 2022" and "April 2022". These languages are Russian, Ukrainian, Greek and others.
30
+
31
+ '
32
+ email:
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - ".gitignore"
38
+ - CHANGELOG.md
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - lib/ruby-i18n-months.rb
46
+ - lib/ruby-i18n-months/i18n-patch.rb
47
+ - lib/ruby-i18n-months/translations.yml
48
+ - lib/ruby-i18n-months/version.rb
49
+ - ruby-i18n-months.gemspec
50
+ homepage: https://github.com/crosspath/ruby-i18n-months
51
+ licenses:
52
+ - MIT
53
+ metadata:
54
+ homepage_uri: https://github.com/crosspath/ruby-i18n-months
55
+ source_code_uri: https://github.com/crosspath/ruby-i18n-months
56
+ changelog_uri: https://github.com/crosspath/ruby-i18n-months/blob/master/CHANGELOG.md
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.3.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.2.15
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Format dates for that languages that use different words for months in formats
76
+ like "23rd april of 2022" and "April 2022"'
77
+ test_files: []