Skip to content

Commit

Permalink
Add methods to count all and complete locales using thor
Browse files Browse the repository at this point in the history
thor: Add methods to count all and complete locales
  • Loading branch information
pama authored Aug 14, 2022
2 parents b50cfb9 + 87c4a73 commit d53db42
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions locales.thor
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,49 @@ class Locales < Thor

desc 'list', 'List locale names.'
def list
puts self.list_locales.join(', ')
end

desc 'count_all', 'Returns the number of available locales'
def count_all
puts self.list_locales.count
end

desc 'complete', 'List complete locales'
def complete
puts self.complete_locales.join(', ')
end

desc 'complete_count', 'Returns the number of complete locales'
def complete_count
puts self.complete_locales.count
end

desc 'incomplete', 'List incomplete locales'
def incomplete
puts self.incomplete_locales.join(', ')
end

desc 'incomplete_count', 'Returns the number of incomplete locales'
def incomplete_count
puts self.incomplete_locales.count
end

private

desc 'list_locales', 'List all locales'
def list_locales
locales = []
Dir.glob(File.dirname(__FILE__) + '/rails/locale/*.{rb,yml}') do |filename|
if md = filename.match(/([\w\-]+)\.(rb|yml)$/)
locales << md[1]
end
end
puts locales.sort.join(', ')
return locales.sort
end

desc 'complete', 'List complete locales'
def complete
desc 'complete_locales', 'List complete locales'
def complete_locales
locales = []
Dir.glob(File.dirname(__FILE__) + '/rails/locale/*.{rb,yml}') do |filename|
if md = filename.match(/([\w\-]+)\.(rb|yml)$/)
Expand All @@ -97,21 +129,9 @@ class Locales < Thor
end
end
end
puts locales.sort.join(', ')
end

desc 'incomplete', 'List incomplete locales'
def incomplete
puts self.incomplete_locales.join(', ')
end

desc 'incomplete_count', 'Returns the number of incomplete locales'
def incomplete_count
puts self.incomplete_locales.count
return locales.sort
end

private

desc 'incomplete_locales', 'Returns an array of incomplete locales'
def incomplete_locales
locales = []
Expand Down

0 comments on commit d53db42

Please sign in to comment.