translation 1.7 → 1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0e41e1529ebddeded105bf60eec7bfdc756be2e
4
- data.tar.gz: c4ea9728e442d17c5616acce199d6a006ebd017c
3
+ metadata.gz: d359ae6010036c8991106bd2c997ce9e134e274c
4
+ data.tar.gz: 9791346e543d7dbfa94b0274f13a106062530d1f
5
5
  SHA512:
6
- metadata.gz: bc84c365831883325b8b20ea4e92c8e4d06ed2a035fcb30e36515e4ca29d2342cb7e0287ec02222b932c86fda1d0137e52b08a479284cc314312c011771a0445
7
- data.tar.gz: 5cd68eb75c7c73023cd5592f99cb3ec87e1787134a10d0e14087ba43a9442e3784bb92f0c5f9aae18d0c0a1543f58ae04689fd1992170e1c877e3bda1430bedc
6
+ metadata.gz: 656c738ea8e941704f986971cc9a739d40973626f10d72015c75adb020201b564e7475f14b16f4fc8f54b180452c7f875c98d9976a9f22ca0baae31d5328c756
7
+ data.tar.gz: 6877fd10b443c673f885d53bb844ef0a40632bedc87924ec2c75be219455f0fe2aed9dcfdeedf4a38a7ac38670e0daff65e6a03d565501b785daef50b9a3315a
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
- # Ruby/Rails gem for [Translation.io](http://translation.io).
2
-
3
- ![Build Status](https://www.codeship.io/projects/f7cd4ac0-b73c-0131-51ea-522dcd2196ed/status)
1
+ # Gem for [Translation.io](http://translation.io). ![Build Status](https://www.codeship.io/projects/f7cd4ac0-b73c-0131-51ea-522dcd2196ed/status) [![Code Climate](https://codeclimate.com/github/aurels/translation-gem/badges/gpa.svg)](https://codeclimate.com/github/aurels/translation-gem) [![Test Coverage](https://codeclimate.com/github/aurels/translation-gem/badges/coverage.svg)](https://codeclimate.com/github/aurels/translation-gem/coverage)
4
2
 
5
3
  ## Description
6
4
 
data/lib/translation.rb CHANGED
@@ -1,11 +1,5 @@
1
1
  require 'net/http'
2
2
 
3
- require 'gettext'
4
- require 'gettext/po'
5
- require 'gettext/po_parser'
6
- require 'gettext/tools'
7
- require 'gettext/text_domain_manager'
8
-
9
3
  module TranslationIO
10
4
  GETTEXT_METHODS = [
11
5
  :nsgettext, :pgettext, :npgettext, :sgettext, :ngettext, :gettext,
@@ -27,7 +21,6 @@ require 'translation_io/yaml_entry'
27
21
 
28
22
  module TranslationIO
29
23
  module Proxy
30
- include GetText
31
24
  end
32
25
 
33
26
  class << self
@@ -37,21 +30,32 @@ module TranslationIO
37
30
  ENV['LANG'] = 'en_US.UTF-8' if ENV['LANG'].blank?
38
31
  ENV['LC_CTYPE'] = 'UTF-8' if ENV['LC_CTYPE'].blank?
39
32
 
40
- if Rails.env.development?
41
- GetText::TextDomainManager.cached = false
42
- end
43
-
44
33
  @config ||= Config.new
45
34
 
46
35
  yield @config
47
36
 
48
- Proxy.bindtextdomain(TEXT_DOMAIN, {
49
- :path => @config.locales_path,
50
- :output_charset => @config.charset
51
- })
37
+ unless @config.disable_gettext
38
+ require 'gettext'
39
+ require 'gettext/po'
40
+ require 'gettext/po_parser'
41
+ require 'gettext/tools'
42
+ require 'gettext/text_domain_manager'
43
+ require 'gettext/tools/xgettext'
44
+
45
+ if Rails.env.development?
46
+ GetText::TextDomainManager.cached = false
47
+ end
52
48
 
53
- Proxy.textdomain(TEXT_DOMAIN)
54
- Object.delegate *GETTEXT_METHODS, :to => Proxy
49
+ Proxy.include GetText
50
+
51
+ Proxy.bindtextdomain(TEXT_DOMAIN, {
52
+ :path => @config.locales_path,
53
+ :output_charset => @config.charset
54
+ })
55
+
56
+ Proxy.textdomain(TEXT_DOMAIN)
57
+ Object.delegate *GETTEXT_METHODS, :to => Proxy
58
+ end
55
59
 
56
60
  @client = Client.new(@config.api_key, @config.endpoint)
57
61
 
@@ -1,19 +1,20 @@
1
1
  module TranslationIO
2
2
  class Client
3
3
  class BaseOperation
4
- class DumpHamlGettextKeysStep
5
- def initialize(haml_source_files)
6
- @haml_source_files = haml_source_files
4
+ class DumpMarkupGettextKeysStep
5
+ def initialize(markup_source_files, markup_type)
6
+ @markup_source_files = markup_source_files
7
+ @markup_type = markup_type
7
8
  end
8
9
 
9
10
  def run
10
- if @haml_source_files.any?
11
- TranslationIO.info "Extracting Gettext entries from HAML files."
11
+ if @markup_source_files.any?
12
+ TranslationIO.info "Extracting Gettext entries from #{@markup_type.to_s.upcase} files."
12
13
 
13
14
  FileUtils.mkdir_p(File.join('tmp', 'translation'))
14
15
 
15
16
  extracted_gettext_entries.each_with_index do |entry, index|
16
- file_path = File.join('tmp', 'translation', "haml-gettext-#{index.to_s.rjust(8,'0')}.rb")
17
+ file_path = File.join('tmp', 'translation', "#{@markup_type}-gettext-#{index.to_s.rjust(8,'0')}.rb")
17
18
 
18
19
  File.open(file_path, 'w') do |file|
19
20
  file.puts "def fake"
@@ -29,11 +30,11 @@ module TranslationIO
29
30
  def extracted_gettext_entries
30
31
  entries = []
31
32
 
32
- @haml_source_files.each do |haml_file_path|
33
- TranslationIO.info haml_file_path, 2, 2
33
+ @markup_source_files.each do |markup_file_path|
34
+ TranslationIO.info markup_file_path, 2, 2
34
35
 
35
- haml_data = File.read(haml_file_path)
36
- entries += TranslationIO::Extractor.extract(haml_data)
36
+ markup_data = File.read(markup_file_path)
37
+ entries += TranslationIO::Extractor.extract(markup_data)
37
38
  end
38
39
 
39
40
  TranslationIO.info "#{entries.size} entries found", 2, 2
@@ -13,7 +13,7 @@ module TranslationIO
13
13
 
14
14
  @target_locales.each do |target_locale|
15
15
  if @parsed_response.has_key?("po_data_#{target_locale}")
16
- po_path = File.join(@locales_path, target_locale.to_s.gsub('-', '_'), "#{TEXT_DOMAIN}.po")
16
+ po_path = File.join(@locales_path, Locale::Tag.parse(target_locale).to_s, "#{TEXT_DOMAIN}.po")
17
17
  FileUtils.mkdir_p(File.dirname(po_path))
18
18
  TranslationIO.info po_path, 2, 2
19
19
 
@@ -3,8 +3,7 @@ require 'translation_io/client/base_operation/save_new_po_files_step'
3
3
  require 'translation_io/client/base_operation/create_new_mo_files_step'
4
4
  require 'translation_io/client/base_operation/save_new_yaml_files_step'
5
5
  require 'translation_io/client/base_operation/save_special_yaml_files_step'
6
- require 'translation_io/client/base_operation/dump_haml_gettext_keys_step'
7
- require 'translation_io/client/base_operation/dump_slim_gettext_keys_step'
6
+ require 'translation_io/client/base_operation/dump_markup_gettext_keys_step'
8
7
 
9
8
  module TranslationIO
10
9
  class Client
@@ -12,7 +12,7 @@ module TranslationIO
12
12
  TranslationIO.info "Updating PO files."
13
13
 
14
14
  @target_locales.each do |target_locale|
15
- po_path = "#{@locales_path}/#{target_locale.gsub('-', '_')}/#{TEXT_DOMAIN}.po"
15
+ po_path = "#{@locales_path}/#{Locale::Tag.parse(target_locale).to_s}/#{TEXT_DOMAIN}.po"
16
16
  TranslationIO.info po_path, 2, 2
17
17
 
18
18
  if File.exist?(po_path)
@@ -19,8 +19,8 @@ module TranslationIO
19
19
  yaml_file_paths = config.yaml_file_paths
20
20
 
21
21
  unless config.disable_gettext
22
- BaseOperation::DumpHamlGettextKeysStep.new(haml_source_files).run
23
- BaseOperation::DumpSlimGettextKeysStep.new(slim_source_files).run
22
+ BaseOperation::DumpMarkupGettextKeysStep.new(haml_source_files, :haml).run
23
+ BaseOperation::DumpMarkupGettextKeysStep.new(slim_source_files, :slim).run
24
24
  end
25
25
 
26
26
  UpdatePotFileStep.new(pot_path, source_files).run(params)
@@ -29,9 +29,30 @@ module TranslationIO
29
29
  create_yaml_pot_files_step = CreateYamlPoFilesStep.new(source_locale, target_locales, yaml_file_paths)
30
30
  create_yaml_pot_files_step.run(params)
31
31
 
32
- all_used_yaml_locales = create_yaml_pot_files_step.all_used_yaml_locales.to_a.map(&:to_s).sort
32
+ all_used_yaml_locales = create_yaml_pot_files_step.all_used_yaml_locales.to_a.map(&:to_s).sort
33
+
34
+ warn_source_locale_unfound(source_locale, all_used_yaml_locales)
35
+ warn_target_locale_unfound(target_locales, all_used_yaml_locales)
36
+
37
+ TranslationIO.info "Sending data to server"
38
+ uri = URI("#{client.endpoint}/projects/#{client.api_key}/init")
39
+ parsed_response = BaseOperation.perform_request(uri, params)
40
+
41
+ unless parsed_response.nil?
42
+ BaseOperation::SaveNewPoFilesStep.new(target_locales, locales_path, parsed_response).run
43
+ BaseOperation::SaveNewYamlFilesStep.new(target_locales, yaml_locales_path, parsed_response).run
44
+ BaseOperation::SaveSpecialYamlFilesStep.new(source_locale, target_locales, yaml_locales_path, yaml_file_paths).run
45
+ CleanupYamlFilesStep.new(source_locale, target_locales, yaml_file_paths, yaml_locales_path).run
46
+ BaseOperation::CreateNewMoFilesStep.new(locales_path).run
47
+
48
+ info_yaml_directory_structure
49
+ end
50
+
51
+ cleanup
52
+ end
53
+
54
+ def warn_source_locale_unfound(source_locale, all_used_yaml_locales)
33
55
  is_source_locale_unfound = !source_locale.in?(all_used_yaml_locales)
34
- unfound_target_locales = target_locales - all_used_yaml_locales
35
56
 
36
57
  if is_source_locale_unfound
37
58
  puts
@@ -48,12 +69,16 @@ module TranslationIO
48
69
  exit(0)
49
70
  end
50
71
  end
72
+ end
51
73
 
52
- if unfound_target_locales.any?
74
+ def warn_target_locale_unfound(target_locales, all_used_yaml_locales)
75
+ target_locales_unfound = target_locales - all_used_yaml_locales
76
+
77
+ if target_locales_unfound.any?
53
78
  puts
54
79
  puts "----------"
55
80
  puts "Your `config.target_locales` are [#{target_locales.sort.join(', ')}]."
56
- puts "But we haven't found any YAML key for [#{unfound_target_locales.join(', ')}], is this normal?"
81
+ puts "But we haven't found any YAML key for [#{target_locales_unfound.join(', ')}], is this normal?"
57
82
  puts "If not, check that you haven't misspelled the locale (ex. 'en-GB' instead of 'en')."
58
83
  puts "----------"
59
84
  puts "Do you want to continue? (y/N)"
@@ -65,26 +90,14 @@ module TranslationIO
65
90
  exit(0)
66
91
  end
67
92
  end
93
+ end
68
94
 
69
- TranslationIO.info "Sending data to server"
70
- uri = URI("#{client.endpoint}/projects/#{client.api_key}/init")
71
- parsed_response = BaseOperation.perform_request(uri, params)
72
-
73
- unless parsed_response.nil?
74
- BaseOperation::SaveNewPoFilesStep.new(target_locales, locales_path, parsed_response).run
75
- BaseOperation::SaveNewYamlFilesStep.new(target_locales, yaml_locales_path, parsed_response).run
76
- BaseOperation::SaveSpecialYamlFilesStep.new(source_locale, target_locales, yaml_locales_path, yaml_file_paths).run
77
- CleanupYamlFilesStep.new(source_locale, target_locales, yaml_file_paths, yaml_locales_path).run
78
- BaseOperation::CreateNewMoFilesStep.new(locales_path).run
79
-
80
- puts
81
- puts "----------"
82
- puts "If you're wondering why your YAML directory structure has changed so much,"
83
- puts "please check this article: https://translation.io/blog/dealing-with-yaml-files-and-their-directory-structure"
84
- puts "----------"
85
- end
86
-
87
- cleanup
95
+ def info_yaml_directory_structure
96
+ puts
97
+ puts "----------"
98
+ puts "If you're wondering why your YAML directory structure has changed so much,"
99
+ puts "please check this article: https://translation.io/blog/dealing-with-yaml-files-and-their-directory-structure"
100
+ puts "----------"
88
101
  end
89
102
  end
90
103
  end
@@ -20,8 +20,8 @@ module TranslationIO
20
20
  ApplyYamlSourceEditsStep.new(yaml_file_paths, source_locale).run(params)
21
21
 
22
22
  unless config.disable_gettext
23
- BaseOperation::DumpHamlGettextKeysStep.new(haml_source_files).run
24
- BaseOperation::DumpSlimGettextKeysStep.new(slim_source_files).run
23
+ BaseOperation::DumpMarkupGettextKeysStep.new(haml_source_files, :haml).run
24
+ BaseOperation::DumpMarkupGettextKeysStep.new(slim_source_files, :slim).run
25
25
  end
26
26
 
27
27
  UpdatePotFileStep.new(pot_path, source_files).run(params)
@@ -1,11 +1,6 @@
1
1
  require 'i18n'
2
2
  require 'i18n/config'
3
3
 
4
- require 'gettext'
5
- require 'gettext/po'
6
- require 'gettext/po_parser'
7
- require 'gettext/tools/xgettext'
8
-
9
4
  module TranslationIO
10
5
  class Railtie < Rails::Railtie
11
6
  rake_tasks do
@@ -28,34 +23,41 @@ module I18n
28
23
  def locale=(locale)
29
24
  I18n.enforce_available_locales!(locale) if I18n.respond_to?(:enforce_available_locales!)
30
25
  @locale = locale.to_sym rescue nil
31
- GetText.set_current_locale(locale.to_s.gsub('-', '_').to_sym)
26
+
27
+ if defined?(GetText)
28
+ GetText.set_current_locale(locale.to_s.gsub('-', '_').to_sym)
29
+ else
30
+ puts "do not set gettext locale because not loaded"
31
+ end
32
32
  end
33
33
  end
34
34
  end
35
35
 
36
- module GetText
37
- class POParser < Racc::Parser
38
- def initialize
39
- @ignore_fuzzy = true
40
- @report_warning = false
36
+ if defined?(GetText)
37
+ module GetText
38
+ class POParser < Racc::Parser
39
+ def initialize
40
+ @ignore_fuzzy = true
41
+ @report_warning = false
42
+ end
41
43
  end
42
- end
43
44
 
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
45
+ module Tools
46
+ class XGetText
47
+ def parse(paths)
48
+ po = PO.new
49
+ paths = [paths] if paths.kind_of?(String)
50
+ paths.each do |path|
51
+ begin
52
+ parse_path(path, po)
53
+ rescue SystemExit => e
54
+ # puts(_("Error parsing %{path}") % {:path => path})
55
+ puts
56
+ puts
57
+ end
56
58
  end
59
+ po
57
60
  end
58
- po
59
61
  end
60
62
  end
61
63
  end
@@ -1,3 +1,6 @@
1
+ require 'gettext'
2
+ require 'gettext/po'
3
+ require 'gettext/po_parser'
1
4
  require 'gettext/tools'
2
5
 
3
6
  namespace :translation do
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.7'
4
+ version: '1.8'
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: 2016-04-19 00:00:00.000000000 Z
12
+ date: 2016-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gettext
@@ -67,6 +67,20 @@ dependencies:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '4.1'
70
+ - !ruby/object:Gem::Dependency
71
+ name: codeclimate-test-reporter
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
70
84
  description: Rails translation made _("simple") with YAML and GetText. Localize your
71
85
  app using either t(".keys") or _("free text") and type "rake translation:sync" to
72
86
  synchronize with your translators.
@@ -80,8 +94,7 @@ files:
80
94
  - lib/translation_io/client.rb
81
95
  - lib/translation_io/client/base_operation.rb
82
96
  - lib/translation_io/client/base_operation/create_new_mo_files_step.rb
83
- - lib/translation_io/client/base_operation/dump_haml_gettext_keys_step.rb
84
- - lib/translation_io/client/base_operation/dump_slim_gettext_keys_step.rb
97
+ - lib/translation_io/client/base_operation/dump_markup_gettext_keys_step.rb
85
98
  - lib/translation_io/client/base_operation/save_new_po_files_step.rb
86
99
  - lib/translation_io/client/base_operation/save_new_yaml_files_step.rb
87
100
  - lib/translation_io/client/base_operation/save_special_yaml_files_step.rb
@@ -1,46 +0,0 @@
1
- module TranslationIO
2
- class Client
3
- class BaseOperation
4
- class DumpSlimGettextKeysStep
5
- def initialize(slim_source_files)
6
- @slim_source_files = slim_source_files
7
- end
8
-
9
- def run
10
- if @slim_source_files.any?
11
- TranslationIO.info "Extracting Gettext entries from SLIM files."
12
-
13
- FileUtils.mkdir_p(File.join('tmp', 'translation'))
14
-
15
- extracted_gettext_entries.each_with_index do |entry, index|
16
- file_path = File.join('tmp', 'translation', "slim-gettext-#{index.to_s.rjust(8,'0')}.rb")
17
-
18
- File.open(file_path, 'w') do |file|
19
- file.puts "def fake"
20
- file.puts " #{entry}"
21
- file.puts "end"
22
- end
23
- end
24
- end
25
- end
26
-
27
- protected
28
-
29
- def extracted_gettext_entries
30
- entries = []
31
-
32
- @slim_source_files.each do |slim_file_path|
33
- TranslationIO.info slim_file_path, 2, 2
34
-
35
- slim_data = File.read(slim_file_path)
36
- entries += TranslationIO::Extractor.extract(slim_data)
37
- end
38
-
39
- TranslationIO.info "#{entries.size} entries found", 2, 2
40
-
41
- entries
42
- end
43
- end
44
- end
45
- end
46
- end