rails_locale_sorter 0.0.8 → 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.
- data/README.md +31 -7
- data/bin/locale_apply +1 -1
- data/bin/locale_patch +20 -5
- data/bin/poop +20 -5
- data/bin/scoop +1 -1
- data/lib/rails_locale_sorter.rb +11 -5
- data/lib/rails_locale_sorter/version.rb +1 -1
- data/spec/rls-spec.rb +13 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Rails Locale Sorter
|
2
2
|
===================
|
3
|
-
This is a small utility to assist in
|
3
|
+
This is a small utility to assist in handling your I18n YAML files in a Ruby on Rails project.
|
4
4
|
|
5
5
|
Installation
|
6
6
|
============
|
@@ -8,13 +8,37 @@ Installation
|
|
8
8
|
$ gem install rails_locale_sorter
|
9
9
|
```
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
Creating/Applying Patches
|
12
|
+
=========================
|
13
|
+
To create a patch, just provide input and output directories, and a "source of truth" locale that will be the template for the other languages.
|
14
14
|
|
15
|
-
|
15
|
+
```
|
16
|
+
$ locale_patch path/to/locales path/to/output en.yml
|
17
|
+
```
|
18
|
+
|
19
|
+
The output directory will now contain a list of YAML files containing missing translations.
|
20
|
+
|
21
|
+
Once the strings have been translated, they can be applied back into your project:
|
22
|
+
|
23
|
+
```
|
24
|
+
$ locale_apply path/to/translated_patches path/to/locales
|
25
|
+
```
|
26
|
+
The patching process also sorts the file's content alphabetically.
|
27
|
+
|
28
|
+
Defaults
|
29
|
+
========
|
30
|
+
These commands default to "locales/", "new-locales/", and "en.yml". Meaning that all you need to do to run through the entire process is:
|
31
|
+
|
32
|
+
```
|
33
|
+
$ cd my_rails_app/config
|
34
|
+
$ locale_patch
|
35
|
+
$ locale_apply
|
36
|
+
```
|
37
|
+
|
38
|
+
Or use the handy, descriptive aliases:
|
16
39
|
|
17
|
-
It defaults to english as the base language; you can change it by passing in a parameter.
|
18
40
|
```
|
19
|
-
$
|
41
|
+
$ cd my_rails_app/config
|
42
|
+
$ poop
|
43
|
+
$ scoop
|
20
44
|
```
|
data/bin/locale_apply
CHANGED
data/bin/locale_patch
CHANGED
@@ -1,11 +1,26 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
2
3
|
require 'rails_locale_sorter'
|
4
|
+
require 'optparse'
|
3
5
|
|
4
|
-
|
6
|
+
options = { :filter => [] }
|
7
|
+
optparse = OptionParser.new do |o|
|
8
|
+
o.banner = "Usage: locale_patch [source-path] [out-path] [default-language]\n\n\n"
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
10
|
+
o.separator "Options:"
|
11
|
+
|
12
|
+
o.on('-i', '--ignore x,y,z', 'Ignore a locale section by name') do |filt|
|
13
|
+
options[:filter].concat filt.split(",")
|
14
|
+
end
|
15
|
+
|
16
|
+
puts o
|
17
|
+
end
|
18
|
+
|
19
|
+
optparse.parse!
|
20
|
+
|
21
|
+
source_dir = ARGV.shift || "locales"
|
22
|
+
out_dir = ARGV.shift || "new-locales"
|
23
|
+
truth_locale = ARGV.shift || "en.yml"
|
9
24
|
|
10
25
|
lm = RailsLocaleSorter::LocaleManager.new source_dir, out_dir
|
11
|
-
lm.create_patches truth_locale
|
26
|
+
lm.create_patches truth_locale, options[:filter]
|
data/bin/poop
CHANGED
@@ -1,11 +1,26 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
2
3
|
require 'rails_locale_sorter'
|
4
|
+
require 'optparse'
|
3
5
|
|
4
|
-
|
6
|
+
options = { :filter => [] }
|
7
|
+
optparse = OptionParser.new do |o|
|
8
|
+
o.banner = "Usage: locale_patch [source-path] [out-path] [default-language]\n\n\n"
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
10
|
+
o.separator "Options:"
|
11
|
+
|
12
|
+
o.on('-i', '--ignore x,y,z', 'Ignore a locale section by name') do |filt|
|
13
|
+
options[:filter].concat filt.split(",")
|
14
|
+
end
|
15
|
+
|
16
|
+
puts o
|
17
|
+
end
|
18
|
+
|
19
|
+
optparse.parse!
|
20
|
+
|
21
|
+
source_dir = ARGV.shift || "locales"
|
22
|
+
out_dir = ARGV.shift || "new-locales"
|
23
|
+
truth_locale = ARGV.shift || "en.yml"
|
9
24
|
|
10
25
|
lm = RailsLocaleSorter::LocaleManager.new source_dir, out_dir
|
11
|
-
lm.create_patches truth_locale
|
26
|
+
lm.create_patches truth_locale, options[:filter]
|
data/bin/scoop
CHANGED
data/lib/rails_locale_sorter.rb
CHANGED
@@ -60,7 +60,7 @@ module RailsLocaleSorter
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
def create_patches(truth = "en.yml")
|
63
|
+
def create_patches(truth = "en.yml", filters = [])
|
64
64
|
translations = YAML::load_file("#{@source}/#{truth}")
|
65
65
|
|
66
66
|
process_each_file do |hash, file, filename|
|
@@ -68,7 +68,7 @@ module RailsLocaleSorter
|
|
68
68
|
hash = list_missing_keys(translations, hash)
|
69
69
|
end
|
70
70
|
|
71
|
-
sort_and_write(filename, hash)
|
71
|
+
sort_and_write(filename, hash, filters)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -108,18 +108,24 @@ module RailsLocaleSorter
|
|
108
108
|
def process_each_file(&block)
|
109
109
|
# for ya2yaml
|
110
110
|
$KCODE="UTF8"
|
111
|
-
|
111
|
+
|
112
|
+
puts 'Processing...'
|
113
|
+
|
112
114
|
with_each_file do |f, filename|
|
113
|
-
|
115
|
+
print " #{filename.split('.').first} "
|
116
|
+
STDOUT.flush
|
114
117
|
hash = YAML::load(f)
|
115
118
|
|
116
119
|
block.call(hash, f, filename)
|
117
120
|
end
|
121
|
+
puts "Done!"
|
118
122
|
end
|
119
123
|
|
120
|
-
def sort_and_write(filename, hash)
|
124
|
+
def sort_and_write(filename, hash, filters = [])
|
121
125
|
hash = OrderFact.convert_and_sort(hash, true)
|
122
126
|
|
127
|
+
filters.each { |filt| hash.first.last.delete(filt) }
|
128
|
+
|
123
129
|
File.open("#{@out}/#{filename}", "w+") do |fw|
|
124
130
|
fw.puts hash.ya2yaml(:syck_compatible => true)
|
125
131
|
end
|
data/spec/rls-spec.rb
CHANGED
@@ -44,6 +44,19 @@ describe RailsLocaleSorter::LocaleManager do
|
|
44
44
|
result.should_not include "both: Both"
|
45
45
|
result.should_not include "exotic: 下一页!След"
|
46
46
|
end
|
47
|
+
|
48
|
+
it "allows for filtering of sections" do
|
49
|
+
@lm.create_patches "src.yml", "date"
|
50
|
+
|
51
|
+
result = File.open("#{OUT_DIR}/out.yml").read
|
52
|
+
result.should include "out:"
|
53
|
+
result.should include "text:"
|
54
|
+
result.should include "source_only: "
|
55
|
+
result.should_not include "date:"
|
56
|
+
result.should_not include "src_only: "
|
57
|
+
result.should_not include "both: Both"
|
58
|
+
result.should_not include "exotic: 下一页!След"
|
59
|
+
end
|
47
60
|
end
|
48
61
|
|
49
62
|
describe "poop and scoop" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_locale_sorter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.8
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Wheeler
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-03-
|
18
|
+
date: 2012-03-24 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|