i18n-migrations 0.2.5 → 1.0.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
  SHA256:
3
- metadata.gz: 63075e442e0c11d1bea96ec41770177852a52e737881781ca483e8a4114cdeba
4
- data.tar.gz: 8628199cb76d9d0312db4e69971df5ba4e0e74ce98e748a959be3873c664c814
3
+ metadata.gz: f50a6b0b64079bf6a368d78ee8bca1aad59934c08c7a197bae01781dd5e9907e
4
+ data.tar.gz: 878543ee25ad4aec558ae25cb3ec31d76ad78419024f4620f06912bcdf37d0b8
5
5
  SHA512:
6
- metadata.gz: 6a51c120ff520f528f338cd18ed0112ef1f7e75c33e851e385f12b2351a87d02b48ee132f0bfb8c8409276b5182a9e4fc2ea53507d89d0e7fa7c6db20ad4b5bc
7
- data.tar.gz: 18f4049a026d33bbf5947e9e18bb60861d042a0ccd8a0fe1786ecaa28ef268adf092951fdd1d97edfd6febb2c2c187cb096c999262a4b8b7e89f17efa5824831
6
+ metadata.gz: 1ac50b979c48e11b06286f95892a1fd827f6baad49359c53da3e39b4905d527fe8c0941361df48c7ebded46f40594852c8f29e5b6ad18d2e23301d18be23632a
7
+ data.tar.gz: 8311e93c074438ae29cace119a3f8bf2953b2d77f00510fafbe640c9c2301de76c082030e524fb4ece0e1ad12f4a76a4c0153bf5674aea24bd64b3eb87fd9df1
@@ -0,0 +1,27 @@
1
+ # this is where your migration files will live. it will be relative to your config file
2
+ migration_dir: i18n/migrate
3
+
4
+ # this is where your locale files will live (en.yml, es.yml, etc). it will be relative to your config file
5
+ locales_dir: config/locales
6
+
7
+ # this is the locale you will be translating from
8
+ main_locale: en
9
+
10
+ # put all other locales you want to use here, if they don't already exist, add them with i18n-migrations new_locale es
11
+ # each locale needs:
12
+ other_locales:
13
+ es:
14
+ name: Spanish
15
+ # a spreadsheet that translators will use to do their work, these are the links to them
16
+ google_spreadsheet: https://docs.google.com/spreadsheets/d/GOOGLE_SPREADSHEET_ID/edit
17
+ # put things like your product name here along with any possible mistranslations
18
+ do_not_translate:
19
+ "Transparent Classroom":
20
+ - Aula Transparente
21
+ - clase transparente
22
+
23
+ # you need a service account key in order to access google spreadsheets. This is the path to it, relative to your config file
24
+ google_service_account_key_path: i18n/google_drive_key.json
25
+
26
+ # this is your api key to use google translate
27
+ google_translate_api_key: [INSERT_GOOGLE_TRANSLATE_API_KEY]
@@ -0,0 +1,6 @@
1
+ ---
2
+ es:
3
+ colors:
4
+ blue: "[autotranslated]"
5
+ green: "[autotranslated]"
6
+ red: "[autotranslated]"
@@ -0,0 +1,7 @@
1
+ ---
2
+ en:
3
+ VERSION: 201901311613_add_colors
4
+ colors:
5
+ blue: blue
6
+ green: green
7
+ red: red
@@ -0,0 +1,7 @@
1
+ ---
2
+ es:
3
+ VERSION: 201901311613_add_colors
4
+ colors:
5
+ blue: azul
6
+ green: verde
7
+ red: rojo
@@ -0,0 +1,9 @@
1
+ require 'i18n-migrations'
2
+
3
+ class AddColors201901311613 < I18n::Migrations::Migration
4
+ def change
5
+ add'colors.red', 'red'
6
+ add'colors.blue', 'blue'
7
+ add'colors.green', 'green'
8
+ end
9
+ end
@@ -5,6 +5,10 @@ module I18n
5
5
  class Config
6
6
  CONFIG_FILE_NAME = '.i18n-migrations.yml'
7
7
 
8
+ def initialize(config_file_name = CONFIG_FILE_NAME)
9
+ @config_file_name = config_file_name
10
+ end
11
+
8
12
  def migration_dir
9
13
  get_file(:migration_dir)
10
14
  end
@@ -18,29 +22,31 @@ module I18n
18
22
  end
19
23
 
20
24
  def other_locales
21
- get_value(:other_locales)
25
+ get_value(:other_locales).keys
22
26
  end
23
27
 
24
28
  def google_service_account_key_path
