From 3abcaee07a810f4b2e0bd96dc113473bed38cfcc Mon Sep 17 00:00:00 2001 From: Viktor Date: Sat, 9 Dec 2023 18:47:10 -0300 Subject: [PATCH 01/10] Specify Rails 7.1+ gem version --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81bfffb9..ba9b7bd9 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Centralization of locale data collection for Ruby on Rails. Include the gem to your Gemfile: ``` ruby -gem 'rails-i18n', '~> 7.0.0' # For 7.0.0 +gem 'rails-i18n', '~> 7.0.0' # For Rails >= 7.0.0 gem 'rails-i18n', '~> 6.0' # For 6.x gem 'rails-i18n', '~> 5.1' # For 5.0.x, 5.1.x and 5.2.x gem 'rails-i18n', '~> 4.0' # For 4.0.x @@ -24,7 +24,7 @@ gem 'rails-i18n', github: 'svenfuchs/rails-i18n', branch: 'rails-3-x' # For 3.x Alternatively, execute the following command: ``` shell -gem install rails-i18n -v '~> 7.0.0' # For 7.0.0 +gem install rails-i18n -v '~> 7.0.0' # For Rails >= 7.0.0 gem install rails-i18n -v '~> 6.0' # For 6.x gem install rails-i18n -v '~> 5.1' # For For 5.0.x, 5.1.x and 5.2.x gem install rails-i18n -v '~> 4.0' # For 4.0.x From bb77a5de1c4e3727078e8fd6c66ba81721101e03 Mon Sep 17 00:00:00 2001 From: bondee <38813699+kimdj2@users.noreply.github.com> Date: Wed, 31 Jan 2024 20:29:07 +0900 Subject: [PATCH 02/10] Add missing key (storage units) --- rails/locale/ko.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rails/locale/ko.yml b/rails/locale/ko.yml index e0ace3b1..2deda785 100644 --- a/rails/locale/ko.yml +++ b/rails/locale/ko.yml @@ -156,9 +156,11 @@ ko: format: "%n%u" units: byte: 바이트 + eb: EB gb: GB kb: KB mb: MB + pb: PB tb: TB percentage: format: From 39dd01edfc523c632cccc06838621b4f7ee79087 Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Fri, 19 Apr 2024 17:49:57 +0300 Subject: [PATCH 03/10] Added missing translations --- rails/locale/lt.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rails/locale/lt.yml b/rails/locale/lt.yml index 2c103ede..2bc4a158 100644 --- a/rails/locale/lt.yml +++ b/rails/locale/lt.yml @@ -107,6 +107,9 @@ lt: one: "%{count} mėnesis" few: "%{count} mėnesiai" other: "%{count} mėnesių" + x_years: + one: "%{count} metai" + other: "%{count} metai" prompts: second: Sekundės minute: Minutė @@ -126,15 +129,18 @@ lt: exclusion: yra rezervuotas greater_than: turi būti didesnis už %{count} greater_than_or_equal_to: turi būti didesnis arba lygus %{count} + in: turi būti skaičiuje %{count} inclusion: nenumatyta reikšmė invalid: neteisingas less_than: turi būti mažesnis už %{count} less_than_or_equal_to: turi būti mažesnis arba lygus %{count} + model_invalid: 'Tikrinimo klaida: %{errors}' not_a_number: ne skaičius not_an_integer: privalo būti sveikas skaičius odd: turi būti nelyginis skaičius other_than: privalo būti kitoks nei %{count} present: turi būti tuščias + required: turi egzistuoti taken: jau užimtas too_long: one: per ilgas (daugiausiai %{count} simbolis) @@ -171,6 +177,7 @@ lt: format: delimiter: " " precision: 3 + round_mode: default separator: "," significant: false strip_insignificant_zeros: false @@ -196,9 +203,11 @@ lt: one: Baitas few: Baitai other: Baitų + eb: EB gb: GB kb: KB mb: MB + pb: PB tb: TB percentage: format: From 39430951926a8193d1f4a093bedddbd9e8079bcf Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Sat, 20 Apr 2024 10:39:12 +0300 Subject: [PATCH 04/10] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c6c58b1..5615ff94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ ## unreleased +- Update following locales: + - Lithuanian (lt): Add missing keys (`x_years`, `in`, `model_invalid`, `required`, `round_mode`, `eb`, `pb`) ## 7.0.9 (2024-03-13) From 5693452bb68768323032fdfba2f75c6e695f7224 Mon Sep 17 00:00:00 2001 From: bondee <38813699+kimdj2@users.noreply.github.com> Date: Tue, 18 Jun 2024 09:13:04 +0900 Subject: [PATCH 05/10] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3aef195..1cfa0053 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## unreleased - Update following locales: - Portuguese (pt): Fixed `number.currency.format.format` and `helpers.submit.update` #1122 + - Korean (ko): Add missing keys (Storage units) #1118 - Fix compatibility with frozen string literals. #1120 ## 7.0.9 (2024-03-13) From 12ff3d35b0749ca016f73339989b519bc1619c5b Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Tue, 18 Jun 2024 08:40:23 +0300 Subject: [PATCH 06/10] Update lt.yml lt.datetime.distance_in_words.x_years.few --- rails/locale/lt.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/rails/locale/lt.yml b/rails/locale/lt.yml index 2bc4a158..4af2671a 100644 --- a/rails/locale/lt.yml +++ b/rails/locale/lt.yml @@ -109,6 +109,7 @@ lt: other: "%{count} mėnesių" x_years: one: "%{count} metai" + few: "%{count} metai" other: "%{count} metai" prompts: second: Sekundės From c23708e1ec1db00cac21fe7aec58c55bcc956d2a Mon Sep 17 00:00:00 2001 From: Olle Jonsson Date: Mon, 29 Jul 2024 12:18:22 +0200 Subject: [PATCH 07/10] gemspec: Prefer the "add_dependency" method --- rails-i18n.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rails-i18n.gemspec b/rails-i18n.gemspec index 498d7f38..7a21dc64 100644 --- a/rails-i18n.gemspec +++ b/rails-i18n.gemspec @@ -15,8 +15,8 @@ Gem::Specification.new do |s| s.require_path = 'lib' s.required_rubygems_version = '>= 1.8.11' - s.add_runtime_dependency('i18n', '>= 0.7', '< 2') - s.add_runtime_dependency('railties', '>= 6.0.0', '< 8') + s.add_dependency('i18n', '>= 0.7', '< 2') + s.add_dependency('railties', '>= 6.0.0', '< 8') s.add_development_dependency "rspec-rails", "~> 3.7" s.add_development_dependency "i18n-spec", "~> 0.6.0" s.add_development_dependency 'i18n-tasks', '~> 0.9.37' From c9c65cb3e9a5b3fa73ff988bae8c17bb24a5fe26 Mon Sep 17 00:00:00 2001 From: Marin Rukavina Date: Tue, 13 Aug 2024 11:50:25 +0200 Subject: [PATCH 08/10] Croatian (hr): month names and weekday abbreviations Use genitive case for formatting month names, such as: "13. kolovoza 2024." Use a period after abbreviation names, as is orthographically correct. --- CHANGELOG.md | 1 + rails/locale/hr.yml | 62 ++++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3aef195..6772bcb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## unreleased - Update following locales: - Portuguese (pt): Fixed `number.currency.format.format` and `helpers.submit.update` #1122 + - Croatian (hr): use genitive case for month names and put a period after weekday and month abbreviations #1126 - Fix compatibility with frozen string literals. #1120 ## 7.0.9 (2024-03-13) diff --git a/rails/locale/hr.yml b/rails/locale/hr.yml index 6568f46f..aaf8f2a8 100644 --- a/rails/locale/hr.yml +++ b/rails/locale/hr.yml @@ -9,27 +9,27 @@ hr: has_many: Nije moguće izbrisati zapis jer postoje ovisni %{record} date: abbr_day_names: - - ned - - pon - - uto - - sri - - čet - - pet - - sub + - ned. + - pon. + - uto. + - sri. + - čet. + - pet. + - sub. abbr_month_names: - - - sij - - velj - - ožu - - tra - - svi - - lip - - srp - - kol - - ruj - - lis - - stu - - pro + - sij. + - velj. + - ožu. + - tra. + - svi. + - lip. + - srp. + - kol. + - ruj. + - lis. + - stu. + - pro. day_names: - nedjelja - ponedjeljak @@ -44,18 +44,18 @@ hr: short: "%e.%-m." month_names: - - - siječanj - - veljača - - ožujak - - travanj - - svibanj - - lipanj - - srpanj - - kolovoz - - rujan - - listopad - - studeni - - prosinac + - siječnja + - veljače + - ožujka + - travnja + - svibnja + - lipnja + - srpnja + - kolovoza + - rujna + - listopada + - studenoga + - prosinca order: - :day - :month From 0571e9704daa40cb1e97d5dc77141f7f620294ec Mon Sep 17 00:00:00 2001 From: digitalfrost Date: Mon, 16 Sep 2024 00:12:29 +0200 Subject: [PATCH 09/10] Remove punctuation mark in date No punctuation marks are used in Turkish when writing dates. Fixes #1116 --- rails/locale/tr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rails/locale/tr.yml b/rails/locale/tr.yml index 95088837..cceaec24 100644 --- a/rails/locale/tr.yml +++ b/rails/locale/tr.yml @@ -40,7 +40,7 @@ tr: - Cumartesi formats: default: "%d.%m.%Y" - long: "%e %B %Y, %A" + long: "%e %B %Y %A" short: "%e %b" month_names: - From 8b32b36dd073238bc4612553cb6c17db214dfa60 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 18 Sep 2024 16:27:55 -0400 Subject: [PATCH 10/10] Fix method redefinition warnings when pluralizations are reloaded Fix: https://github.com/svenfuchs/rails-i18n/issues/735 Whenever pluralization rules are reloaded it causes a lot of warnings: ``` lib/rails_i18n/../../rails/pluralization/ar.rb:4: warning: method redefined; discarding old rule lib/rails_i18n/../../rails/pluralization/ar.rb:4: warning: previous definition of rule was here lib/rails_i18n/../../rails/pluralization/gd.rb:4: warning: method redefined; discarding old rule lib/rails_i18n/../../rails/pluralization/gd.rb:4: warning: previous definition of rule was here lib/rails_i18n/../../rails/pluralization/hsb.rb:4: warning: method redefined; discarding old rule lib/rails_i18n/../../rails/pluralization/hsb.rb:4: warning: previous definition of rule was here lib/rails_i18n/../../rails/pluralization/lt.rb:4: warning: method redefined; discarding old rule lib/rails_i18n/../../rails/pluralization/lt.rb:4: warning: previous definition of rule was here lib/rails_i18n/../../rails/pluralization/lv.rb:4: warning: method redefined; discarding old rule lib/rails_i18n/../../rails/pluralization/lv.rb:4: warning: previous definition of rule was here lib/rails_i18n/../../rails/pluralization/mk.rb:4: warning: method redefined; discarding old rule lib/rails_i18n/../../rails/pluralization/mk.rb:4: warning: previous definition of rule was here lib/rails_i18n/../../rails/pluralization/pl.rb:4: warning: method redefined; discarding old rule lib/rails_i18n/../../rails/pluralization/pl.rb:4: warning: previous definition of rule was here lib/rails_i18n/../../rails/pluralization/sl.rb:4: warning: method redefined; discarding old rule lib/rails_i18n/../../rails/pluralization/sl.rb:4: warning: previous definition of rule was here ... ``` This is mostly harmless, but annoying for users who try to run with no warnings at all. --- CHANGELOG.md | 3 +- lib/rails_i18n/pluralization.rb | 143 ++++++++++++++++++++++ lib/rails_i18n/transliteration.rb | 191 ++++++++++++++++++++++++++++++ rails/pluralization/ar.rb | 28 +---- rails/pluralization/gd.rb | 24 +--- rails/pluralization/hsb.rb | 21 +--- rails/pluralization/lt.rb | 23 +--- rails/pluralization/lv.rb | 16 +-- rails/pluralization/mk.rb | 16 +-- rails/pluralization/pl.rb | 25 +--- rails/pluralization/sl.rb | 19 +-- rails/transliteration/ru.rb | 89 +------------- rails/transliteration/uk.rb | 109 +---------------- 13 files changed, 346 insertions(+), 361 deletions(-) create mode 100644 lib/rails_i18n/pluralization.rb create mode 100644 lib/rails_i18n/transliteration.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 914bcb9d..c7e01da5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ - Portuguese (pt): Fixed `number.currency.format.format` and `helpers.submit.update` #1122 - Croatian (hr): use genitive case for month names and put a period after weekday and month abbreviations #1126 - Korean (ko): Add missing keys (Storage units) #1118 - - Fix compatibility with frozen string literals. #1120 +- Fix compatibility with frozen string literals. #1120 +- Refactor translations implemented in Ruby to avoid method redefinition warnings on reload. #1128 ## 7.0.9 (2024-03-13) diff --git a/lib/rails_i18n/pluralization.rb b/lib/rails_i18n/pluralization.rb new file mode 100644 index 00000000..becbcb3f --- /dev/null +++ b/lib/rails_i18n/pluralization.rb @@ -0,0 +1,143 @@ +module RailsI18n + module Pluralization + module Arabic + def self.rule + lambda do |n| + return :other unless n.is_a?(Numeric) + + mod100 = n % 100 + + if n == 0 + :zero + elsif n == 1 + :one + elsif n == 2 + :two + elsif (3..10).to_a.include?(mod100) + :few + elsif (11..99).to_a.include?(mod100) + :many + else + :other + end + end + end + end + + module ScottishGaelic + def self.rule + lambda do |n| + return :other unless n.is_a?(Numeric) + + floorn = n.floor + + if floorn == 1 || floorn == 11 + :one + elsif floorn == 2 || floorn == 12 + :two + elsif (3..19).member?(floorn) + :few + else + :other + end + end + end + end + + module UpperSorbian + def self.rule + lambda do |n| + return :other unless n.is_a?(Numeric) + + mod100 = n % 100 + + case mod100 + when 1 then :one + when 2 then :two + when 3, 4 then :few + else :other + end + end + end + end + + module Lithuanian + def self.rule + lambda do |n| + return :other unless n.is_a?(Numeric) + + mod10 = n % 10 + mod100 = n % 100 + + if mod10 == 1 && !(11..19).to_a.include?(mod100) + :one + elsif (2..9).to_a.include?(mod10) && !(11..19).to_a.include?(mod100) + :few + else + :other + end + end + end + end + + module Latvian + def self.rule + lambda do |n| + if n.is_a?(Numeric) && n % 10 == 1 && n % 100 != 11 + :one + else + :other + end + end + end + end + + module Macedonian + def self.rule + lambda do |n| + if n.is_a?(Numeric) && n % 10 == 1 && n != 11 + :one + else + :other + end + end + end + end + + module Polish + def self.rule + lambda do |n| + return :other unless n.is_a?(Numeric) + + mod10 = n % 10 + mod100 = n % 100 + + if n == 1 + :one + elsif [2, 3, 4].include?(mod10) && ![12, 13, 14].include?(mod100) + :few + elsif [0, 1, 5, 6, 7, 8, 9].include?(mod10) || [12, 13, 14].include?(mod100) + :many + else + :other + end + end + end + end + + module Slovenian + def self.rule + lambda do |n| + return :other unless n.is_a?(Numeric) + + case n % 100 + when 1 then :one + when 2 then :two + when 3, 4 then :few + else :other + end + end + end + end + end +end diff --git a/lib/rails_i18n/transliteration.rb b/lib/rails_i18n/transliteration.rb new file mode 100644 index 00000000..438ddc9a --- /dev/null +++ b/lib/rails_i18n/transliteration.rb @@ -0,0 +1,191 @@ +# frozen_string_literal: true + +module RailsI18n + module Transliteration + module Ukrainian + class << self + def rule + lambda do |string| + next '' unless string + + string.gsub(/./) do |char| + # Regexp.last_match is local to the thread and method scope + # of the method that did the pattern match. + @pre_match, @post_match = $`, $' + + case char + when 'Ж' + lookahead_upcase 'ZH' + when 'Х' + lookahead_upcase 'KH' + when 'Ц' + lookahead_upcase 'TS' + when 'Ч' + lookahead_upcase 'CH' + when 'Ш' + lookahead_upcase 'SH' + when 'Щ' + lookahead_upcase 'SHCH' + when 'г' + behind =~ /[зЗ]/ ? 'gh' : 'h' + when 'Г' + behind =~ /[зЗ]/ ? lookahead_upcase('GH') : 'H' + when 'є' + letter?(behind) ? 'ie' : 'ye' + when 'Є' + letter?(behind) ? lookahead_upcase('IE') : lookahead_upcase('YE') + when 'ї' + letter?(behind) ? 'i' : 'yi' + when 'Ї' + letter?(behind) ? 'I' : lookahead_upcase('YI') + when 'й' + letter?(behind) ? 'i' : 'y' + when 'Й' + letter?(behind) ? 'I' : 'Y' + when 'ю' + letter?(behind) ? 'iu' : 'yu' + when 'Ю' + letter?(behind) ? lookahead_upcase('IU') : lookahead_upcase('YU') + when 'я' + letter?(behind) ? 'ia' : 'ya' + when 'Я' + letter?(behind) ? lookahead_upcase('IA') : lookahead_upcase('YA') + when "'" + # remove apostrophe inside a word + letter?(behind) && letter?(ahead) ? '' : "'" + else + straight_lookup[char] || char + end + end + end + end + + private + + def behind + @pre_match && @pre_match[-1] + end + + def ahead + @post_match && @post_match[0] + end + + def downcased?(symbol) + symbol =~ downcased_regexp + end + + def downcased_regexp + @downcased_regexp ||= /[а-яґєії]/ + end + + # apostrophe can be inside a word + def letter?(symbol) + symbol =~ letter_regexp + end + + def letter_regexp + @letter_regexp ||= /[а-яґєіїА-ЯҐЄІЇ'’]/ + end + + def lookahead_upcase(word) + downcased?(ahead) ? word.capitalize : word.upcase + end + + def straight_lookup + @straight_lookup ||= { + 'а'=>'a','б'=>'b','в'=>'v','ґ'=>'g','д'=>'d','е'=>'e','ж'=>'zh', + 'з'=>'z','и'=>'y','і'=>'i','к'=>'k','л'=>'l','м'=>'m','н'=>'n','о'=>'o', + 'п'=>'p','р'=>'r','с'=>'s','т'=>'t','у'=>'u','ф'=>'f','х'=>'kh','ц'=>'ts', + 'ч'=>'ch','ш'=>'sh','щ'=>'shch','ь'=>'','’'=>'', + 'А'=>'A','Б'=>'B','В'=>'V','Ґ'=>'G','Д'=>'D','Е'=>'E', + 'З'=>'Z','И'=>'Y','І'=>'I','К'=>'K','Л'=>'L','М'=>'M','Н'=>'N','О'=>'O', + 'П'=>'P','Р'=>'R','С'=>'S','Т'=>'T','У'=>'U','Ф'=>'F','Ь'=>'' + } + end + end + end + + # (c) Yaroslav Markin, Julian "julik" Tarkhanov and Co + # https://github.com/yaroslav/russian/blob/master/lib/russian/transliteration.rb + module Russian + class << self + def rule + lambda do |string| + next '' unless string + + chars = string.scan(%r{#{multi_keys.join '|'}|\w|.}) + + result = +"" + + chars.each_with_index do |char, index| + if upper.has_key?(char) && lower.has_key?(chars[index+1]) + # combined case + result << upper[char].downcase.capitalize + elsif upper.has_key?(char) + result << upper[char] + elsif lower.has_key?(char) + result << lower[char] + else + result << char + end + end + + result + end + end + + private + + # use instance variables instead of constants to prevent warnings + # on re-evaling after I18n.reload! + + def upper + @upper ||= begin + upper_single = { + "Ґ"=>"G","Ё"=>"YO","Є"=>"E","Ї"=>"YI","І"=>"I", + "А"=>"A","Б"=>"B","В"=>"V","Г"=>"G", + "Д"=>"D","Е"=>"E","Ж"=>"ZH","З"=>"Z","И"=>"I", + "Й"=>"Y","К"=>"K","Л"=>"L","М"=>"M","Н"=>"N", + "О"=>"O","П"=>"P","Р"=>"R","С"=>"S","Т"=>"T", + "У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"TS","Ч"=>"CH", + "Ш"=>"SH","Щ"=>"SCH","Ъ"=>"'","Ы"=>"Y","Ь"=>"", + "Э"=>"E","Ю"=>"YU","Я"=>"YA", + } + + (upper_single.merge(upper_multi)).freeze + end + end + + def lower + @lower ||= begin + lower_single = { + "і"=>"i","ґ"=>"g","ё"=>"yo","№"=>"#","є"=>"e", + "ї"=>"yi","а"=>"a","б"=>"b", + "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"zh", + "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l", + "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r", + "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h", + "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"'", + "ы"=>"y","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya", + } + + (lower_single.merge(lower_multi)).freeze + end + end + + def upper_multi + @upper_multi ||= { "ЬЕ"=>"IE", "ЬЁ"=>"IE" } + end + + def lower_multi + @lower_multi ||= { "ье"=>"ie", "ьё"=>"ie" } + end + + def multi_keys + @multi_keys ||= (lower_multi.merge(upper_multi)).keys.sort_by {|s| s.length}.reverse.freeze + end + end + end + end +end + diff --git a/rails/pluralization/ar.rb b/rails/pluralization/ar.rb index 2ca1a428..8dd90137 100644 --- a/rails/pluralization/ar.rb +++ b/rails/pluralization/ar.rb @@ -1,30 +1,4 @@ -module RailsI18n - module Pluralization - module Arabic - def self.rule - lambda do |n| - return :other unless n.is_a?(Numeric) - - mod100 = n % 100 - - if n == 0 - :zero - elsif n == 1 - :one - elsif n == 2 - :two - elsif (3..10).to_a.include?(mod100) - :few - elsif (11..99).to_a.include?(mod100) - :many - else - :other - end - end - end - end - end -end +require 'rails_i18n/pluralization' { :ar => { :'i18n' => { diff --git a/rails/pluralization/gd.rb b/rails/pluralization/gd.rb index 25648ebc..bda3e569 100644 --- a/rails/pluralization/gd.rb +++ b/rails/pluralization/gd.rb @@ -1,26 +1,4 @@ -module RailsI18n - module Pluralization - module ScottishGaelic - def self.rule - lambda do |n| - return :other unless n.is_a?(Numeric) - - floorn = n.floor - - if floorn == 1 || floorn == 11 - :one - elsif floorn == 2 || floorn == 12 - :two - elsif (3..19).member?(floorn) - :few - else - :other - end - end - end - end - end -end +require 'rails_i18n/pluralization' { :gd => { :'i18n' => { diff --git a/rails/pluralization/hsb.rb b/rails/pluralization/hsb.rb index 80447ccd..351ba571 100644 --- a/rails/pluralization/hsb.rb +++ b/rails/pluralization/hsb.rb @@ -1,23 +1,4 @@ -module RailsI18n - module Pluralization - module UpperSorbian - def self.rule - lambda do |n| - return :other unless n.is_a?(Numeric) - - mod100 = n % 100 - - case mod100 - when 1 then :one - when 2 then :two - when 3, 4 then :few - else :other - end - end - end - end - end -end +require 'rails_i18n/pluralization' { :hsb => { :'i18n' => { diff --git a/rails/pluralization/lt.rb b/rails/pluralization/lt.rb index 3b2038c4..5bd48ceb 100644 --- a/rails/pluralization/lt.rb +++ b/rails/pluralization/lt.rb @@ -1,25 +1,4 @@ -module RailsI18n - module Pluralization - module Lithuanian - def self.rule - lambda do |n| - return :other unless n.is_a?(Numeric) - - mod10 = n % 10 - mod100 = n % 100 - - if mod10 == 1 && !(11..19).to_a.include?(mod100) - :one - elsif (2..9).to_a.include?(mod10) && !(11..19).to_a.include?(mod100) - :few - else - :other - end - end - end - end - end -end +require 'rails_i18n/pluralization' { :lt => { :'i18n' => { diff --git a/rails/pluralization/lv.rb b/rails/pluralization/lv.rb index 0b2b02ac..28201ad2 100644 --- a/rails/pluralization/lv.rb +++ b/rails/pluralization/lv.rb @@ -1,18 +1,4 @@ -module RailsI18n - module Pluralization - module Latvian - def self.rule - lambda do |n| - if n.is_a?(Numeric) && n % 10 == 1 && n % 100 != 11 - :one - else - :other - end - end - end - end - end -end +require 'rails_i18n/pluralization' { :lv => { :'i18n' => { diff --git a/rails/pluralization/mk.rb b/rails/pluralization/mk.rb index b3b45442..2def0df7 100644 --- a/rails/pluralization/mk.rb +++ b/rails/pluralization/mk.rb @@ -1,18 +1,4 @@ -module RailsI18n - module Pluralization - module Macedonian - def self.rule - lambda do |n| - if n.is_a?(Numeric) && n % 10 == 1 && n != 11 - :one - else - :other - end - end - end - end - end -end +require 'rails_i18n/pluralization' { :mk => { :'i18n' => { diff --git a/rails/pluralization/pl.rb b/rails/pluralization/pl.rb index be3ca855..b692713a 100644 --- a/rails/pluralization/pl.rb +++ b/rails/pluralization/pl.rb @@ -1,27 +1,4 @@ -module RailsI18n - module Pluralization - module Polish - def self.rule - lambda do |n| - return :other unless n.is_a?(Numeric) - - mod10 = n % 10 - mod100 = n % 100 - - if n == 1 - :one - elsif [2, 3, 4].include?(mod10) && ![12, 13, 14].include?(mod100) - :few - elsif [0, 1, 5, 6, 7, 8, 9].include?(mod10) || [12, 13, 14].include?(mod100) - :many - else - :other - end - end - end - end - end -end +require 'rails_i18n/pluralization' { :pl => { :'i18n' => { diff --git a/rails/pluralization/sl.rb b/rails/pluralization/sl.rb index a0ab8705..bba47eb0 100644 --- a/rails/pluralization/sl.rb +++ b/rails/pluralization/sl.rb @@ -1,21 +1,4 @@ -module RailsI18n - module Pluralization - module Slovenian - def self.rule - lambda do |n| - return :other unless n.is_a?(Numeric) - - case n % 100 - when 1 then :one - when 2 then :two - when 3, 4 then :few - else :other - end - end - end - end - end -end +require 'rails_i18n/pluralization' { :sl => { :'i18n' => { diff --git a/rails/transliteration/ru.rb b/rails/transliteration/ru.rb index 0f358b24..1d756faa 100644 --- a/rails/transliteration/ru.rb +++ b/rails/transliteration/ru.rb @@ -1,91 +1,4 @@ -# encoding: utf-8 - -# (c) Yaroslav Markin, Julian "julik" Tarkhanov and Co -# https://github.com/yaroslav/russian/blob/master/lib/russian/transliteration.rb - -module RailsI18n - module Transliteration - module Russian - class << self - def rule - lambda do |string| - next '' unless string - - chars = string.scan(%r{#{multi_keys.join '|'}|\w|.}) - - result = +"" - - chars.each_with_index do |char, index| - if upper.has_key?(char) && lower.has_key?(chars[index+1]) - # combined case - result << upper[char].downcase.capitalize - elsif upper.has_key?(char) - result << upper[char] - elsif lower.has_key?(char) - result << lower[char] - else - result << char - end - end - - result - end - end - - private - - # use instance variables instead of constants to prevent warnings - # on re-evaling after I18n.reload! - - def upper - @upper ||= begin - upper_single = { - "Ґ"=>"G","Ё"=>"YO","Є"=>"E","Ї"=>"YI","І"=>"I", - "А"=>"A","Б"=>"B","В"=>"V","Г"=>"G", - "Д"=>"D","Е"=>"E","Ж"=>"ZH","З"=>"Z","И"=>"I", - "Й"=>"Y","К"=>"K","Л"=>"L","М"=>"M","Н"=>"N", - "О"=>"O","П"=>"P","Р"=>"R","С"=>"S","Т"=>"T", - "У"=>"U","Ф"=>"F","Х"=>"H","Ц"=>"TS","Ч"=>"CH", - "Ш"=>"SH","Щ"=>"SCH","Ъ"=>"'","Ы"=>"Y","Ь"=>"", - "Э"=>"E","Ю"=>"YU","Я"=>"YA", - } - - (upper_single.merge(upper_multi)).freeze - end - end - - def lower - @lower ||= begin - lower_single = { - "і"=>"i","ґ"=>"g","ё"=>"yo","№"=>"#","є"=>"e", - "ї"=>"yi","а"=>"a","б"=>"b", - "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"zh", - "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l", - "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r", - "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h", - "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"'", - "ы"=>"y","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya", - } - - (lower_single.merge(lower_multi)).freeze - end - end - - def upper_multi - @upper_multi ||= { "ЬЕ"=>"IE", "ЬЁ"=>"IE" } - end - - def lower_multi - @lower_multi ||= { "ье"=>"ie", "ьё"=>"ie" } - end - - def multi_keys - @multi_keys ||= (lower_multi.merge(upper_multi)).keys.sort_by {|s| s.length}.reverse.freeze - end - end - end - end -end +require 'rails_i18n/transliteration' { :ru => { :i18n => { diff --git a/rails/transliteration/uk.rb b/rails/transliteration/uk.rb index 34e27ff5..183624b2 100644 --- a/rails/transliteration/uk.rb +++ b/rails/transliteration/uk.rb @@ -1,111 +1,4 @@ -# encoding: utf-8 - -module RailsI18n - module Transliteration - module Ukrainian - class << self - def rule - lambda do |string| - next '' unless string - - string.gsub(/./) do |char| - # Regexp.last_match is local to the thread and method scope - # of the method that did the pattern match. - @pre_match, @post_match = $`, $' - - case char - when 'Ж' - lookahead_upcase 'ZH' - when 'Х' - lookahead_upcase 'KH' - when 'Ц' - lookahead_upcase 'TS' - when 'Ч' - lookahead_upcase 'CH' - when 'Ш' - lookahead_upcase 'SH' - when 'Щ' - lookahead_upcase 'SHCH' - when 'г' - behind =~ /[зЗ]/ ? 'gh' : 'h' - when 'Г' - behind =~ /[зЗ]/ ? lookahead_upcase('GH') : 'H' - when 'є' - letter?(behind) ? 'ie' : 'ye' - when 'Є' - letter?(behind) ? lookahead_upcase('IE') : lookahead_upcase('YE') - when 'ї' - letter?(behind) ? 'i' : 'yi' - when 'Ї' - letter?(behind) ? 'I' : lookahead_upcase('YI') - when 'й' - letter?(behind) ? 'i' : 'y' - when 'Й' - letter?(behind) ? 'I' : 'Y' - when 'ю' - letter?(behind) ? 'iu' : 'yu' - when 'Ю' - letter?(behind) ? lookahead_upcase('IU') : lookahead_upcase('YU') - when 'я' - letter?(behind) ? 'ia' : 'ya' - when 'Я' - letter?(behind) ? lookahead_upcase('IA') : lookahead_upcase('YA') - when "'" - # remove apostrophe inside a word - letter?(behind) && letter?(ahead) ? '' : "'" - else - straight_lookup[char] || char - end - end - end - end - - private - - def behind - @pre_match && @pre_match[-1] - end - - def ahead - @post_match && @post_match[0] - end - - def downcased?(symbol) - symbol =~ downcased_regexp - end - - def downcased_regexp - @downcased_regexp ||= /[а-яґєії]/ - end - - # apostrophe can be inside a word - def letter?(symbol) - symbol =~ letter_regexp - end - - def letter_regexp - @letter_regexp ||= /[а-яґєіїА-ЯҐЄІЇ'’]/ - end - - def lookahead_upcase(word) - downcased?(ahead) ? word.capitalize : word.upcase - end - - def straight_lookup - @straight_lookup ||= { - 'а'=>'a','б'=>'b','в'=>'v','ґ'=>'g','д'=>'d','е'=>'e','ж'=>'zh', - 'з'=>'z','и'=>'y','і'=>'i','к'=>'k','л'=>'l','м'=>'m','н'=>'n','о'=>'o', - 'п'=>'p','р'=>'r','с'=>'s','т'=>'t','у'=>'u','ф'=>'f','х'=>'kh','ц'=>'ts', - 'ч'=>'ch','ш'=>'sh','щ'=>'shch','ь'=>'','’'=>'', - 'А'=>'A','Б'=>'B','В'=>'V','Ґ'=>'G','Д'=>'D','Е'=>'E', - 'З'=>'Z','И'=>'Y','І'=>'I','К'=>'K','Л'=>'L','М'=>'M','Н'=>'N','О'=>'O', - 'П'=>'P','Р'=>'R','С'=>'S','Т'=>'T','У'=>'U','Ф'=>'F','Ь'=>'' - } - end - end - end - end -end +require 'rails_i18n/transliteration' { :uk => { :i18n => {