translation 0.9.4 → 0.9.5

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: 177d0f379cbac2f9d701245ed60658f36b038443
4
- data.tar.gz: 6c58ffb3793de7ce6cc4c990815f73d2be59889f
3
+ metadata.gz: 61d74cef08246ebc2fb57c359957e82ea18c0024
4
+ data.tar.gz: 935f1c9c13da8244b0ece61700a3a07e76a79161
5
5
  SHA512:
6
- metadata.gz: 3d769627f2f86828f676678c83a030a3ae38576b2c0357f9cdc5e08b5cbe5a8101a915d128264646426374d645cb1283d3bcb2c197ca537a6e4e700ccdd18e68
7
- data.tar.gz: 9995cc00333af2cc1ba10e739efc1442b0a2314c5eaa96534f8fd0d1815d155d2280a0c67236c1fe4b1e2010fe3b92d91d6cc9e6bd79c813e4ce800234039c62
6
+ metadata.gz: 41b3cdfcee4610adce8f938c805ce18316e96871b57e4663297991d1fef4801d3d5e0b640030523d6b35d2c6fdf42299d38bc314cb6be95f6e0d398579b8c6cd
7
+ data.tar.gz: 67178106997e7b09f293beeaebd487f9e86b5e2babf73518bb8fb4383094d10d8bfa79a5e014ab1c8635893acbb80c2531cbd1fff43672c4d8fcc0bd7c5792c7
@@ -21,11 +21,11 @@ module TranslationIO
21
21
  end
22
22
 
23
23
  all_flat_special_translations = all_flat_translations.select do |key, value|
24
- YamlEntry.localization?(key, value)
24
+ TranslationIO::YamlEntry.localization?(key, value)
25
25
  end
26
26
 
27
27
  source_flat_special_translations = all_flat_special_translations.select do |key|
28
- YamlEntry.from_locale?(key, @source_locale) && !YamlEntry.ignored?(key)
28
+ TranslationIO::YamlEntry.from_locale?(key, @source_locale) && !TranslationIO::YamlEntry.ignored?(key)
29
29
  end
30
30
 
31
31
  @target_locales.each do |target_locale|
@@ -10,19 +10,26 @@ module TranslationIO
10
10
 
11
11
  def run(params)
12
12
  TranslationIO.info "Importing translations from YAML files."
13
- all_flat_translations = {}
13
+
14
+ all_translations = {}
14
15
 
15
16
  @yaml_file_paths.each do |file_path|
16
17
  TranslationIO.info file_path, 2, 2
17
- all_flat_translations.merge!(YAMLConversion.get_flat_translations_for_yaml_file(file_path))
18
+ file_translations = YAML::load(File.read(file_path))
19
+
20
+ unless file_translations.blank?
21
+ all_translations = all_translations.deep_merge(file_translations)
22
+ end
18
23
  end
19
24
 
25
+ all_flat_translations = FlatHash.to_flat_hash(all_translations)
26
+
20
27
  all_flat_string_translations = all_flat_translations.select do |key, value|
21
- YamlEntry.string?(key, value) && !YamlEntry.localization?(key, value)
28
+ TranslationIO::YamlEntry.string?(key, value) && !TranslationIO::YamlEntry.localization?(key, value)
22
29
  end
23
30
 
24
31
  source_flat_string_tanslations = all_flat_string_translations.select do |key|
25
- YamlEntry.from_locale?(key, @source_locale) && !YamlEntry.ignored?(key)
32
+ TranslationIO::YamlEntry.from_locale?(key, @source_locale) && !TranslationIO::YamlEntry.ignored?(key)
26
33
  end
27
34
 
28
35
  @target_locales.each do |target_locale|
@@ -9,17 +9,22 @@ module TranslationIO
9
9
 
10
10
  def run(params)
11
11
  TranslationIO.info "Generating POT file from YAML files."
12
- all_flat_translations = {}
12
+
13
+ all_translations = {}
13
14
 
14
15
  @yaml_file_paths.each do |file_path|
15
16
  TranslationIO.info file_path, 2, 2
16
- all_flat_translations.merge!(
17
- YAMLConversion.get_flat_translations_for_yaml_file(file_path)
18
- )
17
+ file_translations = YAML::load(File.read(file_path))
18
+
19
+ unless file_translations.blank?
20
+ all_translations = all_translations.deep_merge(file_translations)
21
+ end
19
22
  end
20
23
 
24
+ all_flat_translations = FlatHash.to_flat_hash(all_translations)
25
+
21
26
  source_flat_string_tanslations = all_flat_translations.select do |key, value|
22
- YamlEntry.string?(key, value) && YamlEntry.from_locale?(key, @source_locale) && !YamlEntry.ignored?(key) && !YamlEntry.localization?(key, value)
27
+ TranslationIO::YamlEntry.string?(key, value) && TranslationIO::YamlEntry.from_locale?(key, @source_locale) && !TranslationIO::YamlEntry.ignored?(key) && !TranslationIO::YamlEntry.localization?(key, value)
23
28
  end
24
29
 
25
30
  pot_representation = GetText::PO.new
@@ -5,14 +5,16 @@ module TranslationIO
5
5
  attr_accessor :endpoint
6
6
  attr_accessor :verbose
7
7
  attr_accessor :test
8
+ attr_accessor :ignored_key_prefixes
8
9
 
9
10
  def initialize
10
- self.locales_path = File.join('config', 'locales', 'gettext')
11
- self.source_locale = :en
12
- self.target_locales = []
13
- self.endpoint = 'https://translation.io/api'
14
- self.verbose = 1
15
- self.test = false
11
+ self.locales_path = File.join('config', 'locales', 'gettext')
12
+ self.source_locale = :en
13
+ self.target_locales = []
14
+ self.endpoint = 'https://translation.io/api'
15
+ self.verbose = 1
16
+ self.test = false
17
+ self.ignored_key_prefixes = []
16
18
  end
17
19
 
18
20
  def pot_path
@@ -77,7 +77,7 @@ module TranslationIO
77
77
  current_object[current_key] = {}
78
78
  end
79
79
  current_object = current_object[current_key]
80
- current_object[new_key] = value
80
+ current_object[new_key] = value if current_object.respond_to? :each
81
81
 
82
82
  key_string = ''
83
83
  end
@@ -1,51 +1,53 @@
1
- module YamlEntry
2
-
3
- IGNORED_KEY_PREFIXES = [
4
- 'faker.'
5
- ]
6
-
7
- LOCALIZATION_KEY_PREFIXES = [
8
- 'date.formats',
9
- 'date.order',
10
- 'time.formats',
11
- 'support.array',
12
- 'number.format',
13
- 'number.currency',
14
- 'number.percentage',
15
- 'number.precision',
16
- 'number.human.format',
17
- 'number.human.storage_units.format',
18
- 'number.human.decimal_units.format',
19
- 'number.human.decimal_units.units.unit'
20
- ]
21
-
22
- class << self
23
- def string?(key, value)
24
- key.present? && value.is_a?(String)
25
- end
1
+ module TranslationIO
2
+ module TranslationIO::YamlEntry
3
+
4
+ LOCALIZATION_KEY_PREFIXES = [
5
+ 'date.formats',
6
+ 'date.order',
7
+ 'time.formats',
8
+ 'support.array',
9
+ 'number.format',
10
+ 'number.currency',
11
+ 'number.percentage',
12
+ 'number.precision',
13
+ 'number.human.format',
14
+ 'number.human.storage_units.format',
15
+ 'number.human.decimal_units.format',
16
+ 'number.human.decimal_units.units.unit'
17
+ ]
18
+
19
+ class << self
20
+ def string?(key, value)
21
+ key.present? && value.is_a?(String)
22
+ end
26
23
 
27
- def from_locale?(key, locale)
28
- key.present? && key.start_with?("#{locale}.")
29
- end
24
+ def from_locale?(key, locale)
25
+ key.present? && key.start_with?("#{locale}.")
26
+ end
30
27
 
31
- def ignored?(key)
32
- key.present? && IGNORED_KEY_PREFIXES.any? { |p| key_without_locale(key).start_with?(p) }
33
- end
28
+ def ignored?(key)
29
+ key.present? && ignored_key_prefixes.any? { |p| key_without_locale(key).start_with?(p) }
30
+ end
34
31
 
35
- def localization?(key, value)
36
- key.present? && (localization_prefix?(key) || (!YamlEntry.string?(key, value) && !value.nil?))
37
- end
32
+ def localization?(key, value)
33
+ key.present? && (localization_prefix?(key) || (!TranslationIO::YamlEntry.string?(key, value) && !value.nil?))
34
+ end
38
35
 
39
- def localization_prefix?(key)
40
- LOCALIZATION_KEY_PREFIXES.any? do |prefix|
41
- key_without_locale(key).start_with?(prefix)
36
+ def localization_prefix?(key)
37
+ LOCALIZATION_KEY_PREFIXES.any? do |prefix|
38
+ key_without_locale(key).start_with?(prefix)
39
+ end
42
40
  end
43
- end
44
41
 
45
- private
42
+ private
46
43
 
47
- def key_without_locale(key)
48
- key.split('.', 2).last
44
+ def ignored_key_prefixes
45
+ ['faker.'] + TranslationIO.config.ignored_key_prefixes
46
+ end
47
+
48
+ def key_without_locale(key)
49
+ key.split('.', 2).last
50
+ end
49
51
  end
50
52
  end
51
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aurelien Malisart
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-26 00:00:00.000000000 Z
12
+ date: 2014-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gettext
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.2.0
122
+ rubygems_version: 2.2.2
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: Rails translation made _("simple") with YAML and GetText.