Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 125 lines (114 sloc) 3.716 kb
668347a @kuroda Created locales.thor
kuroda authored
1 require File.dirname(__FILE__) + '/rails/test/lib/key_structure.rb'
2
3 class Locales < Thor
4 desc 'test_all', 'Check formality of all locale files.'
5 def test_all
6 Dir.glob(File.dirname(__FILE__) + '/rails/locale/*.{rb,yml}') do |filename|
7 if md = filename.match(/([\w\-]+)\.(rb|yml)$/)
8 locale = md[1]
53289da @kuroda Added special treatment for (date|time).formats
kuroda authored
9 broken_keys = []
668347a @kuroda Created locales.thor
kuroda authored
10 [2, 3].each do |version|
53289da @kuroda Added special treatment for (date|time).formats
kuroda authored
11 missing_keys, keys = KeyStructure.check(locale, version)
12 broken_keys += keys
13 unless missing_keys.empty?
668347a @kuroda Created locales.thor
kuroda authored
14 puts "[#{locale}] Some keys are missing for Rails #{version}."
15 end
16 end
53289da @kuroda Added special treatment for (date|time).formats
kuroda authored
17 unless broken_keys.empty?
18 puts "[#{locale}] Some keys have broken data."
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
53289da @kuroda Added special treatment for (date|time).formats
kuroda authored
27 broken_keys = []
28
668347a @kuroda Created locales.thor
kuroda authored
29 [2, 3].each do |version|
53289da @kuroda Added special treatment for (date|time).formats
kuroda authored
30 missing_keys, keys = KeyStructure.check(locale, version)
31 broken_keys += keys
668347a @kuroda Created locales.thor
kuroda authored
32 unless missing_keys.empty?
33 puts "The following keys are missing for Rails #{version}."
34 missing_keys.each do |key|
35 puts " " + key
36 end
37 good = false
38 end
39 end
40
53289da @kuroda Added special treatment for (date|time).formats
kuroda authored
41 unless broken_keys.empty?
42 puts "The following keys have broken data."
43 broken_keys.uniq.each do |key|
44 puts " " + key
45 end
46 good = false
47 end
48
668347a @kuroda Created locales.thor
kuroda authored
49 puts "The structure is good for Rails 2 and 3." if good
50 end
51
52 desc 'list', 'List locale names.'
53 def list
54 locales = []
55 Dir.glob(File.dirname(__FILE__) + '/rails/locale/*.{rb,yml}') do |filename|
56 if md = filename.match(/([\w\-]+)\.(rb|yml)$/)
57 locales << md[1]
58 end
59 end
60 puts locales.sort.join(', ')
61 end
62
63 desc 'ready', 'List locales ready for Rails 2 and 3.'
64 def ready
65 locales = []
66 Dir.glob(File.dirname(__FILE__) + '/rails/locale/*.{rb,yml}') do |filename|
67 if md = filename.match(/([\w\-]+)\.(rb|yml)$/)
68 locale = md[1]
53289da @kuroda Added special treatment for (date|time).formats
kuroda authored
69 if [2, 3].all? { |version|
70 missing_keys, broken_keys = KeyStructure.check(locale, version)
71 missing_keys.empty? && broken_keys.empty? }
668347a @kuroda Created locales.thor
kuroda authored
72 locales << locale
73 end
74 end
75 end
76 puts locales.sort.join(', ')
77 end
78
79 desc 'ready_for VERSION', 'List locales ready for a VERSION of Rails.'
80 def ready_for(version)
81 locales = []
82 Dir.glob(File.dirname(__FILE__) + '/rails/locale/*.{rb,yml}') do |filename|
83 if md = filename.match(/([\w\-]+)\.(rb|yml)$/)
84 locale = md[1]
53289da @kuroda Added special treatment for (date|time).formats
kuroda authored
85 missing_keys, broken_keys = KeyStructure.check(locale, version)
86 if missing_keys.empty? && broken_keys.empty?
668347a @kuroda Created locales.thor
kuroda authored
87 locales << locale
88 end
89 end
90 end
91 puts locales.sort.join(', ')
e4449e5 Added a method to copy all rails 3 ready translations to a folder
Robert Bjarnason authored
92 locales.sort
93 end
94
511b47a Added function to show you what locales are not ready for a given versio...
Robert Bjarnason authored
95 desc 'not_ready_for VERSION', 'List locales not ready for a VERSION of Rails.'
96 def not_ready_for(version)
97 locales = []
98 Dir.glob(File.dirname(__FILE__) + '/rails/locale/*.{rb,yml}') do |filename|
99 if md = filename.match(/([\w\-]+)\.(rb|yml)$/)
100 locale = md[1]
101 missing_keys, broken_keys = KeyStructure.check(locale, version)
102 if not missing_keys.empty? or not broken_keys.empty?
103 locales << locale
104 end
105 end
106 end
107 puts locales.sort.join(', ')
108 locales.sort
109 end
110
e4449e5 Added a method to copy all rails 3 ready translations to a folder
Robert Bjarnason authored
111 desc 'copy_rails3_ready_to FOLDER','Copy rails 3 ready locales to a folder'
112 def copy_rails3_ready_to(folder)
113 puts "Folder #{folder}"
114 ready_for(3).each do |locale|
115 if locale=="th"
116 cmd = "cp #{File.dirname(__FILE__) + '/rails/locale/' + locale + '.rb'} #{folder}"
117 else
118 cmd = "cp #{File.dirname(__FILE__) + '/rails/locale/' + locale + '.yml'} #{folder}"
119 end
120 puts cmd
121 system cmd
122 end
668347a @kuroda Created locales.thor
kuroda authored
123 end
124 end
Something went wrong with that request. Please try again.