tr4n5l4te 0.1.3 → 0.1.4

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: 2b4177a4047cbccd5f83335dae72a39945ba4bee
4
- data.tar.gz: a11c1373ef983181b6a73bee55797ff43d196b9b
3
+ metadata.gz: 4340f6701e586bd8b845004b3006e58574cacba1
4
+ data.tar.gz: eaf2a16a128c494b29e227b9f1eeaf9981cc4cfb
5
5
  SHA512:
6
- metadata.gz: 2c7bf02c1d0193dab810c7fee10762de2a9ebdfe89d2cb53bb6903e39e4e39f1a48129b8ff7fb68a1601de0671b6629f0e571bf8fe85ee594a8ed656f1c1ae43
7
- data.tar.gz: 8a946e815184707c392521322e61829c86703f2992634fa286527debaa4aef51e6c8ba2991394fcf361cc0a2835ed32ea87f9c50e6434b97a97d73a681735ce2
6
+ metadata.gz: 5ddde917d746dca94e383478f264db6a0b8be60afa0578db9ea071e31a95cd0ece374f947edc2de8ad2ba16a9b39e4743a0a644f6da8c10d648753c8de332fd9
7
+ data.tar.gz: c46a604bc040415700ef356656df1ebfbc1ed25a43e18c23a5a4b42bdb82c0e9f33248b2fad42c11d05dde684a9e37a3994e0b29e10778322a4781e1448907c2
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ *0.1.4* (November 10, 2017)
2
+
3
+ * Fix issue #3 - include original file basename in translated output filename
4
+
1
5
  *0.1.3* (March 16, 2016)
2
6
 
3
7
  * Warn when passing in a non-string to the Translator.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tr4n5l4te
2
2
 
3
- **Version: 0.1.3**
3
+ **Version: 0.1.4**
4
4
 
5
5
  Use Google Translate without an API key.
6
6
 
@@ -43,6 +43,16 @@ end
43
43
 
44
44
  ### Command Line
45
45
 
46
+ ➤ ./exe/translate -h
47
+ Options:
48
+ -y, --yaml-file=<s> A YAML locale file - filename determines source language 'en.yml' - English
49
+ -l, --lang=<s> Destination language
50
+ -i, --list List known languages
51
+ -s, --sleep-time=<i> Sleep time (default: 2)
52
+ -t, --timeout=<i> Poltergeist timeout option (default: 30)
53
+ -v, --verbose Be verbose with output
54
+ -h, --help Show this message
55
+
46
56
  To translate a YAML file:
47
57
 
48
58
  $ ./exe/translate -y /path/to/yml/file -l "destination-language"
data/lib/tr4n5l4te.rb CHANGED
@@ -6,6 +6,8 @@ require 'midwire_common/hash'
6
6
 
7
7
  module Tr4n5l4te
8
8
  class << self
9
+ attr_accessor :configuration
10
+
9
11
  def root
10
12
  Pathname.new(File.dirname(__FILE__)).parent
11
13
  end
@@ -39,10 +41,18 @@ module Tr4n5l4te
39
41
  FileUtils.touch(file)
40
42
  file
41
43
  end
44
+
45
+ def configure
46
+ self.configuration ||= Configuration.new
47
+ yield(configuration)
48
+ end
42
49
  end
43
50
 
44
- autoload :Agent, 'tr4n5l4te/agent'
45
- autoload :Language, 'tr4n5l4te/language'
46
- autoload :Runner, 'tr4n5l4te/runner'
47
- autoload :Translator, 'tr4n5l4te/translator'
51
+ autoload :Agent, 'tr4n5l4te/agent'
52
+ autoload :Configuration, 'tr4n5l4te/configuration'
53
+ autoload :Language, 'tr4n5l4te/language'
54
+ autoload :Runner, 'tr4n5l4te/runner'
55
+ autoload :Translator, 'tr4n5l4te/translator'
48
56
  end
57
+
58
+ Tr4n5l4te.configure {}
@@ -4,7 +4,11 @@ require 'yaml'
4
4
 
5
5
  module Tr4n5l4te
6
6
  Capybara.register_driver :poltergeist do |app|
7
- Capybara::Poltergeist::Driver.new(app, js_errors: false)
7
+ Capybara::Poltergeist::Driver.new(
8
+ app,
9
+ js_errors: false,
10
+ timeout: Tr4n5l4te.configuration.timeout
11
+ )
8
12
  end
9
13
  Capybara.default_driver = :poltergeist
10
14
  Capybara.javascript_driver = :poltergeist
@@ -0,0 +1,9 @@
1
+ module Tr4n5l4te
2
+ class Configuration
3
+ attr_accessor :timeout
4
+
5
+ def initialize
6
+ @timeout = 30
7
+ end
8
+ end
9
+ end
@@ -21,6 +21,11 @@ module Tr4n5l4te
21
21
  log_identifier(start_time)
22
22
  @count = 0
23
23
 
24
+ # configure
25
+ Tr4n5l4te.configure do |config|
26
+ config.timeout = options[:timeout]
27
+ end
28
+
24
29
  hash = YAML.load_file(options[:yaml_file])
25
30
  translated = process(hash)
26
31
  store_translation(translated)
@@ -49,13 +54,16 @@ module Tr4n5l4te
49
54
  end
50
55
 
51
56
  def from_lang
52
- File.basename(options[:yaml_file], '.yml')
57
+ md = File.basename(options[:yaml_file]).match(/^.+(\w\w)\.yml$/)
58
+ raise "Could not determine language from yaml file: '#{options[:yaml_file]}'" unless md
59
+ md[1]
53
60
  end
54
61
 
55
62
  def store_translation(translated)
56
63
  data = YAML.dump(translated)
57
64
  dir = File.dirname(options[:yaml_file])
58
- File.open(File.join(dir, "#{options[:lang]}.yml"), 'w') { |f| f.write(data) }
65
+ base = File.basename(options[:yaml_file]).gsub(/#{from_lang}\.yml$/, '')
66
+ File.open(File.join(dir, "#{base}#{options[:lang]}.yml"), 'w') { |f| f.write(data) }
59
67
  end
60
68
 
61
69
  # rubocop:disable Metrics/MethodLength
@@ -72,11 +80,15 @@ module Tr4n5l4te
72
80
  opt(
73
81
  :list,
74
82
  'List known languages',
75
- type: :boolean, required: false, short: 't')
83
+ type: :boolean, required: false)
76
84
  opt(
77
85
  :sleep_time,
78
86
  'Sleep time',
79
87
  type: :integer, default: 2, short: 's')
88
+ opt(
89
+ :timeout,
90
+ 'Poltergeist timeout option - default 30',
91
+ type: :integer, default: 30, short: 't')
80
92
  opt(
81
93
  :verbose,
82
94
  'Be verbose with output',
@@ -1,3 +1,3 @@
1
1
  module Tr4n5l4te
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tr4n5l4te
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Blackburn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -171,6 +171,7 @@ files:
171
171
  - exe/translate
172
172
  - lib/tr4n5l4te.rb
173
173
  - lib/tr4n5l4te/agent.rb
174
+ - lib/tr4n5l4te/configuration.rb
174
175
  - lib/tr4n5l4te/language.rb
175
176
  - lib/tr4n5l4te/runner.rb
176
177
  - lib/tr4n5l4te/translator.rb
@@ -196,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
197
  version: '0'
197
198
  requirements: []
198
199
  rubyforge_project:
199
- rubygems_version: 2.4.5.1
200
+ rubygems_version: 2.5.1
200
201
  signing_key:
201
202
  specification_version: 4
202
203
  summary: Use Google Translate without an API key.