locales_export_import 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc17ccfb4731014d4540fcf55ebc2b80e546e5de
4
- data.tar.gz: bfec6dc2a76f2d6f57d066b94a8c53ba7dae4103
3
+ metadata.gz: bfae435d4dffd15d0785048f1793fb44ae742900
4
+ data.tar.gz: 8339b98f2042f945bddb981266e84cf5c2831a17
5
5
  SHA512:
6
- metadata.gz: 7cf28a1cecdd3b12b48927104eaec1ad5a5de244074103e7173b1d0b1b6edd9d68ca4d9bac566891a5a3a7b211650b6f3ac91517974c13ec32700b0c7635fc8a
7
- data.tar.gz: b409b2ce3c923df0ecf5b1154e1204c91fc8c479ff934a777464fbec293431766fc0ec30b5ca118a9fb2cba300914b0d459c0476329d4d9a3d1f2dace31d029b
6
+ metadata.gz: 01b0aff8d8004d258898884828dc028e45917bdf4577d345e82b9a0d4a09abf913fec499f3e79733fd72c1c97e653618184bf74bca34f534382f6f1e54dfe5ab
7
+ data.tar.gz: 2eef69a756a94b7778c92cbc6c5a41efb52045d58309f9be82290d86decdff2e8228130f2fa8433675b5a100a84c7fe11753aaabec161c725d631b580094158f
data/README.md CHANGED
@@ -71,6 +71,21 @@ The result will be the locale file(s) in the current working directory, one file
71
71
  Note that if you already have one or several locale files in the same folder (e.g. en-UK.yml and de-DE.yml), these files will be loaded and updated with new values. That way you can import new portion of translations to already exsisting locale file, adding only the new ones while keeping the old keys/values inatact.
72
72
 
73
73
 
74
+ ##### Output options
75
+
76
+ If you have your own way to organize files with directories and names, you can pass an output_path and a file_prefix.
77
+
78
+ ```
79
+ LocalesExportImport::Csv2Yaml.convert(csv_file_name, 'config/locales/my_directory/sub_directory/', 'some_prefix_')
80
+ ````
81
+
82
+ And the result will be something like this:
83
+ ```
84
+ config/locales/my_directory/sub_directory/some_prefix_en.yml
85
+ ````
86
+
87
+ These arguments are optional.
88
+
74
89
  ## Contributing
75
90
 
76
91
  1. Fork it
@@ -1,6 +1,6 @@
1
- require "locales_export_import/version"
2
- require "locales_export_import/yaml2csv"
3
- require "locales_export_import/csv2yaml"
1
+ require 'locales_export_import/yaml2csv'
2
+ require 'locales_export_import/csv2yaml'
3
+ require 'locales_export_import/version'
4
4
 
5
5
  module LocalesExportImport
6
6
  end
@@ -4,8 +4,8 @@ require 'csv'
4
4
  module LocalesExportImport
5
5
  module Csv2Yaml
6
6
  extend self
7
-
8
- def convert(input_file)
7
+
8
+ def convert(input_file, output_path = nil, file_prefix = nil)
9
9
  @yaml = ::Hash.new
10
10
  ::CSV.foreach(::File.join(input_file), :headers => true) do |row|
11
11
  puts "inspect: #{row.inspect}"
@@ -14,21 +14,24 @@ module LocalesExportImport
14
14
  if header && header.end_with?('_value')
15
15
  locale = header.partition('_').first
16
16
  unless @yaml.has_key?(locale)
17
- locale_file = ::File.join("#{locale}.yml")
17
+ locale_file = get_output_file_name(locale, output_path, file_prefix)
18
18
  @yaml[locale] = ::File.exists?(locale_file) ? ::YAML.load_file(locale_file) : ::Hash.new
19
19
  end
20
20
  value = row[header]
21
21
  key_for_locale = [locale, key.partition('.').last].join('.')
22
22
  puts "adding key: #{key_for_locale}"
23
- add_value_to_tree(@yaml[locale], key_for_locale, value) unless value.blank?
23
+ add_value_to_tree(@yaml[locale], key_for_locale, value) unless value.nil? || value.empty?
24
24
  end
25
25
  end
26
26
  end
27
27
  puts "Resulting structure: #{@yaml.inspect}"
28
+ output_files = ::Array.new
28
29
  @yaml.keys.each do |locale|
