Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 99 lines (87 sloc) 2.973 kB
668347a @kuroda Created locales.thor
kuroda authored
1 require File.dirname(__FILE__) + '/rails/test/lib/key_structure.rb'
8086b9f @dmilisic added pluralizations check
dmilisic authored
2 $LOAD_PATH.unshift(File.dirname(__FILE__) + '/lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/lib')
668347a @kuroda Created locales.thor
kuroda authored
3
4 class Locales < Thor
5 desc 'test_all', 'Check formality of all locale files.'
6 def test_all
7 Dir.glob(File.dirname(__FILE__) + '/rails/locale/*.{rb,yml}') do |filename|
8 if md = filename.match(/([\w\-]+)\.(rb|yml)$/)
9 locale = md[1]
8086b9f @dmilisic added pluralizations check
dmilisic authored
10 missing_keys, broken_keys, missing_pluralizations = KeyStructure.check(locale)
11894b5 @kuroda Remove code for Rails 2 from locales.thor
kuroda authored
11 unless missing_keys.empty?
12 puts "[#{locale}] Some keys are missing."
668347a @kuroda Created locales.thor
kuroda authored
13 end
53289da @kuroda Added special treatment for (date|time).formats
kuroda authored
14 unless broken_keys.empty?
15 puts "[#{locale}] Some keys have broken data."
16 end
8086b9f @dmilisic added pluralizations check
dmilisic authored
17 unless missing_pluralizations.empty?
18 puts "[#{locale}] Some keys have missing pluralizations."
19 end
668347a @kuroda Created locales.thor
kuroda authored
20 end
21 end
22 end
23
24 desc 'test LOCALE', 'Check formality of a locale file.'
25 def test(locale)
26 good = true
8086b9f @dmilisic added pluralizations check
dmilisic authored
27
28 missing_keys, broken_keys, missing_pluralizations = KeyStructure.check(locale)
11894b5 @kuroda Remove code for Rails 2 from locales.thor
kuroda authored
29 unless missing_keys.empty?
30 puts "The following keys are missing."
31 missing_keys.each do |key|
32 puts " " + key
668347a @kuroda Created locales.thor
kuroda authored
33 end
11894b5 @kuroda Remove code for Rails 2 from locales.thor
kuroda authored
34 good = false
668347a @kuroda Created locales.thor
kuroda authored
35 end
36
53289da @kuroda Added special treatment for (date|time).formats
kuroda authored
37 unless broken_keys.empty?
38 puts "The following keys have broken data."
39 broken_keys.uniq.each do |key|
40 puts " " + key
41 end
42 good = false
43 end
44
8086b9f @dmilisic added pluralizations check
dmilisic authored
45 unless missing_pluralizations.empty?
46 puts "The following keys have missing pluralizations."
47 missing_pluralizations.uniq.each do |key|
48 puts " " + key
49 end
50 good = false
51 end
52
11894b5 @kuroda Remove code for Rails 2 from locales.thor
kuroda authored
53 puts "The structure is good." if good
668347a @kuroda Created locales.thor
kuroda authored
54 end
55
56 desc 'list', 'List locale names.'
57 def list
58 locales = []
59 Dir.glob(File.dirname(__FILE__) + '/rails/locale/*.{rb,yml}') do |filename|
60 if md = filename.match(/([\w\-]+)\.(rb|yml)$/)
61 locales << md[1]
62 end
63 end
64 puts locales.sort.join(', ')
65 end
66
11894b5 @kuroda Remove code for Rails 2 from locales.thor
kuroda authored
67 desc 'complete', 'List complete locales'
68 def complete
668347a @kuroda Created locales.thor
kuroda authored
69 locales = []
70 Dir.glob(File.dirname(__FILE__) + '/rails/locale/*.{rb,yml}') do |filename|
71 if md = filename.match(/([\w\-]+)\.(rb|yml)$/)
72 locale = md[1]
11894b5 @kuroda Remove code for Rails 2 from locales.thor
kuroda authored
73
8086b9f @dmilisic added pluralizations check
dmilisic authored
74 missing_keys, broken_keys, missing_pluralizations = KeyStructure.check(locale)
75 if missing_keys.empty? && broken_keys.empty? && missing_pluralizations.empty?
668347a @kuroda Created locales.thor
kuroda authored
76 locales << locale
77 end
78 end
79 end
80 puts locales.sort.join(', ')
81 end
3748a52 @kuroda Prepare locales.thor for Rails 4.0.0
kuroda authored
82
83 desc 'incomplete', 'List incomplete locales'
84 def incomplete
85 locales = []
86 Dir.glob(File.dirname(__FILE__) + '/rails/locale/*.{rb,yml}') do |filename|
87 if md = filename.match(/([\w\-]+)\.(rb|yml)$/)
88 locale = md[1]
89
90 missing_keys, broken_keys, missing_pluralizations = KeyStructure.check(locale)
91 unless missing_keys.empty? && broken_keys.empty? && missing_pluralizations.empty?
92 locales << locale
93 end
94 end
95 end
96 puts locales.sort.join(', ')
97 end
668347a @kuroda Created locales.thor
kuroda authored
98 end
Something went wrong with that request. Please try again.