gettext_simple_rails 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d32df11d74af532fb2c84cb336247c20138b87e2
|
4
|
+
data.tar.gz: 083309a6b599a2e26a9385c765a36cba64ad5dbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a68feeab623f9daabf34f2590a558cb30fc39e211a560c6836a1a6b2d1223a540f101da42882ae01963b10965d8c064d09256a6c8e50c6571b535c92b902ad5
|
7
|
+
data.tar.gz: a4f95ac5eba636e6a364fdd62487d0f73ef074337c1940bb15ddca54dd60845f47dc87a20a45efdcc0ec41b7e434a826d326b1a0a3da9874bbc5e13d9b42e6cd
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class GettextSimpleRails::Translators::ActiveRecordTranslator
|
2
|
+
def detected?
|
3
|
+
true
|
4
|
+
end
|
5
|
+
|
6
|
+
def translations
|
7
|
+
return {
|
8
|
+
"activerecord" => {
|
9
|
+
"errors" => {
|
10
|
+
"messages" => {
|
11
|
+
"record_invalid" => "Invalid record"
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
@@ -4,6 +4,33 @@ class GettextSimpleRails::Translators::DeviseTranslator
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def translations
|
7
|
-
|
7
|
+
devise_gem_path = Gem.loaded_specs['devise'].full_gem_path
|
8
|
+
devise_yml_translation_file = "#{devise_gem_path}/config/locales/en.yml"
|
9
|
+
translations = YAML.load(File.read(devise_yml_translation_file))
|
10
|
+
|
11
|
+
# Add failure translations for all devise models.
|
12
|
+
devise_models.each do |clazz|
|
13
|
+
translations["en"]["devise"]["failure"][StringCases.camel_to_snake(clazz.name)] = translations["en"]["devise"]["failure"].clone
|
14
|
+
end
|
15
|
+
|
16
|
+
return translations["en"]
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def devise_models
|
22
|
+
classes = []
|
23
|
+
|
24
|
+
::Rails.application.eager_load!
|
25
|
+
|
26
|
+
::Object.constants.each do |clazz|
|
27
|
+
clazz = clazz.to_s.constantize
|
28
|
+
next unless clazz.class == Class
|
29
|
+
next unless clazz < ActiveRecord::Base
|
30
|
+
next unless clazz.respond_to?(:devise_modules)
|
31
|
+
classes << clazz
|
32
|
+
end
|
33
|
+
|
34
|
+
return classes
|
8
35
|
end
|
9
36
|
end
|
data/lib/gettext_simple_rails.rb
CHANGED
@@ -12,11 +12,11 @@ module GettextSimpleRails
|
|
12
12
|
return "#{Rails.root}/lib/gettext_simple_rails"
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.write_recursive_translations(fp, translations, pre_path = [])
|
15
|
+
def self.write_recursive_translations(fp, translations, pre_path = [], args = {})
|
16
16
|
if translations.is_a?(Hash)
|
17
17
|
translations.each do |key, val|
|
18
18
|
newpath = pre_path + [key]
|
19
|
-
write_recursive_translations(fp, val, newpath)
|
19
|
+
write_recursive_translations(fp, val, newpath, :comment => "Default value: #{val}")
|
20
20
|
end
|
21
21
|
elsif translations.is_a?(Array)
|
22
22
|
translations.each do |val|
|
@@ -24,6 +24,12 @@ module GettextSimpleRails
|
|
24
24
|
write_recursive_translations(fp, val, newpath)
|
25
25
|
end
|
26
26
|
elsif translations.is_a?(String) || translations.is_a?(Fixnum)
|
27
|
+
if args[:comment]
|
28
|
+
args[:comment].to_s.each_line do |line|
|
29
|
+
fp.puts " #. #{line}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
27
33
|
fp.puts " _('#{pre_path.join(".")}')"
|
28
34
|
else
|
29
35
|
raise "Unknownt class: '#{translations.class.name}'."
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gettext_simple_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Johansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/gettext_simple_rails/model_inspector.rb
|
101
101
|
- lib/gettext_simple_rails/translators/simple_form_translator.rb
|
102
102
|
- lib/gettext_simple_rails/translators/active_admin_translator.rb
|
103
|
+
- lib/gettext_simple_rails/translators/active_record_translator.rb
|
103
104
|
- lib/gettext_simple_rails/translators/devise_translator.rb
|
104
105
|
- lib/gettext_simple_rails/translators/date_translator.rb
|
105
106
|
- lib/gettext_simple_rails.rb
|