i18n_scopes 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/i18n_scopes/scope.rb
CHANGED
@@ -49,6 +49,9 @@ module I18nScopes
|
|
49
49
|
define_method(as) do |*args|
|
50
50
|
scoped_translation(self.class.i18n_scope_helper[name], *args)
|
51
51
|
end
|
52
|
+
define_method(:"#{as}_key") do |*args|
|
53
|
+
scoped_translation_key(self.class.i18n_scope_helper[name], *args)
|
54
|
+
end
|
52
55
|
end
|
53
56
|
|
54
57
|
# this method creates a default scope
|
@@ -13,9 +13,31 @@ module I18nScopes
|
|
13
13
|
# * +path_extension+: +Array+ an additional path to the one configued using Scope::ClassMethods#i18n_scope (will be attached to the end)
|
14
14
|
# * +respondable+: an array of objects on which the methods should be looked up
|
15
15
|
# * +parameter_matchings+: a hash containing arguments for the dynamic method calls
|
16
|
+
# * +scoped_default+: this can either be true, if the default translation should be scoped or can be an array with the same args as this method
|
17
|
+
# === Returns:
|
18
|
+
# a translated string
|
16
19
|
def scoped_translation(scope_helper, *args)
|
20
|
+
scope = scoped_translation_key(scope_helper, *args)
|
17
21
|
options = args.extract_options!
|
18
|
-
|
22
|
+
return I18n.translate *args, options.merge(scope: scope)
|
23
|
+
end
|
24
|
+
|
25
|
+
# translates the given key under the configured scope
|
26
|
+
#
|
27
|
+
# === Params:
|
28
|
+
# * +key+: the translation key to lookup
|
29
|
+
# * +options+:
|
30
|
+
# * +path+: +Array+ the path to be overwritten
|
31
|
+
# * +path_extension+: +Array+ an additional path to the one configued using Scope::ClassMethods#i18n_scope (will be attached to the end)
|
32
|
+
# * +respondable+: an array of objects on which the methods should be looked up
|
33
|
+
# * +parameter_matchings+: a hash containing arguments for the dynamic method calls
|
34
|
+
# === Returns:
|
35
|
+
# The translation key
|
36
|
+
def scoped_translation_key(scope_helper, *args)
|
37
|
+
dupped = args.dup
|
38
|
+
options = dupped.extract_options!
|
39
|
+
key = dupped.shift
|
40
|
+
|
19
41
|
additional_parameters = if self.respond_to?(:i18n_parameter_matchings)
|
20
42
|
self.i18n_parameter_matchings
|
21
43
|
else
|
@@ -31,7 +53,7 @@ module I18nScopes
|
|
31
53
|
scope = scope_helper.scope_from_path(self, options, parameter_matchings)
|
32
54
|
|
33
55
|
scope += options[:scope] if options.include?(:scope)
|
34
|
-
return
|
56
|
+
return scope
|
35
57
|
end
|
36
58
|
|
37
59
|
# returns the i18n_scope_helper instance of TranslationHelper
|
data/lib/i18n_scopes/version.rb
CHANGED
data/spec/locales/en.yml
CHANGED
@@ -10,6 +10,9 @@ en:
|
|
10
10
|
name: ScopeTWithPathAndRespondable
|
11
11
|
inherited:
|
12
12
|
name: InheritedScope
|
13
|
+
static_default:
|
14
|
+
scope_t_with_path:
|
15
|
+
default_message: ScopeTWithPathFallbackScopeMessage
|
13
16
|
|
14
17
|
some_module:
|
15
18
|
prefix_suffix:
|
@@ -21,8 +24,9 @@ en:
|
|
21
24
|
scope_t_with_path:
|
22
25
|
flashes:
|
23
26
|
message: ScopeTWithPathFromScope
|
27
|
+
another_message: ScopeTWithPathFallbackMessage
|
24
28
|
inheritance_overwritten:
|
25
29
|
flashes:
|
26
30
|
message: InheritedScopeOverwritten
|
27
31
|
scopes:
|
28
|
-
name: ScopeTWithPathAndControllerName
|
32
|
+
name: ScopeTWithPathAndControllerName
|
@@ -3,7 +3,6 @@ require 'example_classes/scope_t_with_path'
|
|
3
3
|
require 'example_classes/respondable'
|
4
4
|
|
5
5
|
describe ScopeTWithPath do
|
6
|
-
|
7
6
|
|
8
7
|
its(:translate) { should == "ScopeTWithPathTranslationFromFile"}
|
9
8
|
|
@@ -15,4 +14,6 @@ describe ScopeTWithPath do
|
|
15
14
|
|
16
15
|
its(:translate_flash) { should == "ScopeTWithPathFromScope" }
|
17
16
|
|
17
|
+
its(:translate_with_default) { should == "ScopeTWithPathFallbackMessage" }
|
18
|
+
|
18
19
|
end
|
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.
|
4
|
+
version: 0.4.0
|
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-08-
|
12
|
+
date: 2012-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|