translatomatic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +51 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +137 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +74 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/bin/translatomatic +6 -0
  14. data/db/database.yml +9 -0
  15. data/db/migrate/201712170000_initial.rb +23 -0
  16. data/lib/translatomatic/cli.rb +92 -0
  17. data/lib/translatomatic/config.rb +26 -0
  18. data/lib/translatomatic/converter.rb +157 -0
  19. data/lib/translatomatic/converter_stats.rb +27 -0
  20. data/lib/translatomatic/database.rb +105 -0
  21. data/lib/translatomatic/escaped_unicode.rb +90 -0
  22. data/lib/translatomatic/model/locale.rb +22 -0
  23. data/lib/translatomatic/model/text.rb +13 -0
  24. data/lib/translatomatic/model.rb +4 -0
  25. data/lib/translatomatic/option.rb +24 -0
  26. data/lib/translatomatic/resource_file/base.rb +137 -0
  27. data/lib/translatomatic/resource_file/html.rb +33 -0
  28. data/lib/translatomatic/resource_file/plist.rb +29 -0
  29. data/lib/translatomatic/resource_file/properties.rb +60 -0
  30. data/lib/translatomatic/resource_file/text.rb +28 -0
  31. data/lib/translatomatic/resource_file/xcode_strings.rb +65 -0
  32. data/lib/translatomatic/resource_file/xml.rb +64 -0
  33. data/lib/translatomatic/resource_file/yaml.rb +80 -0
  34. data/lib/translatomatic/resource_file.rb +74 -0
  35. data/lib/translatomatic/translation_result.rb +68 -0
  36. data/lib/translatomatic/translator/base.rb +47 -0
  37. data/lib/translatomatic/translator/frengly.rb +64 -0
  38. data/lib/translatomatic/translator/google.rb +30 -0
  39. data/lib/translatomatic/translator/microsoft.rb +32 -0
  40. data/lib/translatomatic/translator/my_memory.rb +55 -0
  41. data/lib/translatomatic/translator/yandex.rb +37 -0
  42. data/lib/translatomatic/translator.rb +63 -0
  43. data/lib/translatomatic/util.rb +24 -0
  44. data/lib/translatomatic/version.rb +3 -0
  45. data/lib/translatomatic.rb +27 -0
  46. data/translatomatic.gemspec +46 -0
  47. metadata +329 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 146d42de6429eea2a7b3598be2e6a0fca7b1ad698d990068e4f432152979c021