29
- output_file = ::File.join("#{locale}.yml")
30
+ output_file = get_output_file_name(locale, output_path, file_prefix)
30
31
  ::File.write(output_file, @yaml[locale].to_yaml)
32
+ output_files << output_file
31
33
  end
34
+ return output_files, @yaml
32
35
  end
33
36
 
34
37
  def add_value_to_tree(hash, key, value)
@@ -40,6 +43,10 @@ module LocalesExportImport
40
43
  add_value_to_tree(hash[head], tail, value)
41
44
  end
42
45
  end
43
-
46
+
47
+ def get_output_file_name(locale, output_path, file_prefix)
48
+ ::File.join(*[output_path, "#{file_prefix}#{locale}.yml"].compact)
49
+ end
50
+
44
51
  end
45
52
  end
@@ -1,3 +1,3 @@
1
1
  module LocalesExportImport
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -4,21 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'locales_export_import/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "locales_export_import"
7
+ spec.name = 'locales_export_import'
8
8
  spec.version = LocalesExportImport::VERSION
9
- spec.authors = ["buru"]
10
- spec.email = ["pavlozahozhenko@gmail.com"]
9
+ spec.authors = ['buru', 'renatocn']
10
+ spec.email = ['pavlozahozhenko@gmail.com']
11
11
  spec.description = %q{Used for exporting locale yaml files to CSV format. CSV files are then being imported into Excel, edited by translators, then imported back to yaml.}
12
- spec.summary = "Used for exporting and importing locale yaml files to CSV"
13
- spec.homepage = "https://github.com/buru/locales_export_import"
14
- spec.license = "MIT"
12
+ spec.summary = 'Used for exporting and importing locale yaml files to CSV'
13
+ spec.homepage = 'https://github.com/buru/locales_export_import'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
23
- spec.add_development_dependency "rspec"
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake', '~> 0'
23
+ spec.add_development_dependency 'rspec', '~> 0'
24
24
  end
@@ -0,0 +1,56 @@
1
+ require 'locales_export_import'
2
+
3
+ describe ::LocalesExportImport::Csv2Yaml do
4
+
5
+ let(:test_input_file_name) { ::File.join('spec', 'support', 'files', 'sample_locale.csv') }
6
+ let(:test_output_file_name) { 'de-DE.yml' }
7
+ let(:custom_output_file_name) { ::File.join('spec', 'support', 'files', 'custom_de-DE.yml') }
8
+
9
+ context '#convert' do
10
+
11
+ after(:each) do
12
+ ::File.delete(test_output_file_name) if ::File.exist?(test_output_file_name)
13
+ ::File.delete(custom_output_file_name) if ::File.exist?(custom_output_file_name)
14
+ end
15
+
16
+ it 'should convert csv file to yaml named after appropriate locale' do
17
+ output_file_names, _ = subject.convert(test_input_file_name)
18
+ expect(output_file_names.first).to eq(test_output_file_name)
19
+ end
20
+
21
+ it 'should convert csv line into a hash' do
22
+ _, yaml_hash = subject.convert(test_input_file_name)
23
+ expect(yaml_hash['de-DE']['de-DE']['views']['generic']['cheer']).to eq('Gut')
24
+ end
25
+
26
+ it 'should output to custom directory with custom prefix if output options are given' do
27
+ output_file_names, _ = subject.convert(test_input_file_name, 'spec/support/files/', 'custom_')
28
+ expect(output_file_names.first).to eq(custom_output_file_name)
29
+ end
30
+
31
+ it 'should output to custom directory with if output path lacks trailing space' do
32
+ output_file_names, _ = subject.convert(test_input_file_name, 'spec/support/files', 'custom_')
33
+ expect(output_file_names.first).to eq(custom_output_file_name)
34
+ end
35
+
36
+ context 'edit existing locale file' do
37
+
38
+ before(:each) do
39
+ ::FileUtils.cp(::File.join('spec', 'support', 'files', 'de-DE.yml'), custom_output_file_name)
40
+ end
41
+
42
+ it 'should merge already existing output file contents with new output file with the same name' do
43
+ _, yaml_hash = subject.convert(test_input_file_name, 'spec/support/files', 'custom_')
44
+ expect(yaml_hash['de-DE']['de-DE']['views']['generic']['but']).to eq('aber')
45
+ end
46
+
47
+ it 'should override value in existing locale file' do
48
+ _, yaml_hash = subject.convert(test_input_file_name, 'spec/support/files', 'custom_')
49
+ expect(yaml_hash['de-DE']['de-DE']['views']['generic']['yes_please']).to eq('Ja, bitte!')
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -13,12 +13,12 @@ describe ::LocalesExportImport::Yaml2Csv do
13
13
  subject.convert([test_input_file_name], test_output_file_name)
