makeloc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4fcd11ff72761200517025cb63581db71ed97ea7
4
+ data.tar.gz: ebf75b16d8a814599c35d72706a8a6fb10df8ed6
5
+ SHA512:
6
+ metadata.gz: 58b256266d23fc34528d513ce6cde0912df811c11b1369551b56d29a6bff0f351d6502398aac6ad680f77bbe749e7f1328bcdecb1cadeae6cd4e8d2c3f39adda
7
+ data.tar.gz: 76c9df4454baf93d219f189c868fec8cbd21861e77f6aa09fc7d45401109c9d4165ec7a0e262b9e8cb71528befd6de0c72b462f98d2d4f8be24fc63b6f044496
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ gem 'rails', '>= 2.2'
3
+
4
+ # Add dependencies to develop your gem here.
5
+ # Include everything needed to run rake, tests, features, etc.
6
+ group :development do
7
+ gem "rdoc", "~> 3.12"
8
+ gem "bundler", "~> 1.0"
9
+ gem "jeweler", "~> 2.0"
10
+ gem "simplecov", "~> 0.8"
11
+ gem "rspec", "~> 2.8"
12
+ gem "genspec", '~> 0.2'
13
+ gem "byebug", '~> 3.1'
14
+ end
15
+
data/Gemfile.lock ADDED
@@ -0,0 +1,156 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (4.1.1)
5
+ actionpack (= 4.1.1)
6
+ actionview (= 4.1.1)
7
+ mail (~> 2.5.4)
8
+ actionpack (4.1.1)
9
+ actionview (= 4.1.1)
10
+ activesupport (= 4.1.1)
11
+ rack (~> 1.5.2)
12
+ rack-test (~> 0.6.2)
13
+ actionview (4.1.1)
14
+ activesupport (= 4.1.1)
15
+ builder (~> 3.1)
16
+ erubis (~> 2.7.0)
17
+ activemodel (4.1.1)
18
+ activesupport (= 4.1.1)
19
+ builder (~> 3.1)
20
+ activerecord (4.1.1)
21
+ activemodel (= 4.1.1)
22
+ activesupport (= 4.1.1)
23
+ arel (~> 5.0.0)
24
+ activesupport (4.1.1)
25
+ i18n (~> 0.6, >= 0.6.9)
26
+ json (~> 1.7, >= 1.7.7)
27
+ minitest (~> 5.1)
28
+ thread_safe (~> 0.1)
29
+ tzinfo (~> 1.1)
30
+ addressable (2.3.6)
31
+ arel (5.0.1.20140414130214)
32
+ builder (3.2.2)
33
+ byebug (3.1.2)
34
+ columnize (~> 0.8)
35
+ debugger-linecache (~> 1.2)
36
+ columnize (0.8.9)
37
+ debugger-linecache (1.2.0)
38
+ descendants_tracker (0.0.4)
39
+ thread_safe (~> 0.3, >= 0.3.1)
40
+ diff-lcs (1.2.5)
41
+ docile (1.1.3)
42
+ erubis (2.7.0)
43
+ faraday (0.9.0)
44
+ multipart-post (>= 1.2, < 3)
45
+ genspec (0.2.8)
46
+ rspec (~> 2)
47
+ sc-core-ext (~> 1.2.1)
48
+ thor
49
+ git (1.2.6)
50
+ github_api (0.11.3)
51
+ addressable (~> 2.3)
52
+ descendants_tracker (~> 0.0.1)
53
+ faraday (~> 0.8, < 0.10)
54
+ hashie (>= 1.2)
55
+ multi_json (>= 1.7.5, < 2.0)
56
+ nokogiri (~> 1.6.0)
57
+ oauth2
58
+ hashie (3.0.0)
59
+ highline (1.6.21)
60
+ hike (1.2.3)
61
+ i18n (0.6.9)
62
+ jeweler (2.0.1)
63
+ builder
64
+ bundler (>= 1.0)
65
+ git (>= 1.2.5)
66
+ github_api
67
+ highline (>= 1.6.15)
68
+ nokogiri (>= 1.5.10)
69
+ rake
70
+ rdoc
71
+ json (1.8.1)
72
+ jwt (1.0.0)
73
+ mail (2.5.4)
74
+ mime-types (~> 1.16)
75
+ treetop (~> 1.4.8)
76
+ mime-types (1.25.1)
77
+ mini_portile (0.6.0)
78
+ minitest (5.3.4)
79
+ multi_json (1.10.1)
80
+ multi_xml (0.5.5)
81
+ multipart-post (2.0.0)
82
+ nokogiri (1.6.2.1)
83
+ mini_portile (= 0.6.0)
84
+ oauth2 (0.9.4)
85
+ faraday (>= 0.8, < 0.10)
86
+ jwt (~> 1.0)
87
+ multi_json (~> 1.3)
88
+ multi_xml (~> 0.5)
89
+ rack (~> 1.2)
90
+ polyglot (0.3.5)
91
+ rack (1.5.2)
92
+ rack-test (0.6.2)
93
+ rack (>= 1.0)
94
+ rails (4.1.1)
95
+ actionmailer (= 4.1.1)
96
+ actionpack (= 4.1.1)
97
+ actionview (= 4.1.1)
98
+ activemodel (= 4.1.1)
99
+ activerecord (= 4.1.1)
100
+ activesupport (= 4.1.1)
101
+ bundler (>= 1.3.0, < 2.0)
102
+ railties (= 4.1.1)
103
+ sprockets-rails (~> 2.0)
104
+ railties (4.1.1)
105
+ actionpack (= 4.1.1)
106
+ activesupport (= 4.1.1)
107
+ rake (>= 0.8.7)
108
+ thor (>= 0.18.1, < 2.0)
109
+ rake (10.3.2)
110
+ rdoc (3.12.2)
111
+ json (~> 1.4)
112
+ rspec (2.99.0)
113
+ rspec-core (~> 2.99.0)
114
+ rspec-expectations (~> 2.99.0)
115
+ rspec-mocks (~> 2.99.0)
116
+ rspec-core (2.99.0)
117
+ rspec-expectations (2.99.0)
118
+ diff-lcs (>= 1.1.3, < 2.0)
119
+ rspec-mocks (2.99.0)
120
+ sc-core-ext (1.2.1)
121
+ activesupport (>= 2.3.5)
122
+ simplecov (0.8.2)
123
+ docile (~> 1.1.0)
124
+ multi_json
125
+ simplecov-html (~> 0.8.0)
126
+ simplecov-html (0.8.0)
127
+ sprockets (2.12.1)
128
+ hike (~> 1.2)
129
+ multi_json (~> 1.0)
130
+ rack (~> 1.0)
131
+ tilt (~> 1.1, != 1.3.0)
132
+ sprockets-rails (2.1.3)
133
+ actionpack (>= 3.0)
134
+ activesupport (>= 3.0)
135
+ sprockets (~> 2.8)
136
+ thor (0.19.1)
137
+ thread_safe (0.3.4)
138
+ tilt (1.4.1)
139
+ treetop (1.4.15)
140
+ polyglot
141
+ polyglot (>= 0.3.1)
142
+ tzinfo (1.2.1)
143
+ thread_safe (~> 0.1)
144
+
145
+ PLATFORMS
146
+ ruby
147
+
148
+ DEPENDENCIES
149
+ bundler (~> 1.0)
150
+ byebug (~> 3.1)
151
+ genspec (~> 0.2)
152
+ jeweler (~> 2.0)
153
+ rails (>= 2.2)
154
+ rdoc (~> 3.12)
155
+ rspec (~> 2.8)
156
+ simplecov (~> 0.8)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 masciugo
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,28 @@
1
+ # Makeloc
2
+ A little generator to tidy locale file contents for Ruby On Rails
3
+
4
+ ## Idea
5
+ Makeloc comes from the necessity to update or create locale files while developing Ruby on Rails application. Often there is a reference language which get manually updated whenever necessary and later all the other locales should follow the same update steps. This last part could be very tedious and prone to errors or missings.
6
+
7
+ Makeloc, given a reference filepath (formatted as `path/to/file/context.reference_lang.yml`) and a target language, creates, in the same folder, a corresponding locale file `path/to/file/context.target_lang.yml` with same keys. If the target file already exists it gets updated. It actually get recreated with the same structure (same keys set) and then updated with old values. This means that keys in the old the target locale not present in the reference one will be wiped out after generation.
8
+
9
+ ## Installation
10
+ gem install makeloc
11
+
12
+ ## Usage
13
+ Makeloc is a generator. The following will create, or update if it exists, the file `config/locales/activerecord.it.yml`
14
+
15
+ rails g makeloc:do it config/locales/activerecord.en.yml
16
+
17
+
18
+ ## Test
19
+
20
+ rake spec
21
+
22
+ ## Contributing
23
+
24
+ Comments and feedback are welcome
25
+
26
+ ----
27
+ Copyright (c) 2014 masciugo. See LICENSE.txt for
28
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "makeloc"
18
+ gem.homepage = "http://github.com/masciugo/makeloc"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{A generator to updates, or creates if not exists, the locale file for the provided target language}
21
+ gem.description = %Q{}
22
+ gem.email = "masciugo@gmail.com"
23
+ gem.authors = ["masciugo"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ # RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ # spec.pattern = FileList['spec/**/*_spec.rb']
32
+ # end
33
+
34
+ RSpec::Core::RakeTask.new(:spec, :tag) do |t, task_args|
35
+ t.rspec_opts = "--format documentation --color"
36
+ t.rspec_opts += " --tag #{task_args[:tag]}" unless (task_args.nil? or task_args[:tag].nil?) #questo non va
37
+ end
38
+
39
+
40
+ desc "Code coverage detail"
41
+ task :simplecov do
42
+ ENV['COVERAGE'] = "true"
43
+ Rake::Task['spec'].execute
44
+ end
45
+
46
+ task :default => :spec
47
+
48
+ require 'rdoc/task'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "makeloc #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,65 @@
1
+ class Hash
2
+ def flatten_keys(prefix="")
3
+ keys = []
4
+ self.keys.each do |key|
5
+ keys << if self[key].is_a? Hash
6
+ current_prefix = prefix + "#{key}."
7
+ self[key].flatten_keys(current_prefix)
8
+ else
9
+ "#{prefix}#{key}"
10
+ end
11
+ end
12
+ prefix == "" ? keys.flatten : keys
13
+ end
14
+
15
+ def parse(only_leaves = false, &block)
16
+ each do |k,v|
17
+ if v.is_a? Hash
18
+ yield(k,v) unless only_leaves
19
+ v.parse(only_leaves,&block)
20
+ else
21
+ yield(k,v)
22
+ end
23
+ end
24
+ end
25
+
26
+ def parse_leaves(&block)
27
+ parse(only_leaves = true, &block)
28
+ end
29
+
30
+ def update_leaves!(&block)
31
+ each do |k,v|
32
+ if v.is_a? Hash
33
+ v.update_leaves!(&block)
34
+ else
35
+ self[k] = yield(k,v)
36
+ end
37
+ end
38
+ end
39
+
40
+ def at(path)
41
+ array_path = path.to_s.split('.')
42
+ current_key = array_path.shift
43
+ if array_path.empty?
44
+ self[current_key]
45
+ else
46
+ self[current_key].at(array_path.join('.'))
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ # hash = { a: 1, b: { d: 2, e: [3, 4] }, c: {f: 0, g: 3} }
53
+ # hash = {"date"=>{"abbr_day_names"=>["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"], "abbr_month_names"=>[nil, "Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"], "day_names"=>["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"], "formats"=>{"default"=>"%d-%m-%Y", "long"=>"%d %B %Y", "short"=>"%d %b"}, "month_names"=>[nil, "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"], "order"=>[:day, :month, :year]}, "datetime"=>{"distance_in_words"=>{"about_x_hours"=>{"one"=>"circa un'ora", "other"=>"circa %{count} ore"}, "about_x_months"=>{"one"=>"circa un mese", "other"=>"circa %{count} mesi"}, "about_x_years"=>{"one"=>"circa un anno", "other"=>"circa %{count} anni"}, "almost_x_years"=>{"one"=>"circa 1 anno", "other"=>"circa %{count} anni"}, "half_a_minute"=>"mezzo minuto", "less_than_x_minutes"=>{"one"=>"meno di un minuto", "other"=>"meno di %{count} minuti"}, "less_than_x_seconds"=>{"one"=>"meno di un secondo", "other"=>"meno di %{count} secondi"}, "over_x_years"=>{"one"=>"oltre un anno", "other"=>"oltre %{count} anni"}, "x_days"=>{"one"=>"1 giorno", "other"=>"%{count} giorni"}, "x_minutes"=>{"one"=>"1 minuto", "other"=>"%{count} minuti"}, "x_months"=>{"one"=>"1 mese", "other"=>"%{count} mesi"}, "x_seconds"=>{"one"=>"1 secondo", "other"=>"%{count} secondi"}}, "prompts"=>{"day"=>"Giorno", "hour"=>"Ora", "minute"=>"Minuto", "month"=>"Mese", "second"=>"Secondi", "year"=>"Anno"}}, "errors"=>{"format"=>"%{attribute} %{message}", "messages"=>{"accepted"=>"deve essere accettata", "blank"=>"non può essere lasciato in bianco", "confirmation"=>"non coincide con la conferma", "empty"=>"non può essere vuoto", "equal_to"=>"deve essere uguale a %{count}", "even"=>"deve essere pari", "exclusion"=>"è riservato", "greater_than"=>"deve essere superiore a %{count}", "greater_than_or_equal_to"=>"deve essere superiore o uguale a %{count}", "inclusion"=>"non è incluso nella lista", "invalid"=>"non è valido", "less_than"=>"deve essere meno di %{count}", "less_than_or_equal_to"=>"deve essere meno o uguale a %{count}", "not_a_number"=>"non è un numero", "not_an_integer"=>"non è un intero", "odd"=>"deve essere dispari", "record_invalid"=>"Validazione fallita: %{errors}", "taken"=>"è già in uso", "too_long"=>{"one"=>"è troppo lungo (il massimo è 1 carattere)", "other"=>"è troppo lungo (il massimo è %{count} caratteri)"}, "too_short"=>{"one"=>"è troppo corto (il minimo è 1 carattere)", "other"=>"è troppo corto (il minimo è %{count} caratteri)"}, "wrong_length"=>{"one"=>"è della lunghezza sbagliata (deve essere di 1 carattere)", "other"=>"è della lunghezza sbagliata (deve essere di %{count} caratteri)"}}, "template"=>{"body"=>"Per favore ricontrolla i seguenti campi:", "header"=>{"one"=>"Non posso salvare questo %{model}: 1 errore", "other"=>"Non posso salvare questo %{model}: %{count} errori."}}}, "helpers"=>{"select"=>{"prompt"=>"Per favore, seleziona", "prompt_allow_nil"=>"Per favore, seleziona o lascia in binaco"}, "submit"=>{"create"=>"Crea %{model}", "submit"=>"Invia %{model}", "update"=>"Aggiorna %{model}", "cancel"=>"Annulla %{model}", "reset"=>"Cancella %{model}", "add"=>"Aggiungi %{model}"}, "links"=>{"new"=>"Nuovo %{model}", "add"=>"Aggiungi %{model}", "edit"=>"Modifica %{model}", "reset"=>"Reset", "back"=>"Indietro", "cancel"=>"Annulla", "confirm"=>"Sei sicuro?", "destroy"=>"Elimina %{model}", "show"=>"Visualizza %{model}"}, "titles"=>{"index"=>"Lista %{model}", "edit"=>"Modifica %{model}", "new"=>"Nuovo %{model}", "show"=>"Riepilogo %{model}"}, "tooltips"=>{"edit"=>"Modifica %{model}", "save"=>"Salva %{model}", "new"=>"Crea %{model}", "destroy"=>"Elimina %{model}", "back"=>"Torna alla lista", "show"=>"Visualizza %{model}", "add"=>"Aggiungi %{model}"}}, "sign_out"=>"Esci", "sign_in"=>"Accedi", "number"=>{"currency"=>{"format"=>{"delimiter"=>",", "format"=>"%n %u", "precision"=>2, "separator"=>".", "significant"=>false, "strip_insignificant_zeros"=>false, "unit"=>"€"}}, "format"=>{"delimiter"=>",", "precision"=>2, "separator"=>".", "significant"=>false, "strip_insignificant_zeros"=>false}, "human"=>{"decimal_units"=>{"format"=>"%n %u", "units"=>{"billion"=>"Miliardi", "million"=>"Milioni", "quadrillion"=>"Biliardi", "thousand"=>"Mila", "trillion"=>"Bilioni", "unit"=>""}}, "format"=>{"delimiter"=>"", "precision"=>1, "significant"=>true, "strip_insignificant_zeros"=>true}, "storage_units"=>{"format"=>"%n %u", "units"=>{"byte"=>{"one"=>"Byte", "other"=>"Byte"}, "gb"=>"GB", "kb"=>"KB", "mb"=>"MB", "tb"=>"TB"}}}, "percentage"=>{"format"=>{"delimiter"=>""}}, "precision"=>{"format"=>{"delimiter"=>""}}}, "support"=>{"array"=>{"last_word_connector"=>" e ", "two_words_connector"=>" e ", "words_connector"=>", "}}, "time"=>{"am"=>"am", "formats"=>{"default"=>"%a %d %b %Y, %H:%M:%S %z", "long"=>"%d %B %Y %H:%M", "short"=>"%d %b %H:%M"}, "pm"=>"pm"}, "gender_suffix"=>{"M"=>"o", "F"=>"a"}, "activemodel"=>{"errors"=>{"format"=>"%{attribute} %{message}", "messages"=>{"accepted"=>"deve essere accettata", "blank"=>"non può essere lasciato in bianco", "confirmation"=>"non coincide con la conferma", "empty"=>"non può essere vuoto", "equal_to"=>"deve essere uguale a %{count}", "even"=>"deve essere pari", "exclusion"=>"è riservato", "greater_than"=>"deve essere superiore a %{count}", "greater_than_or_equal_to"=>"deve essere superiore o uguale a %{count}", "inclusion"=>"non è incluso nella lista", "invalid"=>"non è valido", "less_than"=>"deve essere meno di %{count}", "less_than_or_equal_to"=>"deve essere meno o uguale a %{count}", "not_a_number"=>"non è un numero", "not_an_integer"=>"non è un intero", "odd"=>"deve essere dispari", "record_invalid"=>"Validazione fallita: %{errors}", "taken"=>"è già in uso", "too_long"=>{"one"=>"è troppo lungo (il massimo è 1 carattere)", "other"=>"è troppo lungo (il massimo è %{count} caratteri)"}, "too_short"=>{"one"=>"è troppo corto (il minimo è 1 carattere)", "other"=>"è troppo corto (il minimo è %{count} caratteri)"}, "wrong_length"=>{"one"=>"è della lunghezza sbagliata (deve essere di 1 carattere)", "other"=>"è della lunghezza sbagliata (deve essere di %{count} caratteri)"}}, "template"=>{"body"=>"Per favore ricontrolla i seguenti campi:", "header"=>{"one"=>"Non posso salvare questo %{model}: 1 errore", "other"=>"Non posso salvare questo %{model}: %{count} errori."}}}}, "activerecord"=>{"errors"=>{"format"=>"%{attribute} %{message}", "messages"=>{"accepted"=>"deve essere accettata", "blank"=>"non può essere lasciato in bianco", "confirmation"=>"non coincide con la conferma", "empty"=>"non può essere vuoto", "equal_to"=>"deve essere uguale a %{count}", "even"=>"deve essere pari", "exclusion"=>"è riservato", "greater_than"=>"deve essere superiore a %{count}", "greater_than_or_equal_to"=>"deve essere superiore o uguale a %{count}", "inclusion"=>"non è incluso nella lista", "invalid"=>"non è valido", "less_than"=>"deve essere meno di %{count}", "less_than_or_equal_to"=>"deve essere meno o uguale a %{count}", "not_a_number"=>"non è un numero", "not_an_integer"=>"non è un intero", "odd"=>"deve essere dispari", "record_invalid"=>"Validazione fallita: %{errors}", "taken"=>"è già in uso", "too_long"=>{"one"=>"è troppo lungo (il massimo è 1 carattere)", "other"=>"è troppo lungo (il massimo è %{count} caratteri)"}, "too_short"=>{"one"=>"è troppo corto (il minimo è 1 carattere)", "other"=>"è troppo corto (il minimo è %{count} caratteri)"}, "wrong_length"=>{"one"=>"è della lunghezza sbagliata (deve essere di 1 carattere)", "other"=>"è della lunghezza sbagliata (deve essere di %{count} caratteri)"}}, "template"=>{"body"=>"Per favore ricontrolla i seguenti campi:", "header"=>{"one"=>"Non posso salvare questo %{model}: 1 errore", "other"=>"Non posso salvare questo %{model}: %{count} errori."}}}}}
54
+
55
+ # puts hash.at('date.day_names')
56
+
57
+ # hash.parse{|k,v| puts "#{k} => #{v}"}
58
+ # puts
59
+ # hash.parse_leaves{|k,v| puts "#{k} => #{v}"}
60
+ # puts
61
+ # hash.parse(true){|k,v| puts "#{k} => #{v}"}
62
+ # puts
63
+ # hash.update_leaves!{|k,v| nil }
64
+
65
+ # puts hash
@@ -0,0 +1,8 @@
1
+ Description:
2
+ A little generator to tidy locale file contents for Ruby On Rails
3
+
4
+ Example:
5
+ rails g makeloc:do it config/locales/activerecord.en.yml
6
+
7
+ This will create:
8
+ config/locales/activerecord.it.yml
@@ -0,0 +1,40 @@
1
+ require 'rails/generators'
2
+
3
+ module Makeloc
4
+ class DoGenerator < Rails::Generators::Base
5
+ desc "Updates, or creates if not exists, the locale file for the provided target language"
6
+
7
+ argument :target_lang, :type => :string
8
+ argument :source_file, :type => :string
9
+
10
+ def do
11
+ ref_locale_fp = Pathname.new(source_file)
12
+
13
+ raise "File #{ref_locale_fp} not found" unless ref_locale_fp.exist?
14
+
15
+ ref_lang = locale_fn2lang(ref_locale_fp)
16
+ ref_data = YAML.load(File.open(File.expand_path(ref_locale_fp)))[ref_lang]
17
+
18
+ target_fp = ref_locale_fp.to_s.gsub(".#{ref_lang}.",".#{target_lang}.")
19
+
20
+ # initializing target data with ref data keys and nil values
21
+ target_data = ref_data.deep_dup.update_leaves!{|k,v| nil }
22
+
23
+ # updating target data with original values if they exists
24
+ if File.exist? target_fp
25
+ existing_target_data = YAML.load(File.open(File.expand_path(target_fp)))[target_lang]
26
+ target_data.deep_merge!(existing_target_data) if existing_target_data
27
+ end
28
+
29
+ create_file(target_fp){ {target_lang => target_data}.to_yaml }
30
+
31
+ end
32
+
33
+ private
34
+
35
+ def locale_fn2lang(fn)
36
+ File.basename(fn,'.yml').split('.').last
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails/railtie'
2
+
3
+ module Makeloc
4
+ class Railtie < Rails::Railtie
5
+ generators do
6
+ require "makeloc/generators/do/do_generator"
7
+ end
8
+ end
9
+ end
data/lib/makeloc.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'makeloc/generators/do/do_generator'
2
+ require 'makeloc/railtie'
3
+ require 'makeloc/core_extensions'
4
+
5
+ module Makeloc
6
+
7
+ end
data/makeloc.gemspec ADDED
@@ -0,0 +1,80 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: makeloc 0.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "makeloc"
9
+ s.version = "0.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["masciugo"]
14
+ s.date = "2014-06-09"
15
+ s.description = ""
16
+ s.email = "masciugo@gmail.com"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/makeloc.rb",
30
+ "lib/makeloc/core_extensions.rb",
31
+ "lib/makeloc/generators/do/USAGE",
32
+ "lib/makeloc/generators/do/do_generator.rb",
33
+ "lib/makeloc/railtie.rb",
34
+ "makeloc.gemspec",
35
+ "spec/generators/test_generator_spec.rb",
36
+ "spec/generators/tmp/test.en.yml",
37
+ "spec/generators/tmp/test.en.yml.bk",
38
+ "spec/generators/tmp/test.it.yml",
39
+ "spec/generators/tmp/test_incomplete.en.yml.bk",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+ s.homepage = "http://github.com/masciugo/makeloc"
43
+ s.licenses = ["MIT"]
44
+ s.rubygems_version = "2.2.2"
45
+ s.summary = "A generator to updates, or creates if not exists, the locale file for the provided target language"
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 4
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<rails>, [">= 2.2"])
52
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
53
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
54
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
55
+ s.add_development_dependency(%q<simplecov>, ["~> 0.8"])
56
+ s.add_development_dependency(%q<rspec>, ["~> 2.8"])
57
+ s.add_development_dependency(%q<genspec>, ["~> 0.2"])
58
+ s.add_development_dependency(%q<byebug>, ["~> 3.1"])
59
+ else
60
+ s.add_dependency(%q<rails>, [">= 2.2"])
61
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
64
+ s.add_dependency(%q<simplecov>, ["~> 0.8"])
65
+ s.add_dependency(%q<rspec>, ["~> 2.8"])
66
+ s.add_dependency(%q<genspec>, ["~> 0.2"])
67
+ s.add_dependency(%q<byebug>, ["~> 3.1"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<rails>, [">= 2.2"])
71
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
72
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
73
+ s.add_dependency(%q<jeweler>, ["~> 2.0"])
74
+ s.add_dependency(%q<simplecov>, ["~> 0.8"])
75
+ s.add_dependency(%q<rspec>, ["~> 2.8"])
76
+ s.add_dependency(%q<genspec>, ["~> 0.2"])
77
+ s.add_dependency(%q<byebug>, ["~> 3.1"])
78
+ end
79
+ end
80
+
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ module Makeloc
4
+
5
+ describe DoGenerator do
6
+
7
+ with_args "en", REF_LANG_FP do
8
+ with_input "y\n" do
9
+
10
+ before(:each) do
11
+ FileUtils.rm TARGET_LANG_FP
12
+ end
13
+
14
+ # loaded once at beginning
15
+ let!(:ref_hash_with_root) { YAML.load(File.read(REF_LANG_FP)) }
16
+ let!(:ref_hash) { ref_hash_with_root[REF_LANG] }
17
+
18
+ # loaded at runtime after each generation
19
+ let(:target_hash_with_root) { YAML.load(File.read(TARGET_LANG_FP)) }
20
+ let(:target_hash) { target_hash_with_root[TARGET_LANG] }
21
+
22
+ shared_examples "a brand new generated locale file" do
23
+ it "should generate a #{TARGET_LANG_FP.basename} file in the same dir" do
24
+ File.exists? TARGET_LANG_FP
25
+ end
26
+ it "#{TARGET_LANG_FP.basename} hash has same structure as hash for #{REF_LANG_FP.basename}" do
27
+ ref_hash.flatten_keys.should eql(target_hash.flatten_keys)
28
+ end
29
+ it "#{TARGET_LANG_FP.basename} hash has '#{TARGET_LANG}' as root key" do
30
+ target_hash_with_root.keys.should ==([TARGET_LANG])
31
+ end
32
+ end
33
+
34
+ MISSING_KEYS = %w{ datetime.distance_in_words.about_x_hours.other date.abbr_day_names }
35
+ context "when #{TARGET_LANG_FP.basename} already exists with some missing keys (ie.: #{MISSING_KEYS.join(', ')})" do
36
+
37
+ # loaded once at beginning
38
+ let!(:incomplete_target_hash_with_root) { YAML.load(File.read(TARGET_INCOMPLETE_BK_FP)) }
39
+ let!(:incomplete_target_hash) { incomplete_target_hash_with_root[TARGET_LANG] }
40
+
41
+ before(:each) do
42
+ FileUtils.cp TARGET_INCOMPLETE_BK_FP, TARGET_LANG_FP
43
+ subject.should generate
44
+ end
45
+ it_should_behave_like "a brand new generated locale file"
46
+
47
+ MISSING_KEYS.each do |key|
48
+ it "value at '#{key}' is nil" do
49
+ target_hash.at(key).should be_nil
50
+ end
51
+ end
52
+ it "keeps old values (value at 'date.abbr_month_names' is in lang #{TARGET_LANG})" do
53
+ target_hash.at('date.abbr_month_names').should ==(incomplete_target_hash.at('date.abbr_month_names'))
54
+ end
55
+ end
56
+
57
+ context "when #{TARGET_LANG_FP.basename} doesn't exist" do
58
+ before(:each) do
59
+ subject.should generate
60
+ end
61
+ it_should_behave_like "a brand new generated locale file"
62
+ it "gets created with nil leaves" do
63
+ all_values = []
64
+ target_hash.parse_leaves{|k,v| all_values << v }
65
+ all_values.compact.should be_empty
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end