4
+ data.tar.gz: f87d1f735a5d9d9a868e6112653ec7c9e393abe060880bf86e8adf389e3f761a
5
+ SHA512:
6
+ metadata.gz: 6b1ac516743bd739b785b937e4c969112029a3cf90e14343b42ce42613c29955c6442b847e80c9d7cd134a20b60e722f1b0261ec2c38b8a546c2223332242060
7
+ data.tar.gz: 99f948dcd088f261ba4ab1b96d8b788759999f2620e791d58761250a8575b3902e7aebfc374569f39a964438a4a58f1cfbeff62b9bfeb680acac18407ef0cba7
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/tmp/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,51 @@
1
+ # Enables Travis to use their new container-based infrastructure
2
+ sudo: false
3
+
4
+ # Build for Ruby
5
+ language: ruby
6
+
7
+ # Enables caching for bundler
8
+ cache: bundler
9
+
10
+ # Passes arguments to bundle install (http://gembundler.com/man/bundle-install.1.html)
11
+ # bundler_args:
12
+
13
+ # Specify which ruby versions you wish to run your tests on, each version will be used
14
+ rvm:
15
+ - 1.9
16
+ - 2.2
17
+ - 2.3
18
+ - 2.4
19
+ - ruby-head
20
+ - jruby
21
+
22
+ # Define how to run your tests (defaults to `bundle exec rake` or `rake` depending on whether you have a `Gemfile`)
23
+ script: "bundle exec rake"
24
+
25
+ # Define tasks to be completed before and after tests run . Will allow folding of content on frontend
26
+ #before_script:
27
+ # - command_1
28
+ # - command_2
29
+ #
30
+ #after_script:
31
+ # - command_1
32
+ # - command_2
33
+
34
+ # Specify an ENV variable to run before: 'bundle install' and 'rake' (or your defined 'script')
35
+ env:
36
+ - CI=1
37
+
38
+ # Specify the recipients for email notification
39
+ #notifications:
40
+ # recipients:
41
+ # - email-address-1
42
+ # - email-address-2
43
+
44
+ # Disable email notifications
45
+ #notifications:
46
+ # disabled: true
47
+
48
+ # notifications:
49
+ # webhooks:
50
+ # urls:
51
+ # - https://webhooks.gitter.im/e/c6dbb9323007dfcf81df
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at contact@smugglys.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/smugglys/translatomatic" }
4
+
5
+ # Specify your gem's dependencies in translatomatic.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,137 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ translatomatic (0.1.0)
5
+ activerecord (~> 5.0)
6
+ bigdecimal
7
+ bing_translator (~> 5.1.0)
8
+ easy_translate
9
+ i18n
10
+ i18n_data
11
+ mysql2
12
+ nokogiri
13
+ sqlite3 (~> 1.3)
14
+ thor (~> 0.20)
15
+ yandex-translator
16
+
17
+ GEM
18
+ remote: https://rubygems.org/
19
+ specs:
20
+ activemodel (5.1.4)
21
+ activesupport (= 5.1.4)
22
+ activerecord (5.1.4)
23
+ activemodel (= 5.1.4)
24
+ activesupport (= 5.1.4)
25
+ arel (~> 8.0)
26
+ activesupport (5.1.4)
27
+ concurrent-ruby (~> 1.0, >= 1.0.2)
28
+ i18n (~> 0.7)
29
+ minitest (~> 5.1)
30
+ tzinfo (~> 1.1)
31
+ addressable (2.5.2)
32
+ public_suffix (>= 2.0.2, < 4.0)
33
+ akami (1.3.1)
34
+ gyoku (>= 0.4.0)
35
+ nokogiri
36
+ arel (8.0.0)
37
+ bigdecimal (1.3.3)
38
+ bing_translator (5.1.0)
39
+ json (~> 1.8.0)
40
+ nokogiri (~> 1.8.1)
41
+ savon (~> 2.10.0)
42
+ builder (3.2.3)
43
+ concurrent-ruby (1.0.5)
44
+ crack (0.4.3)
45
+ safe_yaml (~> 1.0.0)
46
+ diff-lcs (1.3)
47
+ docile (1.1.5)
48
+ easy_translate (0.5.0)
49
+ json
50
+ thread
51
+ thread_safe
52
+ gyoku (1.3.1)
53
+ builder (>= 2.1.2)
54
+ hashdiff (0.3.7)
55
+ httparty (0.15.6)
56
+ multi_xml (>= 0.5.2)
57
+ httpi (2.4.2)
58
+ rack
59
+ socksify
60
+ i18n (0.9.1)
61
+ concurrent-ruby (~> 1.0)
62
+ i18n_data (0.8.0)
63
+ json (1.8.6)
64
+ macaddr (1.7.1)
65
+ systemu (~> 2.6.2)
66
+ mini_portile2 (2.3.0)
67
+ minitest (5.10.3)
68
+ multi_xml (0.6.0)
69
+ mysql2 (0.4.10)
70
+ nokogiri (1.8.1)
71
+ mini_portile2 (~> 2.3.0)
72
+ nori (2.6.0)
73
+ public_suffix (3.0.1)
74
+ rack (2.0.3)
75
+ rake (10.5.0)
76
+ rspec (3.7.0)
77
+ rspec-core (~> 3.7.0)
78
+ rspec-expectations (~> 3.7.0)
79
+ rspec-mocks (~> 3.7.0)
80
+ rspec-core (3.7.0)
81
+ rspec-support (~> 3.7.0)
82
+ rspec-expectations (3.7.0)
83
+ diff-lcs (>= 1.2.0, < 2.0)
84
+ rspec-support (~> 3.7.0)
85
+ rspec-mocks (3.7.0)
86
+ diff-lcs (>= 1.2.0, < 2.0)
87
+ rspec-support (~> 3.7.0)
88
+ rspec-support (3.7.0)
89
+ safe_yaml (1.0.4)
90
+ savon (2.10.1)
91
+ akami (~> 1.2)
92
+ builder (>= 2.1.2)
93
+ gyoku (~> 1.2)
94
+ httpi (~> 2.3)
95
+ nokogiri (>= 1.4.0)
96
+ nori (~> 2.4)
97
+ uuid (~> 2.3.7)
98
+ wasabi (~> 3.4)
99
+ simplecov (0.15.1)
100
+ docile (~> 1.1.0)
101
+ json (>= 1.8, < 3)
102
+ simplecov-html (~> 0.10.0)
103
+ simplecov-html (0.10.2)
104
+ socksify (1.7.1)
105
+ sqlite3 (1.3.13)
106
+ systemu (2.6.5)
107
+ thor (0.20.0)
108
+ thread (0.2.2)
109
+ thread_safe (0.3.6)
110
+ tzinfo (1.2.4)
111
+ thread_safe (~> 0.1)
112
+ uuid (2.3.8)
113
+ macaddr (~> 1.0)
114
+ wasabi (3.5.0)
115
+ httpi (~> 2.0)
116
+ nokogiri (>= 1.4.2)
117
+ webmock (3.1.1)
118
+ addressable (>= 2.3.6)
119
+ crack (>= 0.3.2)
120
+ hashdiff
121
+ yandex-translator (0.3.2)
122
+ httparty (>= 0.13.4)
123
+
124
+ PLATFORMS
125
+ ruby
126
+
127
+ DEPENDENCIES
128
+ bundler (~> 1.16)
129
+ rake (~> 10.0)
130
+ rspec (~> 3.0)
131
+ rspec-mocks (~> 3.0)
132
+ simplecov
133
+ translatomatic!
134
+ webmock
135
+
136
+ BUNDLED WITH
137
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Smuggly Systems Intergalactic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ [![Build Status](https://travis-ci.org/smugglys/translatomatic.svg?branch=master)](https://travis-ci.org/smugglys/translatomatic)
2
+ [![Gem Version](https://badge.fury.io/rb/translatomatic.svg)](https://badge.fury.io/rb/translatomatic)
3
+ [![Documentation](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/gems/translatomatic)
4
+
5
+ # Translatomatic
6
+
7
+ Translates text files from one language to another.
8
+
9
+ Features:
10
+ - Translated strings are saved in a database and reused.
11
+ - Understands how to translate different types of files, e.g. java properties, xcode strings, YAML, text, markdown.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'translatomatic'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install translatomatic
28
+
29
+ ## Usage
30
+
31
+ The command line interface for translation functionality is **translatomatic**. For help on available options, execute:
32
+
33
+ $ translatomatic help
34
+
35
+ ## Example Usage
36
+
37
+ To list available translation backends and options:
38
+
39
+ $ translatomatic translators
40
+
41
+ To translate a java properties file to German and French:
42
+
43
+ $ translatomatic src/main/resources/strings.properties de fr
44
+
45
+ This would create the following files.
46
+
47
+ src/main/resources/strings_de.properties
48
+ src/main/resources/strings_fr.properties
49
+
50
+ ## Configuration
51
+
52
+ By default, translatomatic uses an sqlite3 database in *$HOME/.translatomatic/translatomatic.sqlite3* to store translated strings.
53
+ The database can be changed by creating a *database.yml* file under *$HOME/.translatomatic/database.yml* for the **production** environment, e.g.
54
+
55
+ production:
56
+ adapter: mysql2
57
+ host: db.example.com
58
+ database: translatomatic
59
+ pool: 5
60
+ encoding: utf8
61
+ username: username
62
+ password: password
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/smugglys/translatomatic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
71
+
72
+ ## Code of Conduct
73
+
74
+ Everyone interacting in the Translatomatic project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/smugglys/translatomatic/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "translatomatic"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "translatomatic"
5
+
6
+ Translatomatic::CLI.start
data/db/database.yml ADDED
@@ -0,0 +1,9 @@
1
+ production:
2
+ adapter: sqlite3
3
+ encoding: utf-8
4
+ database: $HOME/.translatomatic/translatomatic.sqlite3
5
+
6
+ test:
7
+ adapter: sqlite3
8
+ encoding: utf-8
9
+ database: $GEM_ROOT/spec/tmp/translatomatic.sqlite3
@@ -0,0 +1,23 @@
1
+ # @!visibility private
2
+ class Initial < ActiveRecord::Migration[4.2] # :nodoc:
3
+ def change
4
+ create_table :locales do |t|
5
+ t.string :language, null: false # e.g. "en" ISO 639-1
6
+ t.string :script # e.g. "Hans" ISO 15924
7
+ t.string :region # e.g. "US" ISO 3166-1 alpha-2
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :locales, [:language, :script, :region]
12
+
13
+ create_table :texts do |t|
14
+ t.belongs_to :locale, index: true, null: false
15
+ t.belongs_to :from_text, index: true, foreign_key: {
16
+ to_table: :texts, on_delete: :cascade
17
+ }
18
+ t.text :value, null: false
19
+ t.string :translator
20
+ t.timestamps
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,92 @@
1
+ require "thor"
2
+
3
+ class Translatomatic::CLI < Thor
4
+ include Translatomatic::Util
5
+ package_name "Translatomatic"
6
+ map %W[-v --version] => :version
7
+ map %W[-L --list] => :translators
8
+
9
+ desc "translate file locale...", "translate files to target locale(s)"
10
+ method_option :translator, enum: Translatomatic::Translator.names
11
+ method_option :source_locale, desc: "The locale of the source file, default is autodetermined"
12
+ method_option :debug, type: :boolean, desc: "Turn on debugging output"
13
+ Translatomatic::Converter.options.each do |option|
14
+ method_option option.name, option.to_hash
15
+ end
16
+ Translatomatic::Database.options.each do |option|
17
+ method_option option.name, option.to_hash
18
+ end
19
+ Translatomatic::Translator.modules.each do |mod|
20
+ mod.options.each do |option|
21
+ method_option option.name, option.to_hash
22
+ end
23
+ end
24
+ def translate(file, locale, *locales)
25
+ begin
26
+ log.info("dry run: files will not be translated or written") if options[:dry_run]
27
+
28
+ Translatomatic::Config.instance.debug = options[:debug] if options[:debug]
29
+ Translatomatic::Database.new(options)
30
+
31
+ translator = select_translator
32
+ log.info("Using translator #{translator.name}")
33
+
34
+ converter_options = options.merge(translator: translator)
35
+ converter = Translatomatic::Converter.new(converter_options)
36
+ source = Translatomatic::ResourceFile.load(file, options[:source_locale])
37
+
38
+ raise "Unsupported file type #{file}" unless source
39
+ target_locales = [locale]
40
+ target_locales += locales
41
+ target_locales.each { |i| converter.translate(source, i) }
42
+
43
+ log.info converter.stats
44
+ true
45
+ rescue Interrupt
46
+ puts "\nAborted"
47
+ false
48
+ rescue Exception => e
49
+ log.error("Error translating #{file}")
50
+ log.error(e.message)
51
+ log.debug(e.backtrace.join("\n"))
52
+ false
53
+ end
54
+ end
55
+
56
+ desc "translators", "list available translation backends"
57
+ def translators
58
+ puts Translatomatic::Translator.list
59
+ end
60
+
61
+ desc 'version', 'Display version'
62
+ def version
63
+ puts "Translatomatic version #{Translatomatic::VERSION}"
64
+ end
65
+
66
+ private
67
+
68
+ def select_translator
69
+ # use options translator if specified
70
+ if options[:translator]
71
+ klass = Translatomatic::Translator.find(options[:translator])
72
+ return klass.new(options)
73
+ end
74
+
75
+ # find all available translators that work with the given options
76
+ available = Translatomatic::Translator.available(options)
77
+ if available.empty?
78
+ raise "No translators configured. Use the translators command to see options"
79
+ end
80
+
81
+ return available[0] if available.length == 1
82
+
83
+ # prompt user for which translator to use
84
+ say("Multiple translators available:")
85
+ available.each_with_index { |mod, i| say(" #{i + 1}) #{mod.name}") }
86
+ loop do
87
+ idx = ask("Select translator (1-#{available.length}): ")
88
+ idx = idx.to_i
89
+ return available[idx - 1] if (1..available.length).include?(idx)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,26 @@
1
+ require 'singleton'
2
+ class Translatomatic::Config
3
+ include Singleton
4
+
5
+ attr_accessor :logger
6
+ attr_accessor :debug
7
+
8
+ def debug=(value)
9
+ @debug = value ? true : false
10
+ @logger.level = @debug ? Logger::DEBUG : Logger::INFO
11
+ end
12
+
13
+ private
14
+
15
+ def initialize
16
+ @logger = Logger.new(STDOUT)
17
+ @logger.formatter = proc do |severity, datetime, progname, msg|
18
+ "#{msg}\n"
19
+ end
20
+ self.debug = ENV['DEBUG'] ? true : false
21
+ end
22
+
23
+ def debug?
24
+ @debug
25
+ end
26
+ end