25
29
  get_file(:google_service_account_key_path)
26
30
  end
27
31
 
28
- def google_spreadsheets
29
- get_value(:google_spreadsheets)
32
+ def google_spreadsheet(locale)
33
+ get_value([:other_locales, locale, :google_spreadsheet])
30
34
  end
31
35
 
32
- def google_translate_api_key
33
- get_value(:google_translate_api_key)
36
+ def do_not_translate(locale)
37
+ return {} if locale.to_s == main_locale
38
+
39
+ get_value([:other_locales, locale])['do_not_translate'] || {}
34
40
  end
35
41
 
36
- def do_not_translate
37
- get_value(:do_not_translate)
42
+ def google_translate_api_key
43
+ get_value(:google_translate_api_key)
38
44
  end
39
45
 
40
46
  def read!
41
- yaml_file = find_config_file(CONFIG_FILE_NAME)
47
+ yaml_file = find_config_file(@config_file_name)
42
48
  unless yaml_file
43
- STDERR.puts "Can't find a #{CONFIG_FILE_NAME} file. Try running 'i18n-migrations setup'"
49
+ STDERR.puts "Can't find a #{@config_file_name} file. Try running 'i18n-migrations setup'"
44
50
  exit(1)
45
51
  end
46
52
 
@@ -67,19 +73,27 @@ module I18n
67
73
  private
68
74
 
69
75
  def get_value(key)
70
- if @config.has_key?(key.to_s)
76
+ if key.is_a?(Array)
77
+ value = @config
78
+ key.each do |key_part|
79
+ if value&.has_key?(key_part.to_s)
80
+ value = value[key_part.to_s]
81
+ else
82
+ raise ArgumentError, "You must have defined #{key.join('/')} in #{@root_dir}/#{@config_file_name}"
83
+ end
84
+ end
85
+ value
86
+ elsif @config.has_key?(key.to_s)
71
87
  @config[key.to_s]
72
88
  else
73
- STDERR.puts "You must have defined #{key} in #{@root_dir}/#{CONFIG_FILE_NAME}"
74
- exit(1)
89
+ raise ArgumentError, "You must have defined #{key} in #{@root_dir}/#{@config_file_name}"
75
90
  end
76
91
  end
77
92
 
78
93
  def get_file(key)
79
94
  file = File.join(@root_dir, get_value(key))
80
95
  unless File.exist?(file)
81
- STDERR.puts "#{File.expand_path(file)} does not exist"
82
- exit(1)
96
+ raise ArgumentError, "#{File.expand_path(file)} does not exist, please create it."
83
97
  end
84
98
  file
85
99
  end
@@ -115,9 +115,11 @@ end
115
115
  private
116
116
 
117
117
  def each_locale(name = 'all')
118
- (name == 'all' ? all_locale_names : [name]).each do |l|
119
- yield locale_for(l)
118
+ threads = (name == 'all' ? all_locale_names : [name]).map do |l|
119
+ locale = locale_for(l)
120
+ Thread.new {yield locale}
120
121
  end
122
+ threads.each(&:join)
121
123
  end
122
124
 
123
125
  def all_locale_names
@@ -126,7 +128,7 @@ end
126
128
 
127
129
  def get_google_spreadsheet(locale)
128
130
  GoogleSpreadsheet.new(locale,
129
- config.google_spreadsheets[locale],
131
+ config.google_spreadsheet(locale),
130
132
  config.google_service_account_key_path).sheet
131
133
  end
132
134
 
@@ -134,7 +136,7 @@ end
134
136
  GoogleTranslateDictionary.new(from_locale: config.main_locale,
135
137
  to_locale: locale,
136
138
  key: config.google_translate_api_key,
137
- do_not_translate: config.do_not_translate)
139
+ do_not_translate: config.main_locale == locale ? {} : config.do_not_translate(locale))
138
140
  end
139
141
  end
140
142
  end
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module Migrations
3
- VERSION = "0.2.5"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Lightsmith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-15 00:00:00.000000000 Z
11
+ date: 2019-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -117,6 +117,11 @@ files:
117
117
  - bin/console
118
118
  - bin/i18n-migrate
119
119
  - bin/setup
120
+ - example/.i18n-migrations.yml
121
+ - example/config/es_notes.yml
122
+ - example/config/locales/en.yml
123
+ - example/config/locales/es.yml
124
+ - example/i18n/migrate/201901311613_add_colors.rb
120
125
  - i18n-migrations.gemspec
121
126
  - lib/i18n-migrations.rb
122
127
  - lib/i18n/migrations/config.rb