custom_translations 0.1.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: 9794219a3581514757318819afe7767f0db39bde
4
+ data.tar.gz: 554cbd3368d09644937cad121ef040ba12320983
5
+ SHA512:
6
+ metadata.gz: 572d9d19a752f7c60e5116a826e5d8b2389e8c6ffbd595e5ddaa52bb8a94b2c6fb3a551309cb429fb9d6150194189ea9299130cc8c82cee87bb4b0e472befeb2
7
+ data.tar.gz: 06c0170dd6e0712f0f3c79d2dbc149cf3b95891f62f007b39a3698528230b8d27bba4c91a0e6f287e086f77cadc4e28bb73c557be3f223505c8231588e21b104
data/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ /.bundle
3
+ /Gemfile.lock
4
+ /pkg
5
+ /tmp
6
+ /coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=doc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # CustomTranslations
2
+
3
+ I18n locales overriding via single file.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'custom_translations'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install custom_translations
20
+
21
+ ## Usage
22
+
23
+ Initializer:
24
+ ```ruby
25
+ # config/initializers/custom_translations.rb
26
+ CustomTranslations.path = Rails.root.join('config/locale/custom_translations.yml')
27
+ CustomTranslations.blacklist_keys += [ :devise, :simple_form ]
28
+
29
+ # Add this to your application.rb
30
+ config.i18n.load_path += Dir["#{config.root}/config/locales/**/*.yml", CustomTranslations.path]
31
+ ```
32
+
33
+ Example usage:
34
+ ```ruby
35
+ # Dump translations.
36
+ translations = CustomTranslations.export
37
+
38
+ # Read from JSON.
39
+ CustomTranslations.import(JSON.parse(params[:translations]))
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/[my-github-username]/custom_translations/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
49
+
50
+ ## License
51
+
52
+ Copyright (c) 2014 Zakharov Ivan
53
+
54
+ MIT License
55
+
56
+ Permission is hereby granted, free of charge, to any person obtaining
57
+ a copy of this software and associated documentation files (the
58
+ "Software"), to deal in the Software without restriction, including
59
+ without limitation the rights to use, copy, modify, merge, publish,
60
+ distribute, sublicense, and/or sell copies of the Software, and to
61
+ permit persons to whom the Software is furnished to do so, subject to
62
+ the following conditions:
63
+
64
+ The above copyright notice and this permission notice shall be
65
+ included in all copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
68
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
69
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
70
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
71
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
72
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
73
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'custom_translations/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'custom_translations'
7
+ spec.version = CustomTranslations::VERSION
8
+ spec.authors = ['Zakharov Ivan']
9
+ spec.email = ['chronoiicross@gmail.com']
10
+ spec.summary = 'I18n locales overriding via single file.'
11
+ spec.description = 'I18n locales overriding via single file.'
12
+ spec.homepage = 'https://github.com/drMinami/custom_translations'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'activesupport', '~> 4'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3'
25
+ spec.add_development_dependency 'simplecov'
26
+ end
@@ -0,0 +1,41 @@
1
+ require "custom_translations/version"
2
+ require "active_support/all"
3
+
4
+ module I18n::Backend
5
+ class Simple
6
+ def stored_translations
7
+ init_translations unless initialized?
8
+ translations
9
+ end
10
+ end
11
+ end
12
+
13
+ module CustomTranslations
14
+ cattr_accessor :blacklist_keys
15
+ self.blacklist_keys = [
16
+ :date,
17
+ :time,
18
+ :datetime,
19
+ :number,
20
+ :errors,
21
+ :helpers,
22
+ :support,
23
+ :activerecord
24
+ ]
25
+
26
+ cattr_accessor :path
27
+
28
+ def self.import(data)
29
+ data.each do |locale, dict|
30
+ I18n.backend.store_translations(locale, dict)
31
+ end
32
+
33
+ File.write(path, YAML.dump(data))
34
+ end
35
+
36
+ def self.export
37
+ Hash[I18n.backend.stored_translations.map do |locale, translations|
38
+ [ locale, translations.except(*blacklist_keys) ]
39
+ end]
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module CustomTranslations
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,40 @@
1
+ require "spec_helper"
2
+ require "custom_translations"
3
+
4
+ describe CustomTranslations do
5
+ before(:all) do
6
+ I18n.load_path = ['spec/support/translations.yml']
7
+ CustomTranslations.path = 'spec/support/custom_translations.yml'
8
+ CustomTranslations.blacklist_keys << :devise
9
+ end
10
+
11
+ describe '.export' do
12
+ it 'excludes blacklisted keys' do
13
+ expect(CustomTranslations.export).to match_array({
14
+ en: {
15
+ quux: 'quux',
16
+ foo: 'foo',
17
+ bar: 'bar',
18
+ baz: 'baz'
19
+ }
20
+ })
21
+ end
22
+ end
23
+
24
+ describe '.import' do
25
+ it 'dumps dictionary to file' do
26
+ CustomTranslations.import({
27
+ en: {
28
+ quux: 'quux',
29
+ foo: 'foo',
30
+ bar: 'bar',
31
+ baz: 'baz'
32
+ }
33
+ })
34
+
35
+ contents = "---\n:en:\n :quux: quux\n :foo: foo\n :bar: bar\n :baz: baz\n"
36
+
37
+ expect(File.read(CustomTranslations.path)).to eq(contents)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,6 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ RSpec.configure do |config|
5
+ config.order = 'random'
6
+ end
@@ -0,0 +1,6 @@
1
+ ---
2
+ :en:
3
+ :quux: quux
4
+ :foo: foo
5
+ :bar: bar
6
+ :baz: baz
@@ -0,0 +1,9 @@
1
+ en:
2
+ quux: 'quux'
3
+ number: 'number'
4
+ foo: 'foo'
5
+ bar: 'bar'
6
+ support: 'support'
7
+ devise: 'devise'
8
+ baz: 'baz'
9
+ time: 'time'
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: custom_translations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Zakharov Ivan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: I18n locales overriding via single file.
84
+ email:
85
+ - chronoiicross@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".editorconfig"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - custom_translations.gemspec
97
+ - lib/custom_translations.rb
98
+ - lib/custom_translations/version.rb
99
+ - spec/custom_translations_spec.rb
100
+ - spec/spec_helper.rb
101
+ - spec/support/custom_translations.yml
102
+ - spec/support/translations.yml
103
+ homepage: https://github.com/drMinami/custom_translations
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: I18n locales overriding via single file.
127
+ test_files:
128
+ - spec/custom_translations_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/support/custom_translations.yml
131
+ - spec/support/translations.yml