rails_translation_manager 0.0.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -1
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +20 -0
  5. data/Jenkinsfile +9 -0
  6. data/README.md +1 -1
  7. data/Rakefile +12 -13
  8. data/config/locales/plurals.rb +49 -0
  9. data/lib/rails_translation_manager/cleaner.rb +14 -0
  10. data/lib/rails_translation_manager/i18n_tasks_option_parser.rb +10 -0
  11. data/lib/rails_translation_manager/importer.rb +32 -14
  12. data/lib/rails_translation_manager/locale_checker/all_locales.rb +61 -0
  13. data/lib/rails_translation_manager/locale_checker/base_checker.rb +13 -0
  14. data/lib/rails_translation_manager/locale_checker/incompatible_plurals.rb +79 -0
  15. data/lib/rails_translation_manager/locale_checker/locale_checker_helper.rb +23 -0
  16. data/lib/rails_translation_manager/locale_checker/missing_english_locales.rb +31 -0
  17. data/lib/rails_translation_manager/locale_checker/missing_foreign_locales.rb +31 -0
  18. data/lib/rails_translation_manager/locale_checker/plural_forms.rb +16 -0
  19. data/lib/rails_translation_manager/locale_checker.rb +50 -0
  20. data/lib/rails_translation_manager/version.rb +1 -1
  21. data/lib/rails_translation_manager.rb +21 -3
  22. data/lib/tasks/translation.rake +43 -43
  23. data/rails_translation_manager.gemspec +4 -2
  24. data/spec/locales/cleaner/clean.yml +5 -0
  25. data/spec/locales/cleaner/with_whitespace.yml +5 -0
  26. data/spec/locales/importer/fr.csv +8 -0
  27. data/spec/locales/in_sync/cy/browse.yml +12 -0
  28. data/spec/locales/in_sync/en/browse.yml +8 -0
  29. data/spec/locales/out_of_sync/cy.yml +3 -0
  30. data/spec/locales/out_of_sync/en.yml +6 -0
  31. data/spec/rails_translation_manager/cleaner_spec.rb +13 -0
  32. data/spec/rails_translation_manager/importer_spec.rb +81 -0
  33. data/spec/rails_translation_manager/locale_checker/all_locales_spec.rb +24 -0
  34. data/spec/rails_translation_manager/locale_checker/incompatible_plurals_spec.rb +94 -0
  35. data/spec/rails_translation_manager/locale_checker/locale_checker_helper_spec.rb +61 -0
  36. data/spec/rails_translation_manager/locale_checker/missing_english_locales_spec.rb +72 -0
  37. data/spec/rails_translation_manager/locale_checker/missing_foreign_locales_spec.rb +80 -0
  38. data/spec/rails_translation_manager/locale_checker/plural_forms_spec.rb +27 -0
  39. data/spec/rails_translation_manager/locale_checker_spec.rb +68 -0
  40. data/spec/spec_helper.rb +19 -0
  41. data/spec/support/tasks.rb +7 -0
  42. data/spec/tasks/translation_spec.rb +123 -0
  43. data/test/rails_translation_manager/yaml_writer_test.rb +2 -0
  44. data/tmp/.gitkeep +0 -0
  45. metadata +93 -24
  46. data/jenkins.sh +0 -9
  47. data/lib/rails_translation_manager/stealer.rb +0 -85
  48. data/lib/rails_translation_manager/validator.rb +0 -92
  49. data/test/rails_translation_manager/importer_test.rb +0 -132
  50. data/test/rails_translation_manager/stealer_test.rb +0 -251
  51. data/test/rails_translation_manager/validator_test.rb +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b5174ef0679b5689038dba575d7739d110109836
4
- data.tar.gz: de386962792fc2d729e98183b7e4c962d41798c1
2
+ SHA256:
3
+ metadata.gz: 234b68e06027a3335015a5818993014afea669efe42729d87f4de40efd4dc487
4
+ data.tar.gz: 54a16b4f583813415a6801c62fda5eb9ee603e84bf65206700c0bc33b295b238
5
5
  SHA512:
