the_alive_locales 0.0.1

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: e22bfed04acaead89acaf32116624d40526153b8
4
+ data.tar.gz: fb84f87b6166236b37f49f5f39238d6a26371f92
5
+ SHA512:
6
+ metadata.gz: 886e731c8a10787545709cfe98b05267f3bf9f896ec13195813e63b335333a007423b827ab4ae6649a19ef72e22c1a671522cb1e6c79953a0114fab6840c8e72
7
+ data.tar.gz: 85232140ec38ca99fb95f14edcd18aa3bd54494af3f89cf072d9bd01ad7dea912f99b89fd30536fd3a0c52987e836fbdb0f0d3138b1273c547ef8968f7642ea0
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in the_alive_locales.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ilya N. Zykin
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,29 @@
1
+ ## TheAliveLocales
2
+
3
+ Way to find and log alive localization keys into your i18n locale files
4
+
5
+ This gem collect all executed `I18n.translate` and `I18n.t` calls and dump it into YAML file at
6
+ `#{Rails.root}/log/`
7
+
8
+ ### Installation
9
+
10
+ ```ruby
11
+ group :development do
12
+ gem 'the_alive_locales', '~> 0.0.1'
13
+ end
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```sh
19
+ bundle
20
+ ```
21
+
22
+ ### Usage
23
+
24
+ 1. Install gem
25
+ 2. exec `rails s`
26
+ 2. Visit required pages with required locales
27
+ 3. Learn `/log/alive_locale.LOCALE_NAME.yml`
28
+
29
+ #### MIT license
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/gem_version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module TheAliveLocales
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ require "the_alive_locales/version"
2
+
3
+ module TheAliveLocales
4
+ class Engine < ::Rails::Engine
5
+ config.after_initialize do
6
+ require "the_alive_locales/i18n_patch"
7
+ end
8
+ end
9
+
10
+ def self.log_path locale
11
+ "#{ Rails.root }/log/alive_locale.#{ locale }.yml"
12
+ end
13
+
14
+ def self.dump locale, path, value
15
+ # Create alive file if not exists
16
+ log_path = self.log_path(locale)
17
+ File.open(log_path, 'w+').close unless File.exists? log_path
18
+
19
+ # Open and read alive locale file
20
+ i18n_log = File.open(log_path, "r")
21
+ log_content = i18n_log.read
22
+ i18n_log.close
23
+
24
+ # Read YAML
25
+ # Create { 'en' => {} } if exception
26
+ locale_data = (begin; YAML.load(log_content); rescue; {}; end) || {}
27
+ locale_data[locale] = {} unless locale_data[locale]
28
+
29
+ # Set base values
30
+ path_size = path.size - 1
31
+ current_level = locale_data[locale]
32
+
33
+ # Set base values
34
+ path.each_with_index do |v, i|
35
+ _value = (path_size == i) ? value : {}
36
+ current_level[v.to_s] = _value unless current_level[v.to_s]
37
+ current_level = current_level[v.to_s]
38
+ end
39
+
40
+ # Open alive locale file and write
41
+ i18n_log = File.open(log_path, 'w')
42
+ i18n_log.write locale_data.to_yaml
43
+ i18n_log.close
44
+ end
45
+ end
@@ -0,0 +1,18 @@
1
+ module I18n
2
+ class << self
3
+ def translate(*args)
4
+ tname = args.try :[], 0
5
+ _args = args.try :[], 1
6
+ scope = Array.wrap _args.try(:[],:scope) || _args.try(:[], 'scope')
7
+
8
+ key = [ scope, tname ].flatten
9
+ value = super
10
+
11
+ TheAliveLocales.dump(locale.to_s, key, value)
12
+
13
+ value
14
+ end
15
+
16
+ alias_method :t, :translate
17
+ end
18
+ end
@@ -0,0 +1 @@
1
+ require_relative '../../gem_version.rb'
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'the_alive_locales/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "the_alive_locales"
8
+ spec.version = TheAliveLocales::VERSION
9
+ spec.authors = ["Ilya N. Zykin"]
10
+ spec.email = ["zykin-ilya@ya.ru"]
11
+ spec.summary = %q{Alive locales logger}
12
+ spec.description = %q{Find required locales keys}
13
+ spec.homepage = "https://github.com/the-teacher/the_alive_locales"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rails", "~> 3.0.0"
24
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_alive_locales
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ilya N. Zykin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-03 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.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.0
55
+ description: Find required locales keys
56
+ email:
57
+ - zykin-ilya@ya.ru
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - gem_version.rb
68
+ - lib/the_alive_locales.rb
69
+ - lib/the_alive_locales/i18n_patch.rb
70
+ - lib/the_alive_locales/version.rb
71
+ - the_alive_locales.gemspec
72
+ homepage: https://github.com/the-teacher/the_alive_locales
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Alive locales logger
96
+ test_files: []