translator_with_localeapp 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec29e837e47f36f1b8ec77af4a95107519578e30
4
+ data.tar.gz: fd296837f7d3a2df0f4db78768e27dd151363ab4
5
+ SHA512:
6
+ metadata.gz: 06f6c3fef7926e466b7525d544deefaed3cbc23535c3070a4ef087e866e33ba383c6b453fcdda84fcd6ef78270ad57c7e2e4184a9709d4b28163253b20717b71
7
+ data.tar.gz: c3781148eebedb327930d636c9d310e56d3f567bf7ceb9ecdb869a3dc861eb0ece7925da54be290567884792bb7839316c4903a43587c5b7d1d9db4a7d698a59
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .ruby-version
2
+ locales/
3
+ .localeapp/
4
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'redis'
7
+ gem 'byebug'
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Kuldeep Aggarwal
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ Translator
2
+ -------
data/lib/translator.rb ADDED
@@ -0,0 +1,55 @@
1
+ require 'active_support/core_ext/module/attribute_accessors'
2
+
3
+ module Translator
4
+ autoload :NullStream, 'translator/null_stream'
5
+ autoload :Synchronizer, 'translator/synchronizer'
6
+ autoload :Store, 'translator/store'
7
+ autoload :YamlFileFlattener, 'translator/yaml_file_flattener'
8
+
9
+ mattr_accessor :storage
10
+ @@storage = :Redis
11
+
12
+ mattr_accessor :storage_options
13
+ @@storage_options = { host: 'localhost', port: 6379, db: 1 }
14
+
15
+ mattr_accessor :output_stream
16
+ @@output_stream = nil
17
+
18
+ mattr_reader :default_output_stream
19
+ @@default_output_stream = NullStream.new
20
+
21
+ mattr_accessor :synchronization_data_file
22
+ @@synchronization_data_file = File.expand_path('../../.localeapp/log.yml', __FILE__)
23
+
24
+ mattr_accessor :data_directory
25
+ @@data_directory = File.expand_path('../../locales', __FILE__)
26
+
27
+ mattr_accessor :localeapp_api_key
28
+ @@localeapp_api_key = ''
29
+
30
+
31
+ def self.setup
32
+ yield self if block_given?
33
+ setup_localeapp_configurations
34
+ end
35
+
36
+ def self.load!(paths)
37
+ Synchronizer.new(paths, output_stream).process
38
+ Store.instance.load_files(paths)
39
+ end
40
+
41
+ def self.default_file_paths
42
+ Dir[File.join(data_directory, '*.yml')]
43
+ end
44
+
45
+ def self.setup_localeapp_configurations
46
+ require 'localeapp'
47
+ Localeapp.configure do |config|
48
+ config.api_key = localeapp_api_key
49
+ config.translation_data_directory = data_directory
50
+ config.synchronization_data_file = synchronization_data_file
51
+ config.poll_interval = 0
52
+ end
53
+ end
54
+ private_class_method :setup_localeapp_configurations
55
+ end
@@ -0,0 +1,7 @@
1
+ module Translator
2
+ class NullStream
3
+ def puts(o); end
4
+ alias :write :puts
5
+ alias :<< :puts
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ require 'singleton'
2
+ require 'forwardable'
3
+ require 'moneta'
4
+
5
+ module Translator
6
+ class Store
7
+ include Singleton
8
+ extend Forwardable
9
+
10
+ def initialize(type = Translator.storage, options = Translator.storage_options)
11
+ @type = type # can be removed
12
+ @options = options # can be removed
13
+ @storage = Moneta.new(type, options)
14
+ end
15
+ def_delegators :@storage, :key?, :clear
16
+
17
+ def write(key, value)
18
+ @storage[key] = value
19
+ end
20
+ alias :[]= :write
21
+
22
+ def read(key)
23
+ @storage[key]
24
+ end
25
+ alias :[] :read
26
+
27
+ def load_files(paths)
28
+ paths = (Array(paths) + Translator.default_file_paths).uniq
29
+ YamlFileFlattener.new(paths).process.each { |language, data| write(language, data) }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ module Translator
2
+ class Synchronizer
3
+ attr_reader :paths, :output_stream
4
+ def initialize(paths, output_stream = Translator.output_stream)
5
+ @paths = (Array(paths) + Translator.default_file_paths).uniq
6
+ @output_stream = output_stream || Translator.default_output_stream
7
+ end
8
+
9
+ def process
10
+ push
11
+ update
12
+ end
13
+
14
+ private
15
+ def push
16
+ pusher = ::Localeapp::CLI::Push.new(output: output_stream)
17
+ paths.each { |path| pusher.execute(path) }
18
+ end
19
+
20
+ def update
21
+ pull unless pulled?
22
+ Localeapp::CLI::Update.new(output: output_stream).execute
23
+ end
24
+
25
+ def pull
26
+ require 'fileutils'
27
+ FileUtils.mkdir_p(Translator.data_directory)
28
+ FileUtils.mkdir_p(Pathname.new(Translator.synchronization_data_file).parent)
29
+ File.open(Translator.synchronization_data_file, 'w') { }
30
+ Localeapp::CLI::Pull.new(output: output_stream).execute
31
+ end
32
+
33
+ def pulled?
34
+ File.exist?(resolve_path(Translator.synchronization_data_file))
35
+ end
36
+
37
+ def resolve_path(path)
38
+ File.expand_path(path, __FILE__)
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ module Translator
2
+ module Version
3
+ VERSION = '1.0.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require 'yaml'
2
+
3
+ module Translator
4
+ class YamlFileFlattener
5
+
6
+ attr_reader :paths, :result
7
+ def initialize(paths)
8
+ @paths = paths
9
+ @result = Hash.new { |hash, key| hash[key] = {} }
10
+ end
11
+
12
+ def process
13
+ paths.each do |path|
14
+ load_file(path) do |lang, data|
15
+ result[lang].merge!(data)
16
+ end
17
+ end
18
+ result
19
+ end
20
+
21
+ private
22
+ def load_file(path)
23
+ YAML.load_file(path).each { |lang, data| yield(lang, data) }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'translator/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'translator_with_localeapp'
7
+ s.version = Translator::Version::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.licenses = 'MIT'
10
+ s.summary = 'Flexible syncronization solution of locales with LocaleApp'
11
+ s.email = ['kd.engineer@yahoo.co.in']
12
+ s.homepage = 'https://github.com/kuldeepaggarwal/translator'
13
+ s.description = 'Flexible syncronization solution of locales with LocaleApp.'
14
+ s.authors = ['Kuldeep Aggarwal']
15
+
16
+ s.rubyforge_project = 'devise'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ s.test_files = `git ls-files -- test/*`.split("\n")
21
+ s.require_paths = ['lib']
22
+
23
+ s.required_ruby_version = '>= 1.9.3'
24
+
25
+ s.add_dependency('localeapp', '~> 0.9')
26
+ s.add_dependency('moneta', '~> 0.8')
27
+ s.add_dependency('activesupport', '>= 3.2', '< 5')
28
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: translator_with_localeapp
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kuldeep Aggarwal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: localeapp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: moneta
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ - - <
49
+ - !ruby/object:Gem::Version
50
+ version: '5'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '3.2'
58
+ - - <
59
+ - !ruby/object:Gem::Version
60
+ version: '5'
61
+ description: Flexible syncronization solution of locales with LocaleApp.
62
+ email:
63
+ - kd.engineer@yahoo.co.in
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - .gitignore
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - lib/translator.rb
73
+ - lib/translator/null_stream.rb
74
+ - lib/translator/store.rb
75
+ - lib/translator/synchronizer.rb
76
+ - lib/translator/version.rb
77
+ - lib/translator/yaml_file_flattener.rb
78
+ - translator.gemspec
79
+ homepage: https://github.com/kuldeepaggarwal/translator
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 1.9.3
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project: devise
99
+ rubygems_version: 2.2.2
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Flexible syncronization solution of locales with LocaleApp
103
+ test_files: []