6
- metadata.gz: 3e07bb3ed5ec4b2a4f73672f626d0b579240a63115e7ad39345e00b68912f0ecafadbc5666e28ed365aceef30011a24d6821f805b512e1d8c3a3685c38b5ea7c
7
- data.tar.gz: 96aab0397474451f60f6de06dd2cff484851b493e7f6d5ebd4714aafab99546ebc1f34b8795d70c3282da03cf79a02f2721064ac696fd0c182dba5a2c3591482
6
+ metadata.gz: 2ab59ec749b2827c011728fe5711c850099d379d9089c2d73fc112def0f02c994b58ed646f42fe106c2d15d56cd5aaad1db636d7afe1504740109b57baca3c2f
7
+ data.tar.gz: 9313168a8704e4985ae4a57d89fb6bc8dc47a5ac2f1ae6cdd73686aeec0fe657617776620db6a65c0c45b708ec2de06dc390d546509198a836b6ff7a14212ca3
data/.gitignore CHANGED
@@ -6,7 +6,7 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
- /tmp/
9
+ /tmp/*
10
10
  *.bundle
11
11
  *.so
12
12
  *.o
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.4
1
+ 2.6.6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 1.1.1
2
+
3
+ Fix Rails Translation Manager / Rails naming clash for class. https://github.com/alphagov/rails_translation_manager/pull/26
4
+
5
+ ## 1.1.0
6
+
7
+ Allow multiple files per language to be imported. https://github.com/alphagov/rails_translation_manager/pull/20
8
+
9
+ ## 1.0.0
10
+
11
+ Adds logic to verify locale files are in sync with each other and have the
12
+ correct plural forms. Also introduces RSpec into the Gem which will replace
13
+ Minitest in the coming iterations.
14
+
15
+ Integrates RTM with I18n-tasks. Adds wrappers around `add-missing` & `normalize` tasks, adds Cleaner class to remove the whitespace added by i18n-tasks, adds tests and byebug gem as a debugging tool.
16
+
17
+ ## 0.1.0
18
+
19
+ Don't change the $LOAD_PATH in translation.rake.
20
+
1
21
  ## 0.0.2
2
22
 
3
23
  Added `steal` rake tasks to copy translations from another app.
data/Jenkinsfile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env groovy
2
+
3
+ library("govuk")
4
+
5
+ node {
6
+ govuk.buildProject(
7
+ cleanWorkspace: true,
8
+ )
9
+ }
data/README.md CHANGED
@@ -14,7 +14,7 @@ Support for translation workflow in rails applications.
14
14
  into a translated string of text, for example `Hello %{name}`
15
15
  would become `Hello Sarah` if the variable `name` had the
16
16
  value `Sarah`.
17
- - **YAML**: yet another markup language, a textual data format used for storing
17
+ - **YAML**: YAML Ain't Markup Language, a textual data format used (in this case) for storing
18
18
  translation strings in rails applications
19
19
 
20
20
  ## Technical documentation
data/Rakefile CHANGED
@@ -1,18 +1,17 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ # frozen_string_literal: true
3
2
 
4
- Rake::TestTask.new("test") do |t|
5
- t.description = "Run tests"
6
- t.ruby_opts << "-rubygems"
7
- t.libs << "test"
8
- t.test_files = FileList["test/**/*_test.rb"]
3
+ require 'rspec/core/rake_task'
4
+ require 'bundler/gem_tasks'
5
+ require 'rake/testtask'
6
+ require 'rails_i18n'
7
+
8
+ Rake::TestTask.new('test') do |t|
9
+ t.description = 'Run tests'
10
+ t.libs << 'test'
11
+ t.test_files = FileList['test/**/*_test.rb']
9
12
  t.verbose = true
10
13
  end
11
14
 
12
- require "gem_publisher"
13
- task :publish_gem do |t|
14
- gem = GemPublisher.publish_if_updated("rails_translation_manager.gemspec", :rubygems)
15
- puts "Published #{gem}" if gem
16
- end
15
+ RSpec::Core::RakeTask.new(:spec)
17
16
 
