rails_translation_manager 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/rails_translation_manager/importer.rb +11 -1
- data/lib/rails_translation_manager/version.rb +1 -1
- data/lib/tasks/translation.rake +2 -2
- data/spec/locales/importer/fr.csv +1 -0
- data/spec/rails_translation_manager/importer_spec.rb +13 -0
- data/spec/tasks/translation_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbbde3519b97f6c9881189908af474ef24b5ad5dae1a3c6e3a590df8ca4b9885
|
4
|
+
data.tar.gz: f6ad0e6bf5584f6fa9db3b39d3a7d52c1b04786368c9297090a480690e2cf1e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: befae5c31f13ce323a367033180d58d7969220cde8eded8dd213a0de5405fd82246f0b775c3761d45e2412b25699630538896d6b2ec9692a4f030ea751f9282c
|
7
|
+
data.tar.gz: 25979414b9918d47b58e3f87caa2ba967dcca0bc233c37854f270b8e93f0f95940b3c0f54b7f658ea4ed144b463b740569bebe4c0dfd98907a8e82d02c10fd6f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 1.1.3
|
2
|
+
|
3
|
+
Handle importing files that contain rows with a blank "key". https://github.com/alphagov/rails_translation_manager/pull/28
|
4
|
+
|
1
5
|
## 1.1.2
|
2
6
|
|
3
7
|
Handle importing files that contain Byte Order Marks. https://github.com/alphagov/rails_translation_manager/pull/27
|
@@ -15,7 +15,9 @@ class RailsTranslationManager::Importer
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def import
|
18
|
-
csv =
|
18
|
+
csv = reject_nil_keys(
|
19
|
+
CSV.read(csv_path, encoding: "bom|utf-8", headers: true, header_converters: :downcase)
|
20
|
+
)
|
19
21
|
|
20
22
|
multiple_files_per_language ? import_csv_into_multiple_files(csv) : import_csv(csv)
|
21
23
|
end
|
@@ -40,6 +42,14 @@ class RailsTranslationManager::Importer
|
|
40
42
|
write_yaml(import_yml_path, { locale.to_s => data })
|
41
43
|
end
|
42
44
|
|
45
|
+
def reject_nil_keys(csv)
|
46
|
+
csv.reject do |row|
|
47
|
+
nil_key = row["key"].nil?
|
48
|
+
puts "Invalid row: #{row.inspect} for csv_path: #{csv_path}\n" if nil_key == true
|
49
|
+
nil_key
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
43
53
|
def parse_translation(translation)
|
44
54
|
if translation =~ /^\[/
|
45
55
|
values = translation.gsub(/^\[/, '').gsub(/\]$/, '').gsub("\"", '').split(/\s*,\s*/)
|
data/lib/tasks/translation.rake
CHANGED
@@ -42,7 +42,7 @@ namespace :translation do
|
|
42
42
|
)
|
43
43
|
importer.import
|
44
44
|
|
45
|
-
puts "
|
45
|
+
puts "\nImported CSV from: #{csv_path} to #{import_dir}"
|
46
46
|
end
|
47
47
|
|
48
48
|
namespace :import do
|
@@ -61,7 +61,7 @@ namespace :translation do
|
|
61
61
|
importer.import
|
62
62
|
end
|
63
63
|
|
64
|
-
puts "
|
64
|
+
puts "\nImported all CSVs from: #{directory} to #{import_dir}"
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -16,6 +16,19 @@ RSpec.describe RailsTranslationManager::Importer do
|
|
16
16
|
expect(File).to exist(import_directory + "/hy.yml")
|
17
17
|
end
|
18
18
|
|
19
|
+
it "doesn't try to import a row with a blank key" do
|
20
|
+
importer = described_class.new(
|
21
|
+
locale: "hy",
|
22
|
+
csv_path: "spec/locales/importer/fr.csv",
|
23
|
+
import_directory: import_directory,
|
24
|
+
multiple_files_per_language: false
|
25
|
+
)
|
26
|
+
|
27
|
+
expect { importer.import }.to output(
|
28
|
+
"Invalid row: #<CSV::Row \"key\":nil \"source\":nil \"translation\":nil> for csv_path: spec/locales/importer/fr.csv\n"
|
29
|
+
).to_stdout
|
30
|
+
end
|
31
|
+
|
19
32
|
context "when there is one locale file per language" do
|
20
33
|
let(:yaml_translation_data) { YAML.load_file(import_directory + "/fr.yml")["fr"] }
|
21
34
|
|
@@ -15,7 +15,7 @@ describe "rake tasks" do
|
|
15
15
|
|
16
16
|
it "outputs to stdout" do
|
17
17
|
expect { task.execute(csv_path: csv_path) }
|
18
|
-
.to output("
|
18
|
+
.to output("\nImported CSV from: #{csv_path} to #{Rails.root.join("config", "locales")}\n")
|
19
19
|
.to_stdout
|
20
20
|
end
|
21
21
|
|
@@ -39,7 +39,7 @@ describe "rake tasks" do
|
|
39
39
|
|
40
40
|
it "outputs to stdout" do
|
41
41
|
expect { task.execute(csv_directory: csv_directory) }
|
42
|
-
.to output("
|
42
|
+
.to output("\nImported all CSVs from: #{csv_directory} to #{Rails.root.join("config", "locales")}\n")
|
43
43
|
.to_stdout
|
44
44
|
end
|
45
45
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_translation_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edd Sowden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|