translation 1.2 → 1.3

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: f401074ed1430b32c5c99538ce08de94f54288f0
4
- data.tar.gz: 95b51e1d7e1baf634bd38338d14f538e798dab88
3
+ metadata.gz: 438a297a6cc07e0af97053bf03b98e5c5c0613dd
4
+ data.tar.gz: 433b5ab03bdd59005cf81dfc4c042e0aefb7ab0d
5
5
  SHA512:
6
- metadata.gz: 34e7fef03073d4a3e7725ee4a762920fb46aee17c86492c15f3c1f216d549ae42dcc8346c05a9ce61dc851bb38585e0708054b61c02e213879eeb0e92ade819d
7
- data.tar.gz: 2957860ddb4b052a3f6d4c3fe92d536c3f39ed74c8134908903ec414db76eb89bccde8359e9c6916beddf1a16e94a6459d7fdad80371988b6bfeaf19f0f10161
6
+ metadata.gz: 0fac9fb66470320c386ea22792953ccf164f1a05d2d759b2ec994fae468e6c6d9b96b12109ec0f379f2c2ec48ae391215d5d92c69569270b85fc63d62ca5718e
7
+ data.tar.gz: 2f88d12ab1f5cb1c724086b0cfc40bfe7c3bff4cca05d4078c90d5fef8e1c2ceb913d513eb677d7f317290bd7bdfe79a7a861370979af3ab08c37f6cd130ee56
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Ruby/Rails gem for [Translation.io](http://translation.io).
2
2
 
3
+ ![Build Status](https://www.codeship.io/projects/f7cd4ac0-b73c-0131-51ea-522dcd2196ed/status)
4
+
3
5
  ## Description
4
6
 
5
7
  Add this gem to your [Rails](http://rubyonrails.org) app to translate it with [Translation.io](http://translation.io).
@@ -23,7 +23,7 @@ module TranslationIO
23
23
  # WARNING. THIS FILE WAS AUTO-GENERATED BY THE TRANSLATION GEM.
24
24
  # IF YOU UPDATE IT, YOUR CHANGES WILL BE LOST AT THE NEXT SYNC.
25
25
  #
26
- # To update this file, use this translation interface :
26
+ # To update this file, use this translation interface:
27
27
  # #{@parsed_response['project_url']}/#{target_locale}
28
28
  #
29
29
  EOS
@@ -36,6 +36,7 @@ module TranslationIO
36
36
  yaml_data = YAMLConversion.get_yaml_data_from_flat_translations(target_flat_special_translations)
37
37
 
38
38
  File.open(yaml_path, 'wb') do |file|
39
+ file.write(self.class.top_comment)
39
40
  file.write(yaml_data)
40
41
  end
41
42
  end
@@ -57,6 +58,7 @@ module TranslationIO
57
58
  yaml_path = File.join(@yaml_locales_path, "localization.#{target_locale}.yml")
58
59
 
59
60
  File.open(yaml_path, 'wb') do |file|
61
+ file.write(self.class.top_comment)
60
62
  file.write(parsed_response["yaml_data_#{target_locale}"])
61
63
  end
62
64
  end
@@ -64,6 +66,19 @@ module TranslationIO
64
66
  end
65
67
  end
66
68
 
69
+ def self.top_comment
70
+ <<EOS
71
+ # THIS FILE CONTAINS LOCALIZATION KEYS : date and number formats, number precisions,
72
+ # number separators and all other non-text values depending on the language.
73
+ # These values must not reach the translator, so they are separated in this file.
74
+ #
75
+ # More info here: https://translation.io/blog/gettext-is-better-than-rails-i18n#localization
76
+ #
77
+ # You can edit and/or add new keys here, they won't be touched by Translation.io.
78
+ #
79
+ EOS
80
+ end
81
+
67
82
  end
68
83
  end
69
84
  end
@@ -24,7 +24,24 @@ module TranslationIO
24
24
 
25
25
  UpdatePotFileStep.new(pot_path, source_files).run(params)
26
26
  UpdateAndCollectPoFilesStep.new(target_locales, pot_path, locales_path).run(params)
27
- CreateYamlPoFilesStep.new(source_locale, target_locales, yaml_file_paths).run(params)
27
+
28
+ create_yaml_pot_files_step = CreateYamlPoFilesStep.new(source_locale, target_locales, yaml_file_paths)
29
+ create_yaml_pot_files_step.run(params)
30
+
31
+ all_used_yaml_locales = (create_yaml_pot_files_step.all_used_yaml_locales.to_a.map(&:to_s) - [config.source_locale.to_s]).sort.map(&:to_s)
32
+ yaml_locales_difference = (all_used_yaml_locales) - target_locales.sort.map(&:to_s)
33
+
34
+ if yaml_locales_difference.any?
35
+ TranslationIO.info("[error] Your `config.target_locales` are [#{target_locales.join(', ')}] and we have found some YAML keys for [#{all_used_yaml_locales.join(', ')}] and they does not match.")
36
+ TranslationIO.info("[error] Do you really want to continue? (y/N)")
37
+
38
+ print "> "
39
+ input = STDIN.gets.strip
40
+
41
+ if input != 'y' && input != 'Y'
42
+ exit(0)
43
+ end
44
+ end
28
45
 
29
46
  TranslationIO.info "Sending data to server"
30
47
  uri = URI("#{client.endpoint}/projects/#{client.api_key}/init")
@@ -2,10 +2,13 @@ module TranslationIO
2
2
  class Client
3
3
  class InitOperation < BaseOperation
4
4
  class CreateYamlPoFilesStep
5
+ attr_accessor :all_used_yaml_locales
6
+
5
7
  def initialize(source_locale, target_locales, yaml_file_paths)
6
- @source_locale = source_locale
7
- @target_locales = target_locales
8
- @yaml_file_paths = yaml_file_paths
8
+ @source_locale = source_locale
9
+ @target_locales = target_locales
10
+ @yaml_file_paths = yaml_file_paths
11
+ @all_used_yaml_locales = Set.new
9
12
  end
10
13
 
11
14
  def run(params)
@@ -25,6 +28,7 @@ module TranslationIO
25
28
  all_flat_translations = FlatHash.to_flat_hash(all_translations)
26
29
 
27
30
  all_flat_string_translations = all_flat_translations.select do |key, value|
31
+ all_used_yaml_locales << key.split('.').first
28
32
  YamlEntry.string?(key, value) && !YamlEntry.localization?(key, value)
29
33
  end
30
34
 
@@ -9,6 +9,7 @@ module TranslationIO
9
9
 
10
10
  def run(params)
11
11
  TranslationIO.info "Updating POT file."
12
+
12
13
  GetText::Tools::XGetText.run(*@source_files, '-o', @pot_path,
13
14
  '--msgid-bugs-address', TranslationIO.config.pot_msgid_bugs_address,
14
15
  '--package-name', TranslationIO.config.pot_package_name,
@@ -6,6 +6,7 @@ module TranslationIO
6
6
  attr_accessor :verbose
7
7
  attr_accessor :test
8
8
  attr_accessor :ignored_key_prefixes
9
+ attr_accessor :ignored_source_files
9
10
  attr_accessor :localization_key_prefixes
10
11
  attr_accessor :charset
11
12
  attr_accessor :metadata_path
@@ -25,6 +26,7 @@ module TranslationIO
25
26
  self.verbose = 1
26
27
  self.test = false
27
28
  self.ignored_key_prefixes = []
29
+ self.ignored_source_files = [] # Files not parsed for GetText entries
28
30
  self.localization_key_prefixes = []
29
31
  self.charset = 'UTF-8'
30
32
  self.metadata_path = File.join('config', 'locales', '.translation_io')
@@ -47,9 +49,11 @@ module TranslationIO
47
49
  end
48
50
 
49
51
  def source_files
50
- Dir['**/*.{rb,erb,ruby,rabl}'].select do |p|
52
+ file_paths = Dir['**/*.{rb,erb,ruby,rabl}'].select do |p|
51
53
  !p.start_with?('vendor/') && !p.start_with?('tmp/')
52
54
  end
55
+
56
+ file_paths - ignored_source_files
53
57
  end
54
58
 
55
59
  def haml_source_files
@@ -4,6 +4,7 @@ require 'i18n/config'
4
4
  require 'gettext'
5
5
  require 'gettext/po'
6
6
  require 'gettext/po_parser'
7
+ require 'gettext/tools/xgettext'
7
8
 
8
9
  module TranslationIO
9
10
  class Railtie < Rails::Railtie
@@ -39,4 +40,23 @@ module GetText
39
40
  @report_warning = false
40
41
  end
41
42
  end
43
+
44
+ module Tools
45
+ class XGetText
46
+ def parse(paths)
47
+ po = PO.new
48
+ paths = [paths] if paths.kind_of?(String)
49
+ paths.each do |path|
50
+ begin
51
+ parse_path(path, po)
52
+ rescue SystemExit => e
53
+ # puts(_("Error parsing %{path}") % {:path => path})
54
+ puts
55
+ puts
56
+ end
57
+ end
58
+ po
59
+ end
60
+ end
61
+ end
42
62
  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: '1.2'
4
+ version: '1.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aurelien Malisart
@@ -9,28 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-29 00:00:00.000000000 Z
12
+ date: 2015-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gettext
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '3.1'
21
- - - ">="
18
+ - - '='
22
19
  - !ruby/object:Gem::Version
23
- version: 3.1.2
20
+ version: 3.1.7
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
- - - "~>"
29
- - !ruby/object:Gem::Version
30
- version: '3.1'
31
- - - ">="
25
+ - - '='
32
26
  - !ruby/object:Gem::Version
33
- version: 3.1.2
27
+ version: 3.1.7
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: rake
36
30
  requirement: !ruby/object:Gem::Requirement
@@ -49,20 +43,14 @@ dependencies:
49
43
  name: rspec
50
44
  requirement: !ruby/object:Gem::Requirement
51
45
  requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2.14'
55
- - - '='
46
+ - - ">="
56
47
  - !ruby/object:Gem::Version
57
48
  version: 2.14.1
58
49
  type: :development
59
50
  prerelease: false
60
51
  version_requirements: !ruby/object:Gem::Requirement
61
52
  requirements:
62
- - - "~>"
63
- - !ruby/object:Gem::Version
64
- version: '2.14'
65
- - - '='
53
+ - - ">="
66
54
  - !ruby/object:Gem::Version
67
55
  version: 2.14.1
68
56
  - !ruby/object:Gem::Dependency