18
- task :default => :test
17
+ task default: %i[spec test]
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ {
4
+ # Dari - this isn't an iso code. Probably should be 'prs' as per ISO 639-3.
5
+ dr: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
6
+ # Latin America and Caribbean Spanish
7
+ "es-419": { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
8
+ # Scottish Gaelic
9
+ gd: { i18n: { plural: { keys: %i[one two few other],
10
+ rule: lambda do |n|
11
+ if [1, 11].include?(n)
12
+ :one
13
+ elsif [2, 12].include?(n)
14
+ :two
15
+ elsif [3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19].include?(n)
16
+ :few
17
+ else
18
+ :other
19
+ end
20
+ end } } },
21
+ # Gujarati
22
+ gu: { i18n: { plural: { keys: %i[one other], rule: ->(n) { [0, 1].include?(n) ? :one : :other } } } },
23
+ # Armenian
24
+ hy: { i18n: { plural: { keys: %i[one other], rule: ->(n) { [0, 1].include?(n) ? :one : :other } } } },
25
+ # Kazakh
26
+ kk: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
27
+ # Pashto
28
+ ps: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
29
+ # Punjabi Shahmukhi
30
+ "pa-pk": { i18n: { plural: { keys: %i[one other], rule: ->(n) { [0, 1].include?(n) ? :one : :other } } } },
31
+ # Sinhalese
32
+ si: { i18n: { plural: { keys: %i[one other], rule: ->(n) { [0, 1].include?(n) ? :one : :other } } } },
33
+ # Somali
34
+ so: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
35
+ # Albanian
36
+ sq: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
37
+ # Norwegian
38
+ no: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
39
+ # Tamil
40
+ ta: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
41
+ # Turkmen
42
+ tk: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
43
+ # Uzbek
44
+ uz: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
45
+ # Chinese Hong Kong
46
+ 'zh-hk' => { i18n: { plural: { keys: %i[other], rule: -> { :other } } } },
47
+ # Chinese Taiwan
48
+ 'zh-tw' => { i18n: { plural: { keys: %i[other], rule: -> { :other } } } }
49
+ }
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsTranslationManager
4
+ class Cleaner
5
+
6
+ def initialize(path)
7
+ @path = path
8
+ end
9
+
10
+ def clean
11
+ `find #{@path} -type f -exec perl -p -i -e \"s/[ \t]$//g\" {} \\;`
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ class RailsTranslationManager::I18nTasksOptionParser
2
+ def initialize(task_options, locale)
3
+ @task_options = task_options
4
+ @locale = locale
5
+ end
6
+
7
+ def with_optional_locale
8
+ @locale ? @task_options << ["-l", @locale] : @task_options
9
+ end
10
+ end
@@ -5,36 +5,39 @@ require_relative "yaml_writer"
5
5
  class RailsTranslationManager::Importer
6
6
  include YAMLWriter
7
7
 
8
- def initialize(locale, csv_path, import_directory)
9
- @csv_path = csv_path
8
+ attr_reader :locale, :csv_path, :import_directory, :multiple_files_per_language
9
+
10
+ def initialize(locale:, csv_path:, import_directory:, multiple_files_per_language:)
10
11
  @locale = locale
12
+ @csv_path = csv_path
11
13
  @import_directory = import_directory
14
+ @multiple_files_per_language = multiple_files_per_language
12
15
  end
13
16
 
14
17
  def import
15
- csv = CSV.read(@csv_path, headers: true, header_converters: :downcase)
16
- data = {}
17
- csv.each do |row|
18
+ csv = CSV.read(csv_path, headers: true, header_converters: :downcase)
19
+
20
+ multiple_files_per_language ? import_csv_into_multiple_files(csv) : import_csv(csv)
21
+ end
22
+
23
+ private
24
+
25
+ def import_csv(csv, import_yml_path = File.join(import_directory, "#{locale}.yml"))
26
+ data = csv.each_with_object({}) do |row, hash|
18
27
  key = row["key"]
19
28
  key_parts = key.split(".")
20
29
  if key_parts.length > 1
21
- leaf_node = (data[key_parts.first] ||= {})
30
+ leaf_node = (hash[key_parts.first] ||= {})
22
31
  key_parts[1..-2].each do |part|
23
32
  leaf_node = (leaf_node[part] ||= {})
24
33
  end
25
34
  leaf_node[key_parts.last] = parse_translation(row["translation"])
26
35
  else
27
- data[key_parts.first] = parse_translation(row["translation"])
36
+ hash[key_parts.first] = parse_translation(row["translation"])
28
37
  end
29
38
  end
30
39
 
31
- write_yaml(import_yml_path, {@locale.to_s => data})
32
- end
33
-
34
- private
35
-
36
- def import_yml_path
37
- File.join(@import_directory, "#{@locale}.yml")
40
+ write_yaml(import_yml_path, { locale.to_s => data })
38
41
  end
39
42
 
40
43
  def parse_translation(translation)
@@ -55,4 +58,19 @@ class RailsTranslationManager::Importer
55
58
  translation
56
59
  end
57
60
  end
61
+
62
+ def import_csv_into_multiple_files(csv)
63
+ group_csv_by_file(csv).each do |group|
64
+ language_dir = File.join(import_directory, locale)
65
+
66
+ Dir.mkdir(language_dir) unless Dir.exists?(language_dir)
67
+
68
+ import_yml_path = File.join(import_directory, locale, "#{group[0]}.yml")
69
+ import_csv(group[1], import_yml_path)
70
+ end
71
+ end
72
+
73
+ def group_csv_by_file(csv)
74
+ csv.group_by { |row| row["key"].split(".").first }
75
+ end
58
76
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AllLocales
4
+ attr_reader :locale_path
5
+
6
+ def initialize(locale_path)
7
+ @locale_path = locale_path
8
+ end
9
+
10
+ def generate
11
+ paths = locale_file_paths.compact
12
+
13
+ raise NoLocaleFilesFound, "No locale files found for the supplied path" if paths.blank?
14
+
15
+ paths.flat_map do |locale_group|
16
+ {
17
+ locale: locale_group[:locale],
18
+ keys: all_keys_for_locale(locale_group)
19
+ }
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def locale_file_paths
26
+ I18n.available_locales.map do |locale|
27
+ grouped_paths = Dir[locale_path].select do |path|
28
+ locale = locale.downcase
29
+
30
+ path =~ %r{/#{locale}/} || path =~ %r{/#{locale}\.yml$}
31
+ end
32
+
33
+ { locale: locale.downcase, paths: grouped_paths } if grouped_paths.present?
34
+ end
35
+ end
36
+
37
+ def all_keys_for_locale(locale_group)
38
+ locale_group[:paths].flat_map do |path|
39
+ keys_from_file(file_path: path)
40
+ end
41
+ end
42
+
43
+ def keys_from_file(locale_hash: nil, key_chain: nil, locale_keys: [], file_path: nil)
44
+ locale_hash ||= YAML.load_file(file_path)
45
+ keys = locale_hash.keys
46
+ keys.each do |key|
47
+ if locale_hash.fetch(key).is_a?(Hash)
48
+ keys_from_file(locale_hash: locale_hash.fetch(key), key_chain: "#{key_chain}.#{key}", locale_keys: locale_keys)
49
+ else
50
+ keys.each do |final_key|
51
+ locale_keys << "#{key_chain}.#{final_key}"
52
+ end
53
+ end
54
+ end
55
+
56
+ # remove locale prefix from keys, e.g: ".en.browse.page" -> "browse.page"
57
+ locale_keys.uniq.map { |key| key.split(".")[2..].join(".") }
58
+ end
59
+
60
+ class NoLocaleFilesFound < StandardError; end
61
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class BaseChecker
4
+ attr_reader :all_locales
5
+
6
+ def initialize(all_locales)
7
+ @all_locales = all_locales
8
+ end
9
+
10
+ def report
11
+ raise "You must define a `report` method in the child class!"
12
+ end
13
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ class IncompatiblePlurals < BaseChecker
4
+ include LocaleCheckerHelper
5
+
6
+ def report
7
+ format_plural_errors if plural_errors.present?
8
+ end
9
+
10
+ private
11
+
12
+ def format_plural_errors
13
+ <<~OUTPUT.chomp
14
+ \e[31m[ERROR]\e[0m Incompatible plural forms, for:
15
+
16
+ #{plural_errors.join("\n\n")}
17
+
18
+ \e[1mIf the keys reported above are not plurals, rename them avoiding plural keywords: #{PLURAL_KEYS}\e[22m
19
+ OUTPUT
20
+ end
21
+
22
+ def plural_errors
23
+ @plural_errors ||= grouped_plural_keys_for_locale.flat_map do |plurals|
24
+ plural_form = all_plural_forms[plurals[:locale]]
25
+
26
+ if plural_form.blank?
27
+ "- \e[31m[ERROR]\e[0m Please add plural form for '#{plurals[:locale]}' <link to future documentation>"
28
+ else
29
+ incompatible_plurals(plurals, plural_form)
30
+ end
31
+ end
32
+ end
33
+
34
+ def incompatible_plurals(plurals, plural_form)
35
+ error_messages = plurals[:groups].map do |plural_group|
36
+ actual_plural_form = plural_group[:keys].sort
37
+
38
+ next if actual_plural_form == plural_form.sort
39
+
40
+ "- '#{plurals[:locale]}', with parent '#{plural_group[:parent]}'. Expected: #{plural_form}, actual: #{actual_plural_form}"
41
+ end
42
+
43
+ error_messages.compact
44
+ end
45
+
46
+ def grouped_plural_keys_for_locale
47
+ all_locales.map do |locale|
48
+ {
49
+ locale: locale[:locale],
50
+ groups: grouped_plural_keys(only_plurals(locale[:keys]))
51
+ }
52
+ end
53
+ end
54
+
55
+ def grouped_plural_keys(keys)
56
+ # %w[parent.key parent.other_key] -> [{ parent: "parent", keys: %w[key other_key] }]
57
+ group_by_parent_keys(keys).map do |plural_key_group|
58
+ {
59
+ parent: plural_key_group.first,
60
+ keys: plural_key_group.last.map { |key_chain| key_chain.split(".").last.to_sym }
61
+ }
62
+ end
63
+ end
64
+
65
+ def group_by_parent_keys(keys)
66
+ # %w[parent.key parent.other_key] -> { "parent" => %w[parent.key parent.other_key] }
67
+ keys.group_by do |key|
68
+ key.split('.')[0..-2].join('.')
69
+ end
70
+ end
71
+
72
+ def only_plurals(keys)
73
+ keys.select { |key| key_is_plural?(key) }
74
+ end
75
+
76
+ def all_plural_forms
77
+ @all_plural_forms ||= PluralForms.all
78
+ end
79
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LocaleCheckerHelper
4
+ PLURAL_KEYS = %w[zero one two few many other].freeze
5
+
6
+ def exclude_plurals(keys)
7
+ keys.reject { |key| key_is_plural?(key) }
8
+ end
9
+
10
+ def group_keys(locales)
11
+ locales.keys.group_by do |key|
12
+ locales[key]
13
+ end
14
+ end
15
+
16
+ def english_keys_excluding_plurals(all_locales)
17
+ exclude_plurals(all_locales.find { |locale| locale[:locale] == :en }[:keys])
18
+ end
19
+
20
+ def key_is_plural?(key)
21
+ PLURAL_KEYS.include?(key.split(".").last)
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MissingEnglishLocales < BaseChecker
4
+ include LocaleCheckerHelper
5
+
6
+ def report
7
+ grouped_missing_keys = group_keys(missing_english_locales)
8
+
9
+ format_missing_english_locales(grouped_missing_keys) if grouped_missing_keys.present?
10
+ end
11
+
12
+ private
13
+
14
+ def format_missing_english_locales(keys)
15
+ formatted_keys = keys.to_a.map do |group|
16
+ "\e[1mMissing English keys:\e[22m #{group[0]}\n\e[1mFound in:\e[22m #{group[1]}"
17
+ end
18
+
19
+ "\e[31m[ERROR]\e[0m Missing English locales, either remove these keys from the foreign locales or add them to the English locales\n\n#{formatted_keys.join("\n\n")}"
20
+ end
21
+
22
+ def missing_english_locales
23
+ all_locales.each_with_object({}) do |locale, hsh|
24
+ missing_keys = exclude_plurals(locale[:keys]) - english_keys_excluding_plurals(all_locales)
25
+
26
+ next if missing_keys.blank?
27
+
28
+ hsh[locale[:locale]] = missing_keys
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MissingForeignLocales < BaseChecker
4
+ include LocaleCheckerHelper
5
+
6
+ def report
7
+ grouped_missing_keys = group_keys(missing_foreign_locales)
8
+
9
+ format_missing_foreign_locales(grouped_missing_keys) if grouped_missing_keys.present?
10
+ end
11
+
12
+ private
13
+
14
+ def format_missing_foreign_locales(keys)
15
+ formatted_keys = keys.to_a.map do |group|
16
+ "\e[1mMissing foreign keys:\e[22m #{group[0]}\n\e[1mAbsent from:\e[22m #{group[1]}"
17
+ end
18
+
19
+ "\e[31m[ERROR]\e[0m Missing foreign locales, either add these keys to the foreign locales or remove them from the English locales\e[0m\n\n#{formatted_keys.join("\n\n")}"
20
+ end
21
+
22
+ def missing_foreign_locales
23
+ all_locales.each_with_object({}) do |locale, hsh|
24
+ missing_keys = english_keys_excluding_plurals(all_locales) - exclude_plurals(locale[:keys])
25
+
26
+ next if missing_keys.blank?
27
+
28
+ hsh[locale[:locale]] = missing_keys
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PluralForms
4
+ def self.all
5
+ I18n.available_locales.each_with_object({}) do |locale, hsh|
6
+ begin
7
+ # fetches plural form (rule) from rails-i18n for locale
8
+ plural_form = I18n.with_locale(locale) { I18n.t!("i18n.plural.keys") }.sort
9
+ rescue I18n::MissingTranslationData
10
+ plural_form = nil
11
+ end
12
+
13
+ hsh[locale.downcase] = plural_form
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsTranslationManager
4
+ class LocaleChecker
5
+ attr_reader :locale_path
6
+
7
+ CHECKER_CLASSES = [MissingEnglishLocales,
8
+ MissingForeignLocales,
9
+ IncompatiblePlurals].freeze
10
+
11
+ def initialize(locale_path)
12
+ @locale_path = locale_path
13
+ end
14
+
15
+ def validate_locales
16
+ output_result
17
+ rescue AllLocales::NoLocaleFilesFound => e
18
+ puts e
19
+ false
20
+ end
21
+
22
+ private
23
+
24
+ def output_result
25
+ errors = checker_errors.compact
26
+
27
+ if errors.blank?
28
+ puts "Locale files are in sync, nice job!"
29
+ true
30
+ else
31
+ errors.each do |error_message|
32
+ puts "\n"
33
+ puts error_message
34
+ puts "\n"
35
+ end
36
+ false
37
+ end
38
+ end
39
+
40
+ def checker_errors
41
+ CHECKER_CLASSES.flat_map do |checker|
42
+ checker.new(all_locales).report
43
+ end
44
+ end
45
+
46
+ def all_locales
47
+ @all_locales ||= AllLocales.new(locale_path).generate
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsTranslationManager
2
- VERSION = "0.0.2"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -1,9 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails_translation_manager/version"
2
4
  require "rails_translation_manager/railtie" if defined?(Rails)
3
5
  require "rails-i18n"
4
6
 
7
+ require "rails_translation_manager/locale_checker/base_checker"
8
+ require "rails_translation_manager/locale_checker/locale_checker_helper"
9
+ require "rails_translation_manager/locale_checker/missing_foreign_locales"
10
+ require "rails_translation_manager/locale_checker/missing_english_locales"
11
+ require "rails_translation_manager/locale_checker/plural_forms"
12
+ require "rails_translation_manager/locale_checker/incompatible_plurals"
13
+ require "rails_translation_manager/locale_checker/all_locales"
14
+ require "rails_translation_manager/locale_checker"
15
+ require "rails_translation_manager/cleaner"
16
+ require "rails_translation_manager/exporter"
17
+ require "rails_translation_manager/importer"
18
+
5
19
  module RailsTranslationManager
6
- autoload :Exporter, "rails_translation_manager/exporter"
7
- autoload :Importer, "rails_translation_manager/importer"
8
- autoload :Stealer, "rails_translation_manager/stealer"
20
+ rails_i18n_path = Gem::Specification.find_by_name("rails-i18n").gem_dir
21
+ rails_translation_manager = Gem::Specification.find_by_name("rails_translation_manager").gem_dir
22
+
23
+ I18n.load_path.concat(
24
+ Dir["#{rails_i18n_path}/rails/pluralization/*.rb"],
25
+ ["#{rails_translation_manager}/config/locales/plurals.rb"]
26
+ )
9
27
  end