14
14
  ::CSV.foreach(test_output_file_name, :headers => true, encoding: 'UTF-8') do |row|
15
15
  if $. == 2
16
- row['key'].should == 'de-DE.views.generic.back'
17
- row['de-DE_value'].should == 'Zurück'
16
+ expect(row['key']).to eq('de-DE.views.generic.back')
17
+ expect(row['de-DE_value']).to eq('Zurück')
18
18
  end
19
19
  if $. == 61
20
- row['key'].should == 'de-DE.emails.email_verification.from'
21
- row['de-DE_value'].should == 'kundenservice@blacorp.com'
20
+ expect(row['key']).to eq('de-DE.emails.email_verification.from')
21
+ expect(row['de-DE_value']).to eq('kundenservice@blacorp.com')
22
22
  end
23
23
  end
24
24
  end
@@ -27,7 +27,7 @@ describe ::LocalesExportImport::Yaml2Csv do
27
27
  pattern = /Passwor.{1}/
28
28
  subject.convert([test_input_file_name], test_output_file_name, pattern)
29
29
  ::CSV.foreach(test_output_file_name, :headers => true, encoding: 'UTF-8') do |row|
30
- row['de-DE_value'].should =~ pattern
30
+ expect(row['de-DE_value']).to match(pattern)
31
31
  end
32
32
  end
33
33
 
