i18n-docs 0.0.10 → 0.1.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 +4 -4
- data/README.md +38 -2
- data/i18n-docs.gemspec +3 -2
- data/lib/i18n_docs/csv_to_yaml.rb +12 -6
- data/lib/i18n_docs/missing_keys_finder.rb +4 -4
- data/lib/i18n_docs/translation_file_export.rb +1 -1
- data/lib/i18n_docs/translations.rb +1 -3
- data/lib/i18n_docs/version.rb +1 -1
- data/lib/tasks/store_translations.rake +5 -10
- data/test/fixtures/config.yml +1 -1
- data/test/fixtures/error.csv +3 -0
- data/test/test_helper.rb +1 -4
- data/test/unit/csv_to_yaml_test.rb +11 -2
- data/test/unit/translation_file_export_test.rb +2 -2
- data/test/unit/translations_test.rb +9 -9
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dfaf572b4a18ef1c85ae6641dba030ca833fc2f
|
4
|
+
data.tar.gz: 85391361b7c3c7f2eea154a7aa5bed34b15e0ccb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90bb038ed0f6651347019398af8373e8f1daf84007e70531e3aecb7a6c5f6952f9f7850078253cad119ba56cf4b92f6447e58290230ce6b218df8e079753fe32
|
7
|
+
data.tar.gz: 388126fd79d675b78b541c99da04c0b384eb10ad07562d59e0676320535c50e0d320fe5a530898922e76c398d9fc9086ee88570ff5900eadd19123e9c58941e5
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Although we use it with Google Docs, it could be used with any CSV file.
|
|
16
16
|
|
17
17
|
### Configuration
|
18
18
|
|
19
|
-
Add the GEM to your
|
19
|
+
Add the GEM to your project:
|
20
20
|
|
21
21
|
gem 'i18n-docs'
|
22
22
|
|
@@ -27,6 +27,8 @@ Create a configuration file in `config/translations.yml`:
|
|
27
27
|
forms.yml: "https://docs.google.com/spreadsheet/pub?key=0Ap...XveWc&single=true&gid=0&output=csv"
|
28
28
|
... etc ...
|
29
29
|
|
30
|
+
#### Rails
|
31
|
+
|
30
32
|
Finally, let Rails know what locales you will be using. Add this to `config/application.rb`:
|
31
33
|
|
32
34
|
module Web
|
@@ -40,6 +42,41 @@ Finally, let Rails know what locales you will be using. Add this to `config/appl
|
|
40
42
|
|
41
43
|
This defines which languages and translation files to import from a Google Spreadsheet. The content of the Spreadsheet URL is stored to a file called e.g. `example1.yml` within folders `config/locales/en` and all other detected locales.
|
42
44
|
|
45
|
+
#### Non Rails
|
46
|
+
|
47
|
+
Load rake tasks in your `Rakefile`:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'i18n-docs'
|
51
|
+
|
52
|
+
spec = Gem::Specification.find_by_name 'i18n-docs'
|
53
|
+
load "#{spec.gem_dir}/lib/tasks/store_translations.rake"
|
54
|
+
```
|
55
|
+
|
56
|
+
Create `environment` task in your `Rakefile`:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
task :environment do
|
60
|
+
...
|
61
|
+
end
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
The minimal scope of this task is to set up `I18n.available_locales`.
|
66
|
+
|
67
|
+
Translations will be stored under `config/locales` in project root directory.
|
68
|
+
Don't forget to setup `I18n` accordingly:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
I18n.load_path = Dir[File.join(MyProject.root, 'config', 'locales', '**', '*.yml')]
|
72
|
+
```
|
73
|
+
|
74
|
+
And to load them:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
I18n.backend.load_translations
|
78
|
+
```
|
79
|
+
|
43
80
|
### Rake Tasks
|
44
81
|
|
45
82
|
Following Rake tasks are added by the GEM to your Rails project:
|
@@ -116,4 +153,3 @@ Follow this: http://stackoverflow.com/questions/12562697/opensslsslsslerror-ssl-
|
|
116
153
|
### Credits/License
|
117
154
|
|
118
155
|
This gem is sponsored by [local.ch](http://www.local.ch/). It is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License). If you're a ruby developer and want to work with us in Switzerland, please check out our [jobs page](http://local-ch.github.com/).
|
119
|
-
|
data/i18n-docs.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.date = '2013-05-10'
|
10
10
|
s.summary = "Maintain translations in Google Docs and export them to your Rails project."
|
11
11
|
s.description = "GEM providing helper scripts to manage i18n translations in Google Docs. Features: check YAML files for missing translations; export YAML files to CSV; download translations from multiple Google spreadsheets and store to YAML files"
|
12
|
-
s.authors = ["Georg Kunz", "Ivan Jovanovic", "Jeremy Seitz", "Eduard Schäli", "Robin Wunderlin", "Esteban Pastorino"]
|
13
|
-
s.email = '
|
12
|
+
s.authors = ["Georg Kunz", "Ivan Jovanovic", "Jeremy Seitz", "Eduard Schäli", "Robin Wunderlin", "Esteban Pastorino", "Krzysztof Sakwerda"]
|
13
|
+
s.email = 'eduard.schaeli@localsearch.ch'
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.homepage = 'https://github.com/local-ch/i18n-docs'
|
16
16
|
|
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency('rake')
|
19
19
|
|
20
20
|
s.add_development_dependency('mocha', '~> 0.13.3')
|
21
|
+
s.add_development_dependency('test-unit', '~> 3.1.7')
|
21
22
|
end
|
@@ -4,6 +4,10 @@ module I18nDocs
|
|
4
4
|
|
5
5
|
attr_reader :input_file, :output_file, :locales, :translations
|
6
6
|
|
7
|
+
def self.root_path
|
8
|
+
@root_path ||= defined?(Rails) ? Rails.root : Pathname.new(Dir.pwd)
|
9
|
+
end
|
10
|
+
|
7
11
|
def initialize(input_file, output_file, locales = [])
|
8
12
|
@input_file = input_file
|
9
13
|
@output_file = File.basename(output_file)
|
@@ -19,12 +23,9 @@ module I18nDocs
|
|
19
23
|
|
20
24
|
def write_files
|
21
25
|
@locales.each do |locale|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
else
|
26
|
-
output_file_path = "#{locale}_#{@output_file}"
|
27
|
-
end
|
26
|
+
output_file_path = self.class.root_path.join('config', 'locales', locale, @output_file)
|
27
|
+
FileUtils.mkdir_p File.dirname(output_file_path)
|
28
|
+
|
28
29
|
File.open(output_file_path, 'w') do |file|
|
29
30
|
final_translation_hash = {locale => @translations[locale]}
|
30
31
|
file.puts YAML::dump(final_translation_hash)
|
@@ -71,6 +72,11 @@ module I18nDocs
|
|
71
72
|
raise "Error around key '#{keys.join '.'}': Expected #{memo.inspect} to be a Hash"
|
72
73
|
end
|
73
74
|
end
|
75
|
+
|
76
|
+
if data_hash.is_a? String
|
77
|
+
raise "Error around key '#{keys.join '.'}': Expected #{data_hash.inspect} to be a Hash"
|
78
|
+
end
|
79
|
+
|
74
80
|
data_hash[leaf] = value
|
75
81
|
end
|
76
82
|
|
@@ -71,10 +71,10 @@ module I18nDocs
|
|
71
71
|
|
72
72
|
def collect_keys(scope, translations)
|
73
73
|
full_keys = []
|
74
|
-
translations.to_a.each do |key,
|
74
|
+
translations.to_a.each do |key, translation|
|
75
75
|
new_scope = scope.dup << key
|
76
|
-
if
|
77
|
-
full_keys += collect_keys(new_scope,
|
76
|
+
if translation.is_a?(Hash)
|
77
|
+
full_keys += collect_keys(new_scope, translation)
|
78
78
|
else
|
79
79
|
full_keys << new_scope.join('.')
|
80
80
|
end
|
@@ -102,7 +102,7 @@ module I18nDocs
|
|
102
102
|
@yaml = {}
|
103
103
|
begin
|
104
104
|
@yaml = YAML.load_file(File.join(Rails.root, 'config', 'ignore_missing_i18n_keys.yml'))
|
105
|
-
rescue
|
105
|
+
rescue
|
106
106
|
STDERR.puts "No ignore_missing_keys.yml config file."
|
107
107
|
end
|
108
108
|
|
@@ -52,7 +52,7 @@ module I18nDocs
|
|
52
52
|
|
53
53
|
input_file = File.join(@source_dir, locale, @source_file)
|
54
54
|
translations = {}
|
55
|
-
translations = YAML.load_file(input_file) if File.
|
55
|
+
translations = YAML.load_file(input_file) if File.exist?(input_file)
|
56
56
|
translations[locale]
|
57
57
|
end
|
58
58
|
|
@@ -26,7 +26,7 @@ module I18nDocs
|
|
26
26
|
|
27
27
|
def load_config
|
28
28
|
@settings = {}
|
29
|
-
@settings = YAML.load_file(config_file) if File.
|
29
|
+
@settings = YAML.load_file(config_file) if File.exist?(config_file)
|
30
30
|
end
|
31
31
|
|
32
32
|
def download_files
|
@@ -69,5 +69,3 @@ module I18nDocs
|
|
69
69
|
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
73
|
-
|
data/lib/i18n_docs/version.rb
CHANGED
@@ -9,12 +9,11 @@ namespace :i18n do
|
|
9
9
|
|
10
10
|
desc "Download translations from Google Spreadsheet and save them to YAML files."
|
11
11
|
task :import_translations => :environment do
|
12
|
-
raise "'Rails' not found! Tasks can only run within a Rails application!" if !defined?(Rails)
|
13
12
|
|
14
|
-
config_file =
|
15
|
-
raise "No config file 'config/translations.yml' found." if !File.
|
13
|
+
config_file = I18nDocs::CsvToYaml.root_path.join('config', 'translations.yml')
|
14
|
+
raise "No config file 'config/translations.yml' found." if !File.exist?(config_file)
|
16
15
|
|
17
|
-
tmp_dir =
|
16
|
+
tmp_dir = I18nDocs::CsvToYaml.root_path.join('tmp')
|
18
17
|
Dir.mkdir(tmp_dir) unless Dir.exist?(tmp_dir)
|
19
18
|
|
20
19
|
translations = I18nDocs::Translations.new(config_file, tmp_dir)
|
@@ -26,10 +25,8 @@ namespace :i18n do
|
|
26
25
|
|
27
26
|
desc "Export all language files to CSV files (only files contained in en folder are considered)"
|
28
27
|
task :export_translations => :environment do
|
29
|
-
|
30
|
-
|
31
|
-
source_dir = Rails.root.join('config', 'locales')
|
32
|
-
output_dir = Rails.root.join('tmp')
|
28
|
+
source_dir = I18nDocs::CsvToYaml.root_path.join('config', 'locales')
|
29
|
+
output_dir = I18nDocs::CsvToYaml.root_path.join('tmp')
|
33
30
|
locales = I18n.available_locales
|
34
31
|
|
35
32
|
input_files = Dir[File.join(source_dir, ENV['locale'] || 'en', '*.yml')]
|
@@ -54,5 +51,3 @@ namespace :i18n do
|
|
54
51
|
end
|
55
52
|
|
56
53
|
end
|
57
|
-
|
58
|
-
|
data/test/fixtures/config.yml
CHANGED
@@ -6,4 +6,4 @@
|
|
6
6
|
# second.yml: http://www.google.com/spreadsheet/second.csv
|
7
7
|
#
|
8
8
|
files:
|
9
|
-
download.yml: "https://docs.google.com/
|
9
|
+
download.yml: "https://docs.google.com/spreadsheets/d/1PbmkqamXuNyP7gnVARpeCfV8rA7WvX98dTqsQB3Wdts/pub?output=csv"
|
data/test/test_helper.rb
CHANGED
@@ -16,7 +16,7 @@ module TestHelper
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def create_tmp_dir
|
19
|
-
FileUtils::mkdir(tmp_dir) if ! File.
|
19
|
+
FileUtils::mkdir(tmp_dir) if ! File.exist?(tmp_dir)
|
20
20
|
end
|
21
21
|
|
22
22
|
def remove_tmp_dir
|
@@ -24,6 +24,3 @@ module TestHelper
|
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
@@ -134,10 +134,10 @@ module UnitTests
|
|
134
134
|
end
|
135
135
|
|
136
136
|
def test_write_files
|
137
|
-
assert !File.
|
137
|
+
assert !File.exist?(@output_file)
|
138
138
|
@csv_to_yaml.process
|
139
139
|
@csv_to_yaml.write_files
|
140
|
-
assert File.
|
140
|
+
assert File.exist?(@output_file)
|
141
141
|
end
|
142
142
|
|
143
143
|
def test_key_has_spaces
|
@@ -149,5 +149,14 @@ module UnitTests
|
|
149
149
|
assert_equal 'yes', translations['en']['has']['space']
|
150
150
|
end
|
151
151
|
|
152
|
+
def test_wrong_csv_format_error_message
|
153
|
+
@input_file = File.join(fixture_path, 'error.csv')
|
154
|
+
@csv_to_yaml = I18nDocs::CsvToYaml.new(@input_file, @output_file, @locales)
|
155
|
+
|
156
|
+
assert_raise "Error around key 'top_level.key.another_key': Expected \"Value2\" to be a Hash" do
|
157
|
+
@csv_to_yaml.process
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
152
161
|
end
|
153
162
|
end
|
@@ -24,9 +24,9 @@ module UnitTests
|
|
24
24
|
|
25
25
|
|
26
26
|
def test_export
|
27
|
-
assert !File.
|
27
|
+
assert !File.exist?(@output_file)
|
28
28
|
@exporter.export
|
29
|
-
assert File.
|
29
|
+
assert File.exist?(@output_file), "Expected to have a CSV file written"
|
30
30
|
end
|
31
31
|
|
32
32
|
def dtest_load_language
|
@@ -26,33 +26,33 @@ module UnitTests
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_download
|
29
|
-
assert !File.
|
30
|
-
@translations.download("https://docs.google.com/
|
31
|
-
assert File.
|
29
|
+
assert !File.exist?(@tmp_file)
|
30
|
+
@translations.download("https://docs.google.com/spreadsheets/d/1PbmkqamXuNyP7gnVARpeCfV8rA7WvX98dTqsQB3Wdts/pub?output=csv", @tmp_file)
|
31
|
+
assert File.exist?(@tmp_file), "Expected to have downloaded Google Spreadsheet to '#{@tmp_file}'"
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_cleanup
|
35
35
|
@translations.csv_files = {'dummy.yml' => @tmp_file}
|
36
36
|
File.open(@tmp_file, "w") {}
|
37
|
-
assert File.
|
37
|
+
assert File.exist?(@tmp_file)
|
38
38
|
@translations.clean_up
|
39
|
-
assert !File.
|
39
|
+
assert !File.exist?(@tmp_file), "Expected to delete file"
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_store_translations
|
43
|
-
assert !File.
|
43
|
+
assert !File.exist?(@output_file)
|
44
44
|
|
45
45
|
@translations.csv_files = {@output_file => @fixture_file}
|
46
46
|
@translations.store_translations
|
47
47
|
|
48
|
-
assert File.
|
48
|
+
assert File.exist?(@output_file)
|
49
49
|
end
|
50
50
|
|
51
51
|
def test_download_files
|
52
52
|
expected_file = File.join(tmp_dir, 'download.csv')
|
53
|
-
assert !File.
|
53
|
+
assert !File.exist?(expected_file)
|
54
54
|
@translations.download_files
|
55
|
-
assert File.
|
55
|
+
assert File.exist?(expected_file)
|
56
56
|
assert File.open(expected_file).read.encoding.name == 'UTF-8'
|
57
57
|
end
|
58
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-docs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Kunz
|
@@ -10,6 +10,7 @@ authors:
|
|
10
10
|
- Eduard Schäli
|
11
11
|
- Robin Wunderlin
|
12
12
|
- Esteban Pastorino
|
13
|
+
- Krzysztof Sakwerda
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
@@ -43,10 +44,24 @@ dependencies:
|
|
43
44
|
- - "~>"
|
44
45
|
- !ruby/object:Gem::Version
|
45
46
|
version: 0.13.3
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: test-unit
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.1.7
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.1.7
|
46
61
|
description: 'GEM providing helper scripts to manage i18n translations in Google Docs.
|
47
62
|
Features: check YAML files for missing translations; export YAML files to CSV; download
|
48
63
|
translations from multiple Google spreadsheets and store to YAML files'
|
49
|
-
email:
|
64
|
+
email: eduard.schaeli@localsearch.ch
|
50
65
|
executables: []
|
51
66
|
extensions: []
|
52
67
|
extra_rdoc_files: []
|
@@ -67,6 +82,7 @@ files:
|
|
67
82
|
- test/fixtures/config.yml
|
68
83
|
- test/fixtures/de/header.yml
|
69
84
|
- test/fixtures/en/header.yml
|
85
|
+
- test/fixtures/error.csv
|
70
86
|
- test/fixtures/minimal.csv
|
71
87
|
- test/fixtures/test.csv
|
72
88
|
- test/test_helper.rb
|
@@ -92,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
108
|
version: '0'
|
93
109
|
requirements: []
|
94
110
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.6.5
|
96
112
|
signing_key:
|
97
113
|
specification_version: 4
|
98
114
|
summary: Maintain translations in Google Docs and export them to your Rails project.
|