localizator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +53 -0
- data/Rakefile +1 -0
- data/lib/localizator.rb +7 -0
- data/lib/localizator/helpers.rb +20 -0
- data/lib/localizator/version.rb +3 -0
- data/lib/tasks/localizator.rake +66 -0
- metadata +53 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Andrey Morskov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Localizator
|
2
|
+
|
3
|
+
This plugin provides two simple rake tasks to help keeping tranlations in
|
4
|
+
sync with the default locale.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'localizator'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install localizator
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Start creating a new locale with:
|
23
|
+
|
24
|
+
rake localizator:update[nl]
|
25
|
+
|
26
|
+
It will generate a new file in 'config/locales/nl-missing.yml' with the
|
27
|
+
keys in your default locale which need to be translated.
|
28
|
+
|
29
|
+
Open this file in your favourite text editor and translate it!
|
30
|
+
|
31
|
+
Once done you can merge the translatios into your main locale file
|
32
|
+
('config/locales/nl.yml') with:
|
33
|
+
|
34
|
+
rake localizator:merge[nl]
|
35
|
+
|
36
|
+
Since this is the first run, this will simply copy your translations to
|
37
|
+
the main locale file.
|
38
|
+
|
39
|
+
Now, every time you edit your main locale file you can run the samle update
|
40
|
+
task with:
|
41
|
+
|
42
|
+
rake localizator:update[nl]
|
43
|
+
|
44
|
+
Then translate the missing keys in your 'config/locales/nl-missing.yml'
|
45
|
+
file and merge them back into the main locale file.
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
1. Fork it
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
53
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/localizator.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Localizator
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
def self.locale_diff(a, b)
|
6
|
+
diff = {}
|
7
|
+
if b.nil? or (b.class != a.class)
|
8
|
+
return a
|
9
|
+
end
|
10
|
+
if a.is_a? Hash
|
11
|
+
a.keys.each do |key|
|
12
|
+
ret = locale_diff(a[key], b[key])
|
13
|
+
diff[key] = ret if !ret.empty?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
diff
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
namespace :localizator do
|
2
|
+
|
3
|
+
desc "Generate a YAML file with missing translations"
|
4
|
+
task :update, [:locale] => :environment do |t, args|
|
5
|
+
args.with_defaults(:locale => 'new_locale')
|
6
|
+
dl = I18n.default_locale.to_s
|
7
|
+
dl = "en"
|
8
|
+
tl = args[:locale]
|
9
|
+
filename = "#{Rails.root}/config/locales/#{tl}-missing.yml"
|
10
|
+
if File.exists?(filename)
|
11
|
+
puts "File 'config/locales/#{tl}-missing.yml' exists."
|
12
|
+
puts "Merge it first with 'rake localizer:merge[#{tl}]' or delete it"
|
13
|
+
else
|
14
|
+
translations = {}
|
15
|
+
I18n.load_path.each do |file|
|
16
|
+
if File.extname(file) == ".yml"
|
17
|
+
tree = YAML::parse(File.open(file))
|
18
|
+
translations.deep_merge!(tree.transform)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
missing_translations = {tl => Localizator::Helpers::locale_diff(translations[dl], translations[tl])}
|
22
|
+
if !missing_translations[tl].empty?
|
23
|
+
File.open(filename, 'w') do |f|
|
24
|
+
f.puts missing_translations.to_yaml
|
25
|
+
end
|
26
|
+
puts "Created 'config/locales/#{tl}-missing.yml' with missing translations."
|
27
|
+
puts "Edit and merge it back with 'rake localizer:merge[#{tl}]'"
|
28
|
+
else
|
29
|
+
puts "All keys in locale '#{dl}' are translated!"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Merge translations into main locale file"
|
35
|
+
task :merge , [:locale] => :environment do |t, args|
|
36
|
+
args.with_defaults(:locale => 'new_locale')
|
37
|
+
tl = args[:locale]
|
38
|
+
filename = "#{Rails.root}/config/locales/#{tl}-missing.yml"
|
39
|
+
if !File.exists?(filename)
|
40
|
+
puts "File 'config/locales/#{tl}-missing.yml' does not exist."
|
41
|
+
puts "Create it first with 'rake localizer:update[#{tl}]'"
|
42
|
+
else
|
43
|
+
translations = {}
|
44
|
+
I18n.load_path.each do |file|
|
45
|
+
if File.extname(file) == ".yml"
|
46
|
+
tree = YAML::parse(File.open(file))
|
47
|
+
translations.deep_merge!(tree.transform)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
final = {tl => translations[tl]}
|
51
|
+
base = "#{Rails.root}/config/locales/#{tl}.yml"
|
52
|
+
if File.exists?(base)
|
53
|
+
puts "Backing up 'config/locales/#{tl}.yml' to 'config/locales/#{tl}.yml.bak'..."
|
54
|
+
FileUtils.cp(base, "#{Rails.root}/config/locales/#{tl}.yml.bak")
|
55
|
+
end
|
56
|
+
File.open(base, 'w') do |f|
|
57
|
+
f.puts final.to_yaml
|
58
|
+
end
|
59
|
+
puts "Removing 'config/locales/#{tl}-missing.yml'..."
|
60
|
+
FileUtils.rm(filename)
|
61
|
+
puts "Created 'config/locales/#{tl}.yml' with merged translations."
|
62
|
+
puts "Please remove the backup file manually once you are satisfied with the results"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: localizator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Accessd
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email:
|
16
|
+
- accessd0@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/localizator.rb
|
22
|
+
- lib/tasks/localizator.rake
|
23
|
+
- lib/localizator/version.rb
|
24
|
+
- lib/localizator/helpers.rb
|
25
|
+
- MIT-LICENSE
|
26
|
+
- Rakefile
|
27
|
+
- README.md
|
28
|
+
homepage:
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.8.11
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: This plugin provides two simple rake tasks to help keeping tranlations in
|
52
|
+
sync with the default locale.
|
53
|
+
test_files: []
|