rails_translation_manager 0.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +23 -0
- data/Jenkinsfile +9 -0
- data/LICENSE.txt +1 -1
- data/README.md +57 -1
- data/Rakefile +14 -9
- data/config/locales/plurals.rb +49 -0
- data/lib/rails_translation_manager/cleaner.rb +14 -0
- data/lib/rails_translation_manager/importer.rb +35 -19
- data/lib/rails_translation_manager/locale_checker/all_locales.rb +61 -0
- data/lib/rails_translation_manager/locale_checker/base_checker.rb +13 -0
- data/lib/rails_translation_manager/locale_checker/incompatible_plurals.rb +79 -0
- data/lib/rails_translation_manager/locale_checker/locale_checker_helper.rb +23 -0
- data/lib/rails_translation_manager/locale_checker/missing_english_locales.rb +31 -0
- data/lib/rails_translation_manager/locale_checker/missing_foreign_locales.rb +31 -0
- data/lib/rails_translation_manager/locale_checker/plural_forms.rb +16 -0
- data/lib/rails_translation_manager/locale_checker.rb +50 -0
- data/lib/rails_translation_manager/version.rb +1 -1
- data/lib/rails_translation_manager/yaml_writer.rb +17 -0
- data/lib/rails_translation_manager.rb +21 -2
- data/lib/tasks/translation.rake +37 -28
- data/lib/tasks/translation_helper.rb +11 -0
- data/rails_translation_manager.gemspec +4 -1
- data/spec/locales/cleaner/clean.yml +5 -0
- data/spec/locales/cleaner/with_whitespace.yml +5 -0
- data/spec/locales/importer/fr.csv +8 -0
- data/spec/locales/in_sync/cy/browse.yml +12 -0
- data/spec/locales/in_sync/en/browse.yml +8 -0
- data/spec/locales/out_of_sync/cy.yml +3 -0
- data/spec/locales/out_of_sync/en.yml +6 -0
- data/spec/rails_translation_manager/cleaner_spec.rb +13 -0
- data/spec/rails_translation_manager/importer_spec.rb +81 -0
- data/spec/rails_translation_manager/locale_checker/all_locales_spec.rb +24 -0
- data/spec/rails_translation_manager/locale_checker/incompatible_plurals_spec.rb +94 -0
- data/spec/rails_translation_manager/locale_checker/locale_checker_helper_spec.rb +61 -0
- data/spec/rails_translation_manager/locale_checker/missing_english_locales_spec.rb +72 -0
- data/spec/rails_translation_manager/locale_checker/missing_foreign_locales_spec.rb +80 -0
- data/spec/rails_translation_manager/locale_checker/plural_forms_spec.rb +27 -0
- data/spec/rails_translation_manager/locale_checker_spec.rb +68 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/tasks.rb +7 -0
- data/spec/tasks/translation_spec.rb +123 -0
- data/test/rails_translation_manager/yaml_writer_test.rb +60 -0
- data/tmp/.gitkeep +0 -0
- metadata +104 -13
- data/lib/rails_translation_manager/validator.rb +0 -92
- data/test/rails_translation_manager/importer_test.rb +0 -166
- data/test/rails_translation_manager/validator_test.rb +0 -51
@@ -1,166 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
require "rails_translation_manager/importer"
|
3
|
-
require "tmpdir"
|
4
|
-
require "csv"
|
5
|
-
|
6
|
-
module RailsTranslationManager
|
7
|
-
class ImporterTest < Minitest::Test
|
8
|
-
test 'should create a new locale file for a filled in translation csv file' do
|
9
|
-
given_csv(:fr,
|
10
|
-
[:key, :source, :translation],
|
11
|
-
["world_location.type.country", "Country", "Pays"],
|
12
|
-
["world_location.country", "Germany", "Allemange"],
|
13
|
-
["other.nested.key", "original", "translated"]
|
14
|
-
)
|
15
|
-
|
16
|
-
Importer.new(:fr, csv_path(:fr), import_directory).import
|
17
|
-
|
18
|
-
yaml_translation_data = YAML.load_file(File.join(import_directory, "fr.yml"))
|
19
|
-
expected = {"fr" => {
|
20
|
-
"world_location" => {
|
21
|
-
"country" => "Allemange",
|
22
|
-
"type" => {
|
23
|
-
"country" => "Pays"
|
24
|
-
}
|
25
|
-
},
|
26
|
-
"other" => {
|
27
|
-
"nested" => {
|
28
|
-
"key" => "translated"
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}}
|
32
|
-
assert_equal expected, yaml_translation_data
|
33
|
-
end
|
34
|
-
|
35
|
-
test 'outputs YAML without the header --- line for consistency with convention' do
|
36
|
-
given_csv(:fr,
|
37
|
-
[:key, :source, :translation],
|
38
|
-
["key", "value", "le value"],
|
39
|
-
)
|
40
|
-
|
41
|
-
Importer.new(:fr, csv_path(:fr), import_directory).import
|
42
|
-
|
43
|
-
assert_equal "fr:", File.readlines(File.join(import_directory, "fr.yml")).first.strip
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'outputs a newline at the end of the YAML for consistency with code editors' do
|
47
|
-
given_csv(:fr,
|
48
|
-
[:key, :source, :translation],
|
49
|
-
["key", "value", "le value"],
|
50
|
-
)
|
51
|
-
|
52
|
-
Importer.new(:fr, csv_path(:fr), import_directory).import
|
53
|
-
|
54
|
-
assert_match /\n$/, File.readlines(File.join(import_directory, "fr.yml")).last
|
55
|
-
end
|
56
|
-
|
57
|
-
test 'strips whitespace from the end of lines for consistency with code editors' do
|
58
|
-
given_csv(:fr,
|
59
|
-
[:key, :source, :translation],
|
60
|
-
["key", "value", nil],
|
61
|
-
)
|
62
|
-
|
63
|
-
Importer.new(:fr, csv_path(:fr), import_directory).import
|
64
|
-
|
65
|
-
lines = File.readlines(File.join(import_directory, "fr.yml"))
|
66
|
-
refute lines.any? { |line| line =~ /\s\n$/ }
|
67
|
-
end
|
68
|
-
|
69
|
-
test 'imports arrays from CSV as arrays' do
|
70
|
-
given_csv(:fr,
|
71
|
-
[:key, :source, :translation],
|
72
|
-
["fruit", ["Apples", "Bananas", "Pears"], ["Pommes", "Bananes", "Poires"]]
|
73
|
-
)
|
74
|
-
|
75
|
-
Importer.new(:fr, csv_path(:fr), import_directory).import
|
76
|
-
|
77
|
-
yaml_translation_data = YAML.load_file(File.join(import_directory, "fr.yml"))
|
78
|
-
expected = {"fr" => {
|
79
|
-
"fruit" => ["Pommes", "Bananes", "Poires"]
|
80
|
-
}}
|
81
|
-
assert_equal expected, yaml_translation_data
|
82
|
-
end
|
83
|
-
|
84
|
-
test 'interprets string "nil" as nil' do
|
85
|
-
given_csv(:fr,
|
86
|
-
[:key, :source, :translation],
|
87
|
-
["things", ["one", nil, "two"], ["une", nil, "deux"]]
|
88
|
-
)
|
89
|
-
|
90
|
-
Importer.new(:fr, csv_path(:fr), import_directory).import
|
91
|
-
|
92
|
-
yaml_translation_data = YAML.load_file(File.join(import_directory, "fr.yml"))
|
93
|
-
expected = {"fr" => {
|
94
|
-
"things" => ["une", nil, "deux"]
|
95
|
-
}}
|
96
|
-
assert_equal expected, yaml_translation_data
|
97
|
-
end
|
98
|
-
|
99
|
-
test 'interprets string ":thing" as symbol' do
|
100
|
-
given_csv(:fr,
|
101
|
-
[:key, :source, :translation],
|
102
|
-
["sentiment", ":whatever", ":bof"]
|
103
|
-
)
|
104
|
-
|
105
|
-
Importer.new(:fr, csv_path(:fr), import_directory).import
|
106
|
-
|
107
|
-
yaml_translation_data = YAML.load_file(File.join(import_directory, "fr.yml"))
|
108
|
-
expected = {"fr" => {
|
109
|
-
"sentiment" => :bof
|
110
|
-
}}
|
111
|
-
assert_equal expected, yaml_translation_data
|
112
|
-
end
|
113
|
-
|
114
|
-
test 'interprets integer strings as integers' do
|
115
|
-
given_csv(:fr,
|
116
|
-
[:key, :source, :translation],
|
117
|
-
["price", "123", "123"]
|
118
|
-
)
|
119
|
-
|
120
|
-
Importer.new(:fr, csv_path(:fr), import_directory).import
|
121
|
-
|
122
|
-
yaml_translation_data = YAML.load_file(File.join(import_directory, "fr.yml"))
|
123
|
-
expected = {"fr" => {
|
124
|
-
"price" => 123
|
125
|
-
}}
|
126
|
-
assert_equal expected, yaml_translation_data
|
127
|
-
end
|
128
|
-
|
129
|
-
test 'interprets boolean values as booleans, not strings' do
|
130
|
-
given_csv(:fr,
|
131
|
-
[:key, :source, :translation],
|
132
|
-
["key1", "is true", "true"],
|
133
|
-
["key2", "is false", "false"]
|
134
|
-
)
|
135
|
-
|
136
|
-
Importer.new(:fr, csv_path(:fr), import_directory).import
|
137
|
-
|
138
|
-
yaml_translation_data = YAML.load_file(File.join(import_directory, "fr.yml"))
|
139
|
-
expected = {"fr" => {
|
140
|
-
"key1" => true,
|
141
|
-
"key2" => false
|
142
|
-
}}
|
143
|
-
assert_equal expected, yaml_translation_data
|
144
|
-
end
|
145
|
-
|
146
|
-
private
|
147
|
-
|
148
|
-
def csv_path(locale)
|
149
|
-
File.join(import_directory, "#{locale}.csv")
|
150
|
-
end
|
151
|
-
|
152
|
-
def given_csv(locale, header_row, *rows)
|
153
|
-
csv = CSV.generate do |csv|
|
154
|
-
csv << CSV::Row.new(["key", "source", "translation"], ["key", "source", "translation"], true)
|
155
|
-
rows.each do |row|
|
156
|
-
csv << CSV::Row.new(["key", "source", "translation"], row)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
File.open(csv_path(locale), "w") { |f| f.write csv.to_s }
|
160
|
-
end
|
161
|
-
|
162
|
-
def import_directory
|
163
|
-
@import_directory ||= Dir.mktmpdir
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'test_helper'
|
3
|
-
require 'rails_translation_manager/validator'
|
4
|
-
require 'tmpdir'
|
5
|
-
require 'fileutils'
|
6
|
-
|
7
|
-
module RailsTranslationManager
|
8
|
-
class ValidatorTest < Minitest::Test
|
9
|
-
def setup
|
10
|
-
@translation_path = Dir.mktmpdir
|
11
|
-
@translation_validator = Validator.new(@translation_path)
|
12
|
-
end
|
13
|
-
|
14
|
-
def teardown
|
15
|
-
FileUtils.remove_entry_secure(@translation_path)
|
16
|
-
end
|
17
|
-
|
18
|
-
def create_translation_file(locale, content)
|
19
|
-
File.open(File.join(@translation_path, "#{locale}.yml"), "w") do |f|
|
20
|
-
f.write(content.lstrip)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
test "can create a flattened list of substitutions" do
|
25
|
-
translation_file = YAML.load(%q{
|
26
|
-
en:
|
27
|
-
view: View '%{title}'
|
28
|
-
test: foo
|
29
|
-
})
|
30
|
-
expected = [Validator::TranslationEntry.new(%w{en view}, "View '%{title}'")]
|
31
|
-
assert_equal expected, @translation_validator.substitutions_in(translation_file)
|
32
|
-
end
|
33
|
-
|
34
|
-
test "detects extra substitution keys" do
|
35
|
-
create_translation_file("en", %q{
|
36
|
-
en:
|
37
|
-
document:
|
38
|
-
view: View '%{title}'
|
39
|
-
})
|
40
|
-
create_translation_file("sr", %q{
|
41
|
-
sr:
|
42
|
-
document:
|
43
|
-
view: Pročitajte '%{naslov}'
|
44
|
-
})
|
45
|
-
errors = Validator.new(@translation_path).check!
|
46
|
-
|
47
|
-
expected = %q{Key "sr.document.view": Extra substitutions: ["naslov"]. Missing substitutions: ["title"].}
|
48
|
-
assert_equal [expected], errors.map(&:to_s)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|