@@ -0,0 +1,5 @@
1
+ de-DE:
2
+ views:
3
+ generic:
4
+ but: aber
5
+ yes_please: Ja-ja!
@@ -0,0 +1,63 @@
1
+ key,de-DE_value
2
+ de-DE.views.generic.back,Zurück
3
+ de-DE.views.generic.cancel,Abbrechen
4
+ de-DE.views.generic.cheer,Gut
5
+ de-DE.views.generic.confirm,Bestätigen
6
+ de-DE.views.generic.send,Senden
7
+ de-DE.views.generic.edit,Bearbeiten
8
+ de-DE.views.generic.empty,Feld ausfüllen
9
+ de-DE.views.generic.euro_per_month,€ / Monat
10
+ de-DE.views.generic.no_thanks,"Nein, danke"
11
+ de-DE.views.generic.whats_this,Was ist das?
12
+ de-DE.views.generic.yes,Ja
13
+ de-DE.views.generic.no,Nein
14
+ de-DE.views.generic.yes_please,"Ja, bitte!"
15
+ de-DE.views.generic.months,Monaten
16
+ de-DE.views.generic.continue,Weiter
17
+ de-DE.views.generic.or,oder
18
+ de-DE.views.generic.good_luck,Viel Glück!
19
+ de-DE.views.generic.chosen.no_results,Kein Ergebnis für...gefunden
20
+ de-DE.views.generic.chosen.keep_typing,Weiter schreiben...
21
+ de-DE.views.generic.chosen.looking_for,Suchen nach
22
+ de-DE.views.home.answer_and_win,Antworten und gewinnen
23
+ de-DE.views.home.best_deals,Großartige Preise.
24
+ de-DE.views.home.keep_your_number_html,<b>Behalten Sie</b> Ihre bisherige Nummer
25
+ de-DE.views.home.latest_devices,Aktuellste Geräte.
26
+ de-DE.views.home.low_price_guarantee_html,Garantiert <b>niedriger</b> Preis
27
+ de-DE.views.home.participate,Nehmen Sie an einer Umfrage teil
28
+ de-DE.views.home.take_1min_survey,An einer 1-Minuten-Umfrage teilnehmen und 125.000 € gewinnen
29
+ de-DE.views.home.win_up_to_html,<b>Gewinnen Sie</b> bis zu 200.000 €
30
+ de-DE.views.pagination.last,Vorige &raquo;
31
+ de-DE.views.pagination.next,Nächste &rsaquo;
32
+ de-DE.views.profile.account_information,Bankverbindung
33
+ de-DE.views.profile.address,Straße
34
+ de-DE.views.profile.apply_changes,Speichern
35
+ de-DE.views.profile.change_password,Passwort ändern
36
+ de-DE.views.profile.code_send_to,Identifikationscode wurde an folgende Adresse gesendet:
37
+ de-DE.views.profile.code_sent_to_number,Identifikationscode wurde an folgende Nummer gesandt:
38
+ de-DE.views.profile.confirm_password,Passwort wiederholen
39
+ de-DE.views.profile.confirmed,Bestätigt
40
+ de-DE.views.profile.contact_details,Kontaktinformationen
41
+ de-DE.views.profile.current_password,Altes Passwort
42
+ de-DE.views.profile.elisa_viihde,Elisa Viihde:
43
+ de-DE.views.profile.email_address,E-Mail Addresse:
44
+ de-DE.views.profile.first_name,Vorname:
45
+ de-DE.views.profile.gender,Geschlecht:
46
+ de-DE.views.profile.last_name,Nachname:
47
+ de-DE.views.profile.last_participation_date,Letzte Teilnahme:
48
+ de-DE.views.profile.new_password,Neues Passwort
49
+ de-DE.views.profile.number_of_participations,Anzahl der Teilnahmen:
50
+ de-DE.views.profile.operator,Netzbetreiber:
51
+ de-DE.views.profile.password,Passwort:
52
+ de-DE.views.profile.phone_number,Mobilfunknummer:
53
+ de-DE.views.profile.residence,Wohnort:
54
+ de-DE.views.profile.saunalahti_broadband,Telekom Breitband
55
+ de-DE.views.profile.signup_date,Registrierung:
56
+ de-DE.views.profile.ssn,Persönliche ID:
57
+ de-DE.views.profile.storey_and_apartment,Gebäudeteil:
58
+ de-DE.views.profile.verification_code,Identifikationscode
59
+ de-DE.views.profile.year_of_birth,Geburtsjahr:
60
+ de-DE.views.profile.zip_code,Postleitzahl:
61
+ de-DE.emails.email_verification.from,kundenservice@blacorp.com
62
+ de-DE.emails.email_verification.subject,.PROMO Identifizierungscode
63
+ de-DE.emails.email_verification.text,Der .PROMO Identifizierungscode für Ihre E-Mail Addresse lautet: %s
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locales_export_import
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - buru
8
+ - renatocn
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-07-11 00:00:00.000000000 Z
12
+ date: 2016-06-18 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
@@ -28,28 +29,28 @@ dependencies:
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ">="
32
+ - - "~>"
32
33
  - !ruby/object:Gem::Version
33
34
  version: '0'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - ">="
39
+ - - "~>"
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rspec
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
- - - ">="
46
+ - - "~>"
46
47
  - !ruby/object:Gem::Version
47
48
  version: '0'
48
49
  type: :development
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
- - - ">="
53
+ - - "~>"
53
54
  - !ruby/object:Gem::Version
54
55
  version: '0'
55
56
  description: Used for exporting locale yaml files to CSV format. CSV files are then
@@ -70,7 +71,10 @@ files:
70
71
  - lib/locales_export_import/version.rb
71
72
  - lib/locales_export_import/yaml2csv.rb
72
73
  - locales_export_import.gemspec
74
+ - spec/locales_export_import/csv2yaml_spec.rb
73
75
  - spec/locales_export_import/yaml2csv_spec.rb
76
+ - spec/support/files/de-DE.yml
77
+ - spec/support/files/sample_locale.csv
74
78
  - spec/support/files/sample_locale.yml
75
79
  homepage: https://github.com/buru/locales_export_import
76
80
  licenses:
@@ -92,10 +96,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
96
  version: '0'
93
97
  requirements: []
94
98
  rubyforge_project:
95
- rubygems_version: 2.2.2
99
+ rubygems_version: 2.4.8
96
100
  signing_key:
97
101
  specification_version: 4
98
102
  summary: Used for exporting and importing locale yaml files to CSV
99
103
  test_files:
104
+ - spec/locales_export_import/csv2yaml_spec.rb
100
105
  - spec/locales_export_import/yaml2csv_spec.rb
106
+ - spec/support/files/de-DE.yml
107
+ - spec/support/files/sample_locale.csv
101
108
  - spec/support/files/sample_locale.yml
109
+ has_rdoc: