rails_translation_manager 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e7ef3e878a1b5ffc7ae48ad8f683887e79073b3f34a5a3439656f5f7abb6e20
4
- data.tar.gz: 2aac75f9cae7275812da73da0973de515baf0d78eb63e64182e683f8717696ca
3
+ metadata.gz: fbbde3519b97f6c9881189908af474ef24b5ad5dae1a3c6e3a590df8ca4b9885
4
+ data.tar.gz: f6ad0e6bf5584f6fa9db3b39d3a7d52c1b04786368c9297090a480690e2cf1e7
5
5
  SHA512:
6
- metadata.gz: f0b2fa6abaadb21ea912976b1092c6459ea0194a8e19092c522e38224da218395d230936d0d4a0aa830e3d37bd9f6eb6ac1e4909bd5406369c0aa99d1a4d13f4
7
- data.tar.gz: 0dbbefe8208052b63f5ddc80734340ed7985b199f9113aaf5457c48d50e34e889e7379a20c61963b002343f4fb0d35aacc0307b442a15a2b7fbdea77c25349dd
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 = CSV.read(csv_path, encoding: "bom|utf-8", headers: true, header_converters: :downcase)
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*/)
@@ -1,3 +1,3 @@
1
1
  module RailsTranslationManager
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -42,7 +42,7 @@ namespace :translation do
42
42
  )
43
43
  importer.import
44
44
 
45
- puts "Imported CSV from: #{csv_path} to #{import_dir}"
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 "Imported all CSVs from: #{directory} to #{import_dir}"
64
+ puts "\nImported all CSVs from: #{directory} to #{import_dir}"
65
65
  end
66
66
  end
67
67
 
@@ -6,3 +6,4 @@ world_location.sentiment,:whatever,:bof
6
6
  shared.price,123,123
7
7
  shared.key1,is true,true
8
8
  shared.key2,is false,false
9
+ ,,
@@ -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("Imported CSV from: #{csv_path} to #{Rails.root.join("config", "locales")}\n")
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("Imported all CSVs from: #{csv_directory} to #{Rails.root.join("config", "locales")}\n")
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.2
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-05 00:00:00.000000000 Z
11
+ date: 2021-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport