Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Plurals #51

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

Enables extra plural rules to be used outside of Rails Translation Manager

# 1.5.2

Add missing plurals for Gujarati and Yiddish https://github.com/alphagov/rails_translation_manager/pull/44
Expand Down
64 changes: 0 additions & 64 deletions config/locales/plurals.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/rails_translation_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
require "rails_translation_manager/cleaner"
require "rails_translation_manager/exporter"
require "rails_translation_manager/importer"
require "rails_translation_manager/plurals"

module RailsTranslationManager
rails_i18n_path = Gem::Specification.find_by_name("rails-i18n").gem_dir
rails_translation_manager = Gem::Specification.find_by_name("rails_translation_manager").gem_dir

I18n.load_path.concat(
Dir["#{rails_i18n_path}/rails/pluralization/*.rb"],
["#{rails_translation_manager}/config/locales/plurals.rb"]
["lib/rails_translation_manager/plurals.rb"]
)

def self.locale_root
Expand Down
72 changes: 72 additions & 0 deletions lib/rails_translation_manager/plurals.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# frozen_string_literal: true

module RailsTranslationManager
class Plurals
def self.extra_rules
{
# Welsh
cy: { i18n: { plural: { keys: %i[zero one two few many other],
rule:
lambda do |n|
case n
when 0 then :zero
when 1 then :one
when 2 then :two
when 3 then :few
when 6 then :many
else :other
end
end } } },
# Dari - this isn't an iso code. Probably should be 'prs' as per ISO 639-3.
dr: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
# Latin America and Caribbean Spanish
"es-419": { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
# Gujarati
gu: { i18n: { plural: { keys: %i[one other], rule: ->(n) { [0, 1].include?(n) ? :one : :other } } } },
# Scottish Gaelic
gd: { i18n: { plural: { keys: %i[one two few other],
rule: lambda do |n|
if [1, 11].include?(n)
:one
elsif [2, 12].include?(n)
:two
elsif [3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19].include?(n)
:few
else
:other
end
end } } },
# Armenian
hy: { i18n: { plural: { keys: %i[one other], rule: ->(n) { [0, 1].include?(n) ? :one : :other } } } },
# Kazakh
kk: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
# Pashto
ps: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
# Punjabi Shahmukhi
"pa-pk": { i18n: { plural: { keys: %i[one other], rule: ->(n) { [0, 1].include?(n) ? :one : :other } } } },
# Sinhalese
si: { i18n: { plural: { keys: %i[one other], rule: ->(n) { [0, 1].include?(n) ? :one : :other } } } },
# Somali
so: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
# Albanian
sq: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
# Norwegian
no: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
# Tamil
ta: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
# Turkmen
tk: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
# Uzbek
uz: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
# Yiddish
yi: { i18n: { plural: { keys: %i[one other], rule: ->(n) { [0, 1].include?(n) ? :one : :other } } } },
# Chinese Hong Kong
'zh-hk' => { i18n: { plural: { keys: %i[other], rule: -> { :other } } } },
# Chinese Taiwan
'zh-tw' => { i18n: { plural: { keys: %i[other], rule: -> { :other } } } }
}
end
end
end

RailsTranslationManager::Plurals.extra_rules