localer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a309d2dbc2fa3ea7e8ac7de8203ce0f035a7ca4
4
+ data.tar.gz: 865767a7d9351227ff9e4251ead00c9f85c03c0f
5
+ SHA512:
6
+ metadata.gz: 36d7e4bb99174638cf5d9feb228cf89b690a694b48a0f3514820be3facf40f89c4bd681a23519707d22a2daf5fd6834d086b71cd82dd212a202e937ffef4704c
7
+ data.tar.gz: e94ff2870007d253cf7cf7ff2e58987ae0c59e72255c4fecbb6f6475aa1fef934c3f79fc3f54b34eae35e70a19ab8cf4765ff2b8506d666ba7db68e2d8acd977
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,68 @@
1
+ AllCops:
2
+ # Include gemspec and Rakefile
3
+ Include:
4
+ - 'lib/**/*.rb'
5
+ - 'lib/**/*.rake'
6
+ - 'spec/**/*.rb'
7
+ Exclude:
8
+ - 'bin/**/*'
9
+ - 'Gemfile'
10
+ - 'Rakefile'
11
+ - '*.gemspec'
12
+ DisplayCopNames: true
13
+ StyleGuideCopsOnly: false
14
+ TargetRubyVersion: 2.4
15
+
16
+ Naming/AccessorMethodName:
17
+ Enabled: false
18
+
19
+ Style/PercentLiteralDelimiters:
20
+ Enabled: false
21
+
22
+ Style/TrivialAccessors:
23
+ Enabled: false
24
+
25
+ Style/Documentation:
26
+ Exclude:
27
+ - 'spec/**/*.rb'
28
+
29
+ Style/StringLiterals:
30
+ Enabled: false
31
+
32
+ Style/BlockDelimiters:
33
+ Exclude:
34
+ - 'spec/**/*.rb'
35
+
36
+ Style/DoubleNegation:
37
+ Enabled: false
38
+
39
+ Layout/SpaceInsideStringInterpolation:
40
+ EnforcedStyle: no_space
41
+
42
+ Lint/AmbiguousRegexpLiteral:
43
+ Enabled: false
44
+
45
+ Lint/AmbiguousBlockAssociation:
46
+ Enabled: false
47
+
48
+ Metrics/MethodLength:
49
+ Exclude:
50
+ - 'spec/**/*.rb'
51
+
52
+ Metrics/LineLength:
53
+ Max: 120
54
+ Exclude:
55
+ - 'spec/**/*.rb'
56
+
57
+ Metrics/BlockLength:
58
+ Exclude:
59
+ - 'spec/**/*.rb'
60
+
61
+ Rails/Date:
62
+ Enabled: false
63
+
64
+ Rails/TimeZone:
65
+ Enabled: false
66
+
67
+ Security/YAMLLoad:
68
+ Enabled: false
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.3
5
+ before_install: gem install bundler -v 1.16.0
@@ -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 deriabin@gmail.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/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in localer.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Andrey Deryabin
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.
@@ -0,0 +1,42 @@
1
+ # Localer
2
+
3
+ Automatic detecting missing I18n translations tool.
4
+
5
+
6
+ <a href="https://evilmartians.com/">
7
+ <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'localer'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install localer
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aderyabin/localer. 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.
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
39
+
40
+ ## Code of Conduct
41
+
42
+ Everyone interacting in the Localer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/aderyabin/localer/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: [:rubocop, :spec]
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "pry"
4
+ require "thor"
5
+ require_relative "../lib/localer"
6
+
7
+ module Localer
8
+ class CLI < Thor
9
+ desc "version", "Print Localer version"
10
+ def version
11
+ say Localer::VERSION
12
+ end
13
+
14
+ desc "check", "Check I18n complete"
15
+ def check
16
+ if Localer.complete?
17
+ say "\xE2\x9C\x94 No missing translations found.", :green
18
+ else
19
+ missing_translations = Localer.missing_translations
20
+ say "\xE2\x9C\x96 Missing translations found (#{missing_translations.count}):", :red
21
+ missing_translations.each do |tr|
22
+ say "* #{tr}"
23
+ end
24
+
25
+ exit 1
26
+ end
27
+ end
28
+
29
+ desc "console", "Run console"
30
+ def console
31
+ binding.pry
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ Localer::CLI.start(ARGV)
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "localer/version"
4
+ require_relative "localer/service"
5
+ require_relative "localer/parser"
6
+ require_relative "localer/checker"
7
+ require_relative "localer/config"
8
+ require_relative "localer/missing_translations"
9
+
10
+ module Localer # :nodoc:
11
+ class << self
12
+ def parcer
13
+ @parcer ||= begin
14
+ require File.expand_path("config/environment", Dir.pwd)
15
+ I18n.backend.send(:init_translations)
16
+ Parser.call(I18n.backend.send(:translations))
17
+ end
18
+ end
19
+
20
+ # returns array of available locales
21
+ def locales
22
+ parcer.locales
23
+ end
24
+
25
+ def data
26
+ parcer.data
27
+ end
28
+
29
+ # checks missing translations
30
+ def complete?
31
+ Checker.call(locales, data)
32
+ end
33
+
34
+ # returns array of missing translations
35
+ def missing_translations
36
+ MissingTranslations.call(locales, data)
37
+ end
38
+
39
+ def config
40
+ @config ||= Config.call
41
+ end
42
+
43
+ def each_data
44
+ data.each do |key, value|
45
+ locales.each do |locale|
46
+ yield locale, key, value[locale]
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Localer
4
+ # Check missing translations
5
+ # Returns true if no missing translations found, otherwise false
6
+ class Checker < Service
7
+ def call
8
+ Localer.each_data do |_locale, _key, value|
9
+ return false if value.nil?
10
+ end
11
+ true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ module Localer
6
+ # Loads and parse Localer config file `.localer.yml`
7
+ class Config < Service
8
+ option :exclude, default: -> { [] }
9
+ def call
10
+ return unless File.exist?(filename)
11
+ yaml = YAML.load_file(filename)
12
+ @exclude = yaml["Exclude"] if yaml&.key?("Exclude")
13
+ self
14
+ end
15
+
16
+ private
17
+
18
+ def filename
19
+ File.expand_path(".localer.yml", Dir.pwd)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Localer
4
+ # A service that returns array of missing translations
5
+ class MissingTranslations < Service
6
+ def call
7
+ missing = []
8
+ Localer.each_data do |locale, key, value|
9
+ missing.push("#{locale}#{key}") if value.nil?
10
+ end
11
+ missing
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Localer
4
+ # Parse translations into hash:
5
+ # key: translation key
6
+ # value: hash of locale values
7
+ class Parser < Service
8
+ param :translations
9
+ param :config, default: -> { Localer.config }
10
+
11
+ attr_reader :data, :locales
12
+
13
+ def call
14
+ @data = {}
15
+ @locales = []
16
+ @translations.each do |(locale, translation)|
17
+ @locales.push locale
18
+ compare(locale, translation)
19
+ end
20
+
21
+ self
22
+ end
23
+
24
+ private
25
+
26
+ def compare(locale, translation, prefix = "")
27
+ if translation.is_a?(Hash)
28
+ translation.each do |(key, value)|
29
+ full_key = prefix + ".#{key}"
30
+ next if full_key.start_with?(*config.exclude)
31
+ compare(locale, value, full_key)
32
+ end
33
+ else
34
+ @data[prefix] ||= {}
35
+ @data[prefix][locale] = translation
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dry-initializer'
4
+ module Localer
5
+ # Core service object
6
+ class Service
7
+ extend Dry::Initializer # use `param` and `option` for dependencies
8
+
9
+ class << self
10
+ # Instantiates and calls the service at once
11
+ def call(*args, &block)
12
+ new(*args).call(&block)
13
+ end
14
+
15
+ # Accepts both symbolized and stringified attributes
16
+ def new(*args)
17
+ args << args.pop.symbolize_keys if args.last.is_a?(Hash)
18
+ super(*args)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Localer
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "localer/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "localer"
8
+ spec.version = Localer::VERSION
9
+ spec.authors = ["Andrey Deryabin"]
10
+ spec.email = ["deriabin@gmail.com"]
11
+
12
+ spec.summary = %q{Automatic detecting missing I18n translations tool.}
13
+ spec.description = %q{Automatic detecting missing I18n translations tool.}
14
+ spec.homepage = "https://github.com/aderyabin/localer"
15
+ spec.license = "MIT"
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "bin"
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "pry", "~> 0.11"
27
+ spec.add_development_dependency "rubocop", "~> 0.50"
28
+
29
+ spec.add_dependency "thor", "~> 0.20.0"
30
+ spec.add_dependency "dry-initializer", "~> 2.3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: localer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Deryabin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.50'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.50'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.20.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.20.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: dry-initializer
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.3.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.3.0
111
+ description: Automatic detecting missing I18n translations tool.
112
+ email:
113
+ - deriabin@gmail.com
114
+ executables:
115
+ - localer
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - ".travis.yml"
123
+ - CODE_OF_CONDUCT.md
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bin/localer
129
+ - lib/localer.rb
130
+ - lib/localer/checker.rb
131
+ - lib/localer/config.rb
132
+ - lib/localer/missing_translations.rb
133
+ - lib/localer/parser.rb
134
+ - lib/localer/service.rb
135
+ - lib/localer/version.rb
136
+ - localer.gemspec
137
+ homepage: https://github.com/aderyabin/localer
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.6.14
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Automatic detecting missing I18n translations tool.
161
+ test_files: []