i18n-docs 0.0.9 → 0.0.10
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/.gitignore +5 -1
- data/Gemfile +7 -1
- data/README.md +13 -4
- data/Rakefile +22 -11
- data/i18n-docs.gemspec +2 -4
- data/lib/i18n-docs.rb +5 -11
- data/lib/{localch_i18n → i18n_docs}/csv_to_yaml.rb +8 -4
- data/lib/{localch_i18n → i18n_docs}/missing_keys_finder.rb +2 -2
- data/lib/{localch_i18n → i18n_docs}/translation_file_export.rb +22 -22
- data/lib/{localch_i18n → i18n_docs}/translations.rb +1 -1
- data/lib/i18n_docs/version.rb +3 -0
- data/lib/tasks/store_translations.rake +3 -3
- data/test/test_helper.rb +0 -1
- data/test/unit/csv_to_yaml_test.rb +2 -2
- data/test/unit/translation_file_export_test.rb +1 -1
- data/test/unit/translations_test.rb +1 -2
- metadata +6 -21
- data/lib/localch_i18n/version.rb +0 -3
- data/tasks/test.rake +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 652380c1ce699595e1e8f178caae06c4f8b5d838
|
4
|
+
data.tar.gz: f1bd46979506ce45acbfe438b8b8aaea5f78d75a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cead59ccf41276601dfe75f336e7211ea1d71bac1b460f3518633d4d04da8de91befe70294d16dc76cc015076b2e07766ba36eb104f4809402f2f3c6d781db8d
|
7
|
+
data.tar.gz: ea99aa588c362abf09714aa18e375d0c057e011317c86c05c6e9fc481c984935777b20717551cebf300080f5e0265651679b5e13b583a879d716a292420958df
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
#
|
3
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
4
|
+
# development dependencies will be added by default to the :development group.
|
4
5
|
gemspec
|
6
|
+
|
7
|
+
# Declare any dependencies that are still in development here instead of in
|
8
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
9
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
10
|
+
# your gem to rubygems.org.
|
data/README.md
CHANGED
@@ -62,6 +62,11 @@ Following Rake tasks are added by the GEM to your Rails project:
|
|
62
62
|

|
63
63
|
* From now on you should only update translations in Google Docs and run `rake i18n:import_translations` in the application to get changes. You can also export your
|
64
64
|
|
65
|
+
## Error Handling
|
66
|
+
|
67
|
+
I case of the error `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed` when running `rake i18n:import_translations`
|
68
|
+
Follow this: http://stackoverflow.com/questions/12562697/opensslsslsslerror-ssl-connect-returned-1-errno-0-state-sslv3-read-server-ce?answertab=active#tab-top
|
69
|
+
|
65
70
|
## Todo
|
66
71
|
|
67
72
|
*Pull requests welcome!*
|
@@ -73,7 +78,12 @@ Following Rake tasks are added by the GEM to your Rails project:
|
|
73
78
|
|
74
79
|
## CHANGELOG
|
75
80
|
|
76
|
-
|
81
|
+
### 0.0.10
|
82
|
+
|
83
|
+
* rename module to be inline with the gem-name
|
84
|
+
* various cleanups
|
85
|
+
|
86
|
+
### 0.0.9
|
77
87
|
|
78
88
|
* add version.rb
|
79
89
|
* content downloaded is forced to UTF-8
|
@@ -82,10 +92,9 @@ Following Rake tasks are added by the GEM to your Rails project:
|
|
82
92
|
* create tmp directory if it does not exist
|
83
93
|
* strip spaces from keys
|
84
94
|
|
85
|
-
|
95
|
+
### 0.0.7
|
86
96
|
|
87
|
-
*
|
88
|
-
* this version has been YANKED
|
97
|
+
* YANKED from rubygems.org, sorry
|
89
98
|
|
90
99
|
### 0.0.7
|
91
100
|
|
data/Rakefile
CHANGED
@@ -1,17 +1,28 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
1
|
begin
|
4
|
-
|
5
|
-
rescue
|
6
|
-
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
9
5
|
end
|
10
6
|
|
11
|
-
require 'bundler/gem_tasks'
|
12
7
|
require 'i18n-docs'
|
8
|
+
require 'rdoc/task'
|
9
|
+
require 'rake/testtask'
|
13
10
|
|
14
|
-
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'i18n-docs'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.md')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
Bundler::GemHelper.install_tasks
|
15
20
|
|
16
|
-
#
|
17
|
-
|
21
|
+
# Test::Unit Tests
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/*_test.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
task :default => [:test]
|
data/i18n-docs.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
$:.push File.expand_path("../lib", __FILE__)
|
2
2
|
# Maintain your gem's version:
|
3
|
-
require '
|
3
|
+
require 'i18n_docs/version'
|
4
4
|
|
5
5
|
# encoding: utf-8
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = 'i18n-docs'
|
8
|
-
s.version =
|
8
|
+
s.version = I18nDocs::VERSION
|
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"
|
@@ -18,6 +18,4 @@ 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('awesome_print')
|
22
|
-
|
23
21
|
end
|
data/lib/i18n-docs.rb
CHANGED
@@ -1,19 +1,13 @@
|
|
1
|
-
# require 'rake'
|
2
|
-
|
3
|
-
# load rake tasks in case GEM is included within rails project
|
4
|
-
|
5
1
|
require 'csv'
|
6
2
|
require 'yaml'
|
7
3
|
require 'open-uri'
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
require '
|
11
|
-
require '
|
12
|
-
|
13
|
-
|
4
|
+
require 'i18n_docs/missing_keys_finder'
|
5
|
+
require 'i18n_docs/csv_to_yaml'
|
6
|
+
require 'i18n_docs/translations'
|
7
|
+
require 'i18n_docs/translation_file_export'
|
14
8
|
|
15
9
|
if defined?(Rails)
|
16
|
-
class
|
10
|
+
class I18nDocs::Railtie < Rails::Railtie
|
17
11
|
rake_tasks do
|
18
12
|
Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
|
19
13
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module I18nDocs
|
2
2
|
|
3
3
|
class CsvToYaml
|
4
4
|
|
@@ -61,10 +61,14 @@ module LocalchI18n
|
|
61
61
|
tree = keys[0...-1]
|
62
62
|
leaf = keys.last
|
63
63
|
data_hash = tree.inject(@translations[locale]) do |memo, k|
|
64
|
-
if memo.
|
65
|
-
memo
|
64
|
+
if memo.is_a? Hash
|
65
|
+
if memo.has_key?(k)
|
66
|
+
memo[k]
|
67
|
+
else
|
68
|
+
memo[k] = {}
|
69
|
+
end
|
66
70
|
else
|
67
|
-
|
71
|
+
raise "Error around key '#{keys.join '.'}': Expected #{memo.inspect} to be a Hash"
|
68
72
|
end
|
69
73
|
end
|
70
74
|
data_hash[leaf] = value
|
@@ -1,33 +1,33 @@
|
|
1
|
-
module
|
1
|
+
module I18nDocs
|
2
2
|
class TranslationFileExport
|
3
|
-
|
3
|
+
|
4
4
|
attr_accessor :translations
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(source_dir, source_file, output_dir, locales)
|
7
7
|
@source_dir = source_dir
|
8
8
|
@source_file = source_file
|
9
|
-
|
9
|
+
|
10
10
|
@output_file = File.join(output_dir, source_file.gsub('.yml', '.csv'))
|
11
11
|
@locales = locales.map {|l| l.to_s }
|
12
|
-
|
12
|
+
|
13
13
|
@translations = {}
|
14
14
|
end
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
|
17
17
|
def export
|
18
18
|
load_translations
|
19
19
|
write_to_csv
|
20
20
|
end
|
21
|
-
|
22
|
-
|
21
|
+
|
22
|
+
|
23
23
|
def write_to_csv
|
24
24
|
main_locale = @locales.include?('en') ? 'en' : @locales.first
|
25
|
-
|
25
|
+
|
26
26
|
puts " #{@source_file}: write CSV to '#{@output_file}' \n\n"
|
27
|
-
|
27
|
+
|
28
28
|
CSV.open(@output_file, "wb") do |csv|
|
29
29
|
csv << (["key"] + @locales)
|
30
|
-
|
30
|
+
|
31
31
|
@translations[main_locale].keys.each do |key|
|
32
32
|
values = @locales.map do |locale|
|
33
33
|
@translations[locale][key]
|
@@ -35,30 +35,30 @@ module LocalchI18n
|
|
35
35
|
csv << values.unshift(key)
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
end
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
def load_translations
|
43
43
|
@locales.each do |locale|
|
44
44
|
translation_hash = load_language(locale)
|
45
45
|
@translations[locale] = flatten_translations_hash(translation_hash)
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def load_language(locale)
|
50
|
-
|
50
|
+
|
51
51
|
puts " #{@source_file}: load translations for '#{locale}'"
|
52
|
-
|
52
|
+
|
53
53
|
input_file = File.join(@source_dir, locale, @source_file)
|
54
54
|
translations = {}
|
55
55
|
translations = YAML.load_file(input_file) if File.exists?(input_file)
|
56
56
|
translations[locale]
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
def flatten_translations_hash(translations, parent_key = [])
|
60
60
|
flat_hash = {}
|
61
|
-
|
61
|
+
|
62
62
|
translations.each do |key, t|
|
63
63
|
current_key = parent_key.dup << key
|
64
64
|
if t.is_a?(Hash)
|
@@ -71,7 +71,7 @@ module LocalchI18n
|
|
71
71
|
end
|
72
72
|
flat_hash
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
end
|
@@ -3,7 +3,7 @@ namespace :i18n do
|
|
3
3
|
|
4
4
|
desc "Find and list translation keys that do not exist in all locales"
|
5
5
|
task :missing_keys => :environment do
|
6
|
-
finder =
|
6
|
+
finder = I18nDocs::MissingKeysFinder.new(I18n.backend)
|
7
7
|
finder.find_missing_keys
|
8
8
|
end
|
9
9
|
|
@@ -17,7 +17,7 @@ namespace :i18n do
|
|
17
17
|
tmp_dir = Rails.root.join('tmp')
|
18
18
|
Dir.mkdir(tmp_dir) unless Dir.exist?(tmp_dir)
|
19
19
|
|
20
|
-
translations =
|
20
|
+
translations = I18nDocs::Translations.new(config_file, tmp_dir)
|
21
21
|
translations.download_files
|
22
22
|
translations.store_translations
|
23
23
|
translations.clean_up
|
@@ -44,7 +44,7 @@ namespace :i18n do
|
|
44
44
|
|
45
45
|
input_files.each do |file|
|
46
46
|
file = File.basename(file)
|
47
|
-
exporter =
|
47
|
+
exporter = I18nDocs::TranslationFileExport.new(source_dir, file, output_dir, locales)
|
48
48
|
exporter.export
|
49
49
|
end
|
50
50
|
|
data/test/test_helper.rb
CHANGED
@@ -16,7 +16,7 @@ module UnitTests
|
|
16
16
|
|
17
17
|
Rails.stubs(:root).returns(stub(:join => @output_file))
|
18
18
|
|
19
|
-
@csv_to_yaml =
|
19
|
+
@csv_to_yaml = I18nDocs::CsvToYaml.new(@input_file, @output_file, @locales)
|
20
20
|
end
|
21
21
|
|
22
22
|
def teardown
|
@@ -139,7 +139,7 @@ module UnitTests
|
|
139
139
|
@csv_to_yaml.write_files
|
140
140
|
assert File.exists?(@output_file)
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
def test_key_has_spaces
|
144
144
|
row = {'key' => 'has. space', 'en' => 'yes', 'de' => 'ja'}
|
145
145
|
@csv_to_yaml.process_row(row)
|
@@ -14,7 +14,7 @@ module UnitTests
|
|
14
14
|
output_dir = tmp_dir
|
15
15
|
locales = ['en', 'de']
|
16
16
|
|
17
|
-
@exporter =
|
17
|
+
@exporter = I18nDocs::TranslationFileExport.new(source_dir, source_file, output_dir, locales)
|
18
18
|
@output_file = File.join(output_dir, 'header.csv')
|
19
19
|
end
|
20
20
|
|
@@ -10,7 +10,7 @@ module UnitTests
|
|
10
10
|
create_tmp_dir
|
11
11
|
|
12
12
|
config_file = File.join(fixture_path, 'config.yml')
|
13
|
-
@translations =
|
13
|
+
@translations = I18nDocs::Translations.new(config_file, tmp_dir)
|
14
14
|
@translations.tmp_folder = tmp_dir
|
15
15
|
@translations.locales = ['de', 'en']
|
16
16
|
|
@@ -55,6 +55,5 @@ module UnitTests
|
|
55
55
|
assert File.exists?(expected_file)
|
56
56
|
assert File.open(expected_file).read.encoding.name == 'UTF-8'
|
57
57
|
end
|
58
|
-
|
59
58
|
end
|
60
59
|
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.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Kunz
|
@@ -43,20 +43,6 @@ dependencies:
|
|
43
43
|
- - "~>"
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.13.3
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: awesome_print
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
requirements:
|
50
|
-
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '0'
|
53
|
-
type: :development
|
54
|
-
prerelease: false
|
55
|
-
version_requirements: !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '0'
|
60
46
|
description: 'GEM providing helper scripts to manage i18n translations in Google Docs.
|
61
47
|
Features: check YAML files for missing translations; export YAML files to CSV; download
|
62
48
|
translations from multiple Google spreadsheets and store to YAML files'
|
@@ -72,13 +58,12 @@ files:
|
|
72
58
|
- Rakefile
|
73
59
|
- i18n-docs.gemspec
|
74
60
|
- lib/i18n-docs.rb
|
75
|
-
- lib/
|
76
|
-
- lib/
|
77
|
-
- lib/
|
78
|
-
- lib/
|
79
|
-
- lib/
|
61
|
+
- lib/i18n_docs/csv_to_yaml.rb
|
62
|
+
- lib/i18n_docs/missing_keys_finder.rb
|
63
|
+
- lib/i18n_docs/translation_file_export.rb
|
64
|
+
- lib/i18n_docs/translations.rb
|
65
|
+
- lib/i18n_docs/version.rb
|
80
66
|
- lib/tasks/store_translations.rake
|
81
|
-
- tasks/test.rake
|
82
67
|
- test/fixtures/config.yml
|
83
68
|
- test/fixtures/de/header.yml
|
84
69
|
- test/fixtures/en/header.yml
|
data/lib/localch_i18n/version.rb
DELETED