i18n_scopes 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/i18n_scopes/scope.rb +2 -2
- data/lib/i18n_scopes/translation_helper.rb +1 -0
- data/lib/i18n_scopes/translation_methods.rb +0 -1
- data/lib/i18n_scopes/translation_utils.rb +4 -7
- data/lib/i18n_scopes/version.rb +1 -1
- data/spec/example_classes/scope_t_with_path.rb +1 -1
- data/spec/example_classes/translate_without_controller_suffix.rb +15 -0
- data/spec/locales/en.yml +3 -1
- data/spec/should_translate_without_controller_name_spec.rb +9 -0
- metadata +6 -2
data/README.md
CHANGED
@@ -30,7 +30,7 @@ Or install it yourself as:
|
|
30
30
|
### In your class (for example Controller)
|
31
31
|
|
32
32
|
class Local::ExampleController < ActionController::Base
|
33
|
-
i18n_default_scope :class_name, :translation, :action_name, :strip_controller_suffix => true, :
|
33
|
+
i18n_default_scope :class_name, :translation, :action_name, :strip_controller_suffix => true, :plural_classes => false
|
34
34
|
i18n_scope :flash, :class_name, :action_name, :flashes
|
35
35
|
|
36
36
|
def index
|
data/lib/i18n_scopes/scope.rb
CHANGED
@@ -24,11 +24,11 @@ module I18nScopes
|
|
24
24
|
# === Params:
|
25
25
|
# * +path+: Either a single String or Symbol, or an Array of Symbols and Strings
|
26
26
|
# * +options+: options to be used within this class, they will overwrite the configuration made in Configuration
|
27
|
-
# * :
|
27
|
+
# * :plural_classes: if the class name should be pluralized or singularized
|
28
28
|
# * :strip_controller_suffix: if the _controller suffix of classes should be stripped or not
|
29
29
|
#
|
30
30
|
# == Usage:
|
31
|
-
# i18n_scope :flash, :modules, :class_name, :action_name, :custom_value, "static_prefix", :
|
31
|
+
# i18n_scope :flash, :modules, :class_name, :action_name, :custom_value, "static_prefix", :plural_classes => true, :strip_controller_suffix => true
|
32
32
|
#
|
33
33
|
# this will create a +t_flash+ method
|
34
34
|
#
|
@@ -29,6 +29,7 @@ module I18nScopes
|
|
29
29
|
respondables = [object]
|
30
30
|
respondables += [*options.delete(:respondable)] if options.include?(:respondable)
|
31
31
|
respondables << I18nScopes::TranslationUtils # add utils at last
|
32
|
+
parameter_matchings[:options] = self.options.merge(parameter_matchings[:options]) # merge options
|
32
33
|
custom_path.each do |path_name|
|
33
34
|
if path_name.is_a?(Symbol)
|
34
35
|
# find a respondable which responds_to path_name
|
@@ -2,8 +2,6 @@ module I18nScopes
|
|
2
2
|
|
3
3
|
module TranslationUtils
|
4
4
|
|
5
|
-
CONTROLLER_SUFFIX = "_controller"
|
6
|
-
|
7
5
|
# this method will return all modules in a array, each module will be underscored
|
8
6
|
#
|
9
7
|
# === Params:
|
@@ -16,20 +14,19 @@ module I18nScopes
|
|
16
14
|
|
17
15
|
# this method will return a underscored class_name
|
18
16
|
#
|
19
|
-
# Note:
|
17
|
+
# Note: plural_classes and strip_controller_suffix will be used here
|
20
18
|
#
|
21
19
|
# === Params:
|
22
20
|
# * +klass+: the class on which the name should be get
|
23
|
-
# * +options+: options like
|
21
|
+
# * +options+: options like plural_classes and strip_controller_suffix
|
24
22
|
def self.class_name(klass, options = {})
|
25
|
-
|
26
|
-
class_name = if class_name_options[:strip_controller_suffix] && klass.respond_to?(:controller_name)
|
23
|
+
class_name = if options[:strip_controller_suffix] && klass.respond_to?(:controller_name)
|
27
24
|
klass.controller_name
|
28
25
|
else
|
29
26
|
demodulized = ActiveSupport::Inflector.demodulize(klass.name)
|
30
27
|
ActiveSupport::Inflector.underscore(demodulized)
|
31
28
|
end
|
32
|
-
if
|
29
|
+
if options[:plural_classes]
|
33
30
|
ActiveSupport::Inflector.pluralize(class_name)
|
34
31
|
else
|
35
32
|
ActiveSupport::Inflector.singularize(class_name)
|
data/lib/i18n_scopes/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
class TranslateWithoutControllerSuffix
|
2
|
+
|
3
|
+
include I18nScopes::Scope
|
4
|
+
|
5
|
+
i18n_scope :controller_name, :class_name, strip_controller_suffix: true, plural_classes: false
|
6
|
+
|
7
|
+
def translate
|
8
|
+
t_controller_name(:name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.controller_name
|
12
|
+
"scopes"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/spec/locales/en.yml
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_scopes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- spec/example_classes/scope_t_with_path_in_module.rb
|
58
58
|
- spec/example_classes/should_define_scope.rb
|
59
59
|
- spec/example_classes/should_have_attached_scoped_t.rb
|
60
|
+
- spec/example_classes/translate_without_controller_suffix.rb
|
60
61
|
- spec/include_scope_spec.rb
|
61
62
|
- spec/inherit_from_parent_spec.rb
|
62
63
|
- spec/inherited_spec.rb
|
@@ -64,6 +65,7 @@ files:
|
|
64
65
|
- spec/scope_spec.rb
|
65
66
|
- spec/should_define_scope_in_module_spec.rb
|
66
67
|
- spec/should_define_scope_spec.rb
|
68
|
+
- spec/should_translate_without_controller_name_spec.rb
|
67
69
|
- spec/spec_helper.rb
|
68
70
|
homepage: http://github.com/menostos/i18n_scopes
|
69
71
|
licenses: []
|
@@ -99,6 +101,7 @@ test_files:
|
|
99
101
|
- spec/example_classes/scope_t_with_path_in_module.rb
|
100
102
|
- spec/example_classes/should_define_scope.rb
|
101
103
|
- spec/example_classes/should_have_attached_scoped_t.rb
|
104
|
+
- spec/example_classes/translate_without_controller_suffix.rb
|
102
105
|
- spec/include_scope_spec.rb
|
103
106
|
- spec/inherit_from_parent_spec.rb
|
104
107
|
- spec/inherited_spec.rb
|
@@ -106,4 +109,5 @@ test_files:
|
|
106
109
|
- spec/scope_spec.rb
|
107
110
|
- spec/should_define_scope_in_module_spec.rb
|
108
111
|
- spec/should_define_scope_spec.rb
|
112
|
+
- spec/should_translate_without_controller_name_spec.rb
|
109
113
|
- spec/spec_helper.rb
|