locales_export_import 0.4.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c91842fd7a23da6ed15c5970ccf4d63b33752e9
4
+ data.tar.gz: 3d9633b6b9d4a0b2287d3547f66dfcfd79d84f6a
5
+ SHA512:
6
+ metadata.gz: 966f6da09f42a0ebaa78a9b62a30917efdc6818e8bc4f1bd7aad4d399398a0cf0871ccc1b3098dd119b16da2a9ff5adf26675641d8122af56e8d98782cf56cd3
7
+ data.tar.gz: 1bf96e26a12c707f5368610d924eba9d849e347b8a54241b5d713d225b10dbb04cc076fc8914200a4a178d2a330fbd73d54e6e445409d8ed0ce060f529b44551
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in locales_export_import.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 buru
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # LocalesExportImport
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'locales_export_import'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install locales_export_import
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,45 @@
1
+ require 'yaml'
2
+ require 'csv'
3
+
4
+ module LocalesExportImport
5
+ module Csv2Yaml
6
+ extend self
7
+
8
+ def convert(input_file)
9
+ @yaml = ::Hash.new
10
+ ::CSV.foreach(::File.join(input_file), :headers => true) do |row|
11
+ puts "inspect: #{row.inspect}"
12
+ key = row['key'].strip
13
+ row.headers.each do |header|
14
+ if header && header.end_with?('_value')
15
+ locale = header.partition('_').first
16
+ unless @yaml.has_key?(locale)
17
+ locale_file = ::File.join("#{locale}.yml")
18
+ @yaml[locale] = ::File.exists?(locale_file) ? ::YAML.load_file(locale_file) : ::Hash.new
19
+ end
20
+ value = row[header]
21
+ key_for_locale = [locale, key.partition('.').last].join('.')
22
+ puts "adding key: #{key_for_locale}"
23
+ add_value_to_tree(@yaml[locale], key_for_locale, value) unless value.blank?
24
+ end
25
+ end
26
+ end
27
+ puts "Resulting structure: #{@yaml.inspect}"
28
+ @yaml.keys.each do |locale|
29
+ output_file = ::File.join("#{locale}.yml")
30
+ ::File.write(output_file, @yaml[locale].to_yaml)
31
+ end
32
+ end
33
+
34
+ def add_value_to_tree(hash, key, value)
35
+ if !key.include?('.')
36
+ hash[key] = value if hash.is_a?(::Hash)
37
+ else
38
+ head, _, tail = key.partition('.')
39
+ hash[head] = ::Hash.new unless hash.has_key?(head)
40
+ add_value_to_tree(hash[head], tail, value)
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module LocalesExportImport
2
+ VERSION = "0.4.0"
3
+ end
@@ -0,0 +1,45 @@
1
+ require 'yaml'
2
+ require 'csv'
3
+
4
+ module LocalesExportImport
5
+ module Yaml2Csv
6
+ extend self
7
+
8
+ def convert(input_files, output_file, pattern = nil)
9
+ @arr = ::Array.new
10
+ @locales = ::Array.new
11
+ input_files.each do |input_file|
12
+ input_data = ::YAML.load_file(::File.join(input_file))
13
+ input_data.keys.each do |key|
14
+ # 1st level should contain only one key -- locale code
15
+ @locales << key
16
+ construct_csv_row(key, input_data[key], pattern)
17
+ end
18
+ end
19
+ ::CSV.open(::File.join(output_file), 'wb') do |csv|
20
+ # headers
21
+ csv << ['key', *@locales.map {|l| "#{l}_value"}]
22
+ @arr.each { |row| csv << row }
23
+ end
24
+ end
25
+
26
+ def construct_csv_row(key, value, pattern)
27
+ case value
28
+ when ::String
29
+ if !pattern || value =~ pattern
30
+ if @locales.length > 1 && (existing_key_index = @arr.find_index {|el| el.first.partition('.').last == key.partition('.').last})
31
+ @arr[existing_key_index] << value
32
+ else
33
+ @arr << [key, value]
34
+ end
35
+ end
36
+ when ::Array
37
+ # ignoring arrays to avoid having duplicate keys in CSV
38
+ # value.each { |v| construct_csv_row(key, v) }
39
+ when ::Hash
40
+ value.keys.each { |k| construct_csv_row("#{key}.#{k}", value[k], pattern) }
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ require "locales_export_import/version"
2
+
3
+ module LocalesExportImport
4
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'locales_export_import/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "locales_export_import"
8
+ spec.version = LocalesExportImport::VERSION
9
+ spec.authors = ["buru"]
10
+ spec.email = ["pavlozahozhenko@gmail.com"]
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 = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,34 @@
1
+ require 'locales_export_import/yaml2csv'
2
+
3
+ describe ::LocalesExportImport::Yaml2Csv do
4
+
5
+ let(:test_input_file_name) { ::File.join('spec', 'support', 'files', 'sample_locale.yml') }
6
+ let(:test_output_file_name) { ::File.join('spec', 'support', 'files', 'test.csv') }
7
+
8
+ after(:each) do
9
+ ::File.delete(test_output_file_name) if ::File.exist?(test_output_file_name)
10
+ end
11
+
12
+ it 'should convert yaml file to csv' do
13
+ subject.convert([test_input_file_name], test_output_file_name)
14
+ ::CSV.foreach(test_output_file_name, :headers => true, encoding: 'UTF-8') do |row|
15
+ if $. == 2
16
+ row['key'].should == 'de-DE.views.generic.back'
17
+ row['de-DE_value'].should == 'Zurück'
18
+ end
19
+ if $. == 61
20
+ row['key'].should == 'de-DE.emails.email_verification.from'
21
+ row['de-DE_value'].should == 'kundenservice@blacorp.com'
22
+ end
23
+ end
24
+ end
25
+
26
+ it 'should export only values matched by regex pattern' do
27
+ pattern = /Passwor.{1}/
28
+ subject.convert([test_input_file_name], test_output_file_name, pattern)
29
+ ::CSV.foreach(test_output_file_name, :headers => true, encoding: 'UTF-8') do |row|
30
+ row['de-DE_value'].should =~ pattern
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,72 @@
1
+ ---
2
+ de-DE:
3
+ views:
4
+ generic:
5
+ back: Zurück
6
+ cancel: Abbrechen
7
+ cheer: Gut
8
+ confirm: Bestätigen
9
+ send: Senden
10
+ edit: Bearbeiten
11
+ empty: Feld ausfüllen
12
+ euro_per_month: € / Monat
13
+ no_thanks: Nein, danke
14
+ whats_this: Was ist das?
15
+ "yes": Ja
16
+ "no": Nein
17
+ yes_please: Ja, bitte!
18
+ months: Monaten
19
+ continue: Weiter
20
+ or: oder
21
+ good_luck: Viel Glück!
22
+ chosen:
23
+ no_results: Kein Ergebnis für...gefunden
24
+ keep_typing: Weiter schreiben...
25
+ looking_for: Suchen nach
26
+ home:
27
+ answer_and_win: Antworten und gewinnen
28
+ best_deals: Großartige Preise.
29
+ keep_your_number_html: <b>Behalten Sie</b> Ihre bisherige Nummer
30
+ latest_devices: Aktuellste Geräte.
31
+ low_price_guarantee_html: Garantiert <b>niedriger</b> Preis
32
+ participate: Nehmen Sie an einer Umfrage teil
33
+ take_1min_survey: An einer 1-Minuten-Umfrage teilnehmen und 125.000 € gewinnen
34
+ win_up_to_html: <b>Gewinnen Sie</b> bis zu 200.000 €
35
+ pagination:
36
+ last: Vorige &raquo;
37
+ next: Nächste &rsaquo;
38
+ profile:
39
+ account_information: Bankverbindung
40
+ address: Straße
41
+ apply_changes: Speichern
42
+ change_password: Passwort ändern
43
+ code_send_to: 'Identifikationscode wurde an folgende Adresse gesendet:'
44
+ code_sent_to_number: 'Identifikationscode wurde an folgende Nummer gesandt:'
45
+ confirm_password: Passwort wiederholen
46
+ confirmed: Bestätigt
47
+ contact_details: Kontaktinformationen
48
+ current_password: Altes Passwort
49
+ elisa_viihde: 'Elisa Viihde:'
50
+ email_address: 'E-Mail Addresse:'
51
+ first_name: 'Vorname:'
52
+ gender: 'Geschlecht:'
53
+ last_name: 'Nachname:'
54
+ last_participation_date: 'Letzte Teilnahme:'
55
+ new_password: Neues Passwort
56
+ number_of_participations: 'Anzahl der Teilnahmen:'
57
+ operator: 'Netzbetreiber:'
58
+ password: 'Passwort:'
59
+ phone_number: 'Mobilfunknummer:'
60
+ residence: 'Wohnort:'
61
+ saunalahti_broadband: Telekom Breitband
62
+ signup_date: 'Registrierung:'
63
+ ssn: 'Persönliche ID:'
64
+ storey_and_apartment: 'Gebäudeteil:'
65
+ verification_code: Identifikationscode
66
+ year_of_birth: 'Geburtsjahr:'
67
+ zip_code: 'Postleitzahl:'
68
+ emails:
69
+ email_verification:
70
+ from: kundenservice@blacorp.com
71
+ subject: .PROMO Identifizierungscode
72
+ text: 'Der .PROMO Identifizierungscode für Ihre E-Mail Addresse lautet: %s'
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locales_export_import
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - buru
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Used for exporting locale yaml files to CSV format. CSV files are then
56
+ being imported into Excel, edited by translators, then imported back to yaml.
57
+ email:
58
+ - pavlozahozhenko@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/locales_export_import.rb
69
+ - lib/locales_export_import/csv2yaml.rb
70
+ - lib/locales_export_import/version.rb
71
+ - lib/locales_export_import/yaml2csv.rb
72
+ - locales_export_import.gemspec
73
+ - spec/locales_export_import/yaml2csv_spec.rb
74
+ - spec/support/files/sample_locale.yml
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Used for exporting and importing locale yaml files to CSV
99
+ test_files:
100
+ - spec/locales_export_import/yaml2csv_spec.rb
101
+ - spec/support/files/sample_locale.yml