Skip to content

Commit

Permalink
List the line counts of all the locales
Browse files Browse the repository at this point in the history
This makes more sense than just listing those that do not match en.yml
  • Loading branch information
digitalfrost committed Aug 30, 2022
1 parent e0b3ecb commit f9c13fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
12 changes: 3 additions & 9 deletions locales.thor
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,10 @@ class Locales < Thor
puts CheckLocales.en_line_count
end

desc 'check_line_count', 'a heuristic check of the locales. Checks the line count of locale files compared to :en'
desc 'check_line_count', 'Returns a list of locale files with their line count, so that we can identify anomalies'
def check_line_count
wrong_line_count = CheckLocales.check_line_count()
if !wrong_line_count.empty?
puts "The following locale files do not have the same lenght as en.yml:"
for file, count in wrong_line_count do
puts "#{file}: #{count} lines"
end
else
puts "All locale files have the same length as en.yml"
for file, count in CheckLocales.line_counts() do
puts "#{file}: #{count} lines"
end
end

Expand Down
16 changes: 7 additions & 9 deletions rails/test/lib/check_locales.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,19 @@ def self.en_line_count
@en_line_count
end

# a heuristic check of the locales
# returns a hash of locale files with a line count that does not match en.yml
# Helps identify anomalies in the locale.yml files
# returns a hash of locale files with their line count
# in the format 'locale_file' : line count
# {'problem_locale1.yml': 100, 'problem_locale2.yml': 111 ... }
def self.check_line_count
wrong_line_count = {}
# {'locale1.yml': 100, 'locale2.yml': 111 ... }
def self.line_counts
file_line_count = {}
Dir.chdir(@path_to_locales)
locale_files = Dir.glob('**/*.yml')
for f in locale_files do
line_count = File.open(f).readlines().size
if line_count != @en_line_count
wrong_line_count[f] = line_count
end
file_line_count[f] = line_count
end
return wrong_line_count
return file_line_count
end
end

0 comments on commit f9c13fb

Please sign in to comment.