r18n-core 3.1.1 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +398 -0
- data/README.md +63 -47
- data/base/cy.yml +34 -0
- data/lib/r18n-core.rb +37 -38
- data/lib/r18n-core/filter_list.rb +21 -13
- data/lib/r18n-core/filters.rb +43 -48
- data/lib/r18n-core/helpers.rb +2 -2
- data/lib/r18n-core/i18n.rb +70 -78
- data/lib/r18n-core/locale.rb +137 -107
- data/lib/r18n-core/locales/af.rb +36 -0
- data/lib/r18n-core/locales/az.rb +38 -0
- data/lib/r18n-core/locales/bg.rb +29 -0
- data/{locales → lib/r18n-core/locales}/ca.rb +9 -6
- data/{locales → lib/r18n-core/locales}/cs.rb +15 -11
- data/lib/r18n-core/locales/cy.rb +50 -0
- data/{locales → lib/r18n-core/locales}/da.rb +10 -7
- data/lib/r18n-core/locales/de.rb +33 -0
- data/{locales → lib/r18n-core/locales}/en-au.rb +2 -2
- data/{locales → lib/r18n-core/locales}/en-gb.rb +2 -2
- data/{locales → lib/r18n-core/locales}/en-us.rb +4 -3
- data/lib/r18n-core/locales/en.rb +51 -0
- data/{locales → lib/r18n-core/locales}/eo.rb +6 -4
- data/lib/r18n-core/locales/es-cl.rb +16 -0
- data/{locales → lib/r18n-core/locales}/es-us.rb +5 -4
- data/{locales → lib/r18n-core/locales}/es.rb +7 -3
- data/{locales → lib/r18n-core/locales}/fa.rb +2 -2
- data/lib/r18n-core/locales/fi.rb +39 -0
- data/lib/r18n-core/locales/fr.rb +39 -0
- data/{locales → lib/r18n-core/locales}/gl.rb +5 -3
- data/{locales → lib/r18n-core/locales}/hr.rb +13 -10
- data/{locales → lib/r18n-core/locales}/hu.rb +10 -7
- data/{locales → lib/r18n-core/locales}/id.rb +8 -4
- data/lib/r18n-core/locales/it.rb +37 -0
- data/{locales → lib/r18n-core/locales}/ja.rb +5 -4
- data/{locales → lib/r18n-core/locales}/kk.rb +12 -8
- data/{locales → lib/r18n-core/locales}/ko.rb +0 -0
- data/lib/r18n-core/locales/lv.rb +46 -0
- data/lib/r18n-core/locales/mn.rb +30 -0
- data/{locales → lib/r18n-core/locales}/nb.rb +6 -4
- data/lib/r18n-core/locales/nl.rb +31 -0
- data/{locales → lib/r18n-core/locales}/no.rb +0 -0
- data/lib/r18n-core/locales/pl.rb +45 -0
- data/{locales → lib/r18n-core/locales}/pt-br.rb +1 -1
- data/lib/r18n-core/locales/pt.rb +37 -0
- data/lib/r18n-core/locales/ru.rb +46 -0
- data/{locales → lib/r18n-core/locales}/sk.rb +13 -9
- data/{locales → lib/r18n-core/locales}/sr-latn.rb +10 -8
- data/{locales → lib/r18n-core/locales}/sv-se.rb +7 -5
- data/lib/r18n-core/locales/th.rb +41 -0
- data/{locales → lib/r18n-core/locales}/tr.rb +7 -6
- data/lib/r18n-core/locales/uk.rb +31 -0
- data/lib/r18n-core/locales/vi.rb +37 -0
- data/{locales → lib/r18n-core/locales}/zh-cn.rb +2 -2
- data/{locales → lib/r18n-core/locales}/zh-tw.rb +4 -4
- data/{locales → lib/r18n-core/locales}/zh.rb +7 -4
- data/lib/r18n-core/translated.rb +38 -37
- data/lib/r18n-core/translated_string.rb +19 -8
- data/lib/r18n-core/translation.rb +24 -19
- data/lib/r18n-core/unsupported_locale.rb +14 -6
- data/lib/r18n-core/untranslated.rb +23 -7
- data/lib/r18n-core/utils.rb +19 -23
- data/lib/r18n-core/version.rb +1 -1
- data/lib/r18n-core/yaml_loader.rb +17 -13
- data/lib/r18n-core/yaml_methods.rb +3 -1
- metadata +245 -118
- data/.rspec +0 -1
- data/Rakefile +0 -13
- data/locales/af.rb +0 -32
- data/locales/az.rb +0 -34
- data/locales/bg.rb +0 -25
- data/locales/de.rb +0 -29
- data/locales/en.rb +0 -48
- data/locales/fi.rb +0 -35
- data/locales/fr.rb +0 -35
- data/locales/it.rb +0 -34
- data/locales/lv.rb +0 -41
- data/locales/mn.rb +0 -27
- data/locales/nl.rb +0 -28
- data/locales/pl.rb +0 -40
- data/locales/pt.rb +0 -29
- data/locales/ru.rb +0 -41
- data/locales/th.rb +0 -37
- data/locales/uk.rb +0 -27
- data/locales/vi.rb +0 -33
- data/r18n-core.gemspec +0 -29
- data/spec/filters_spec.rb +0 -324
- data/spec/i18n_spec.rb +0 -260
- data/spec/locale_spec.rb +0 -216
- data/spec/locales/cs_spec.rb +0 -23
- data/spec/locales/en-us_spec.rb +0 -13
- data/spec/locales/en_spec.rb +0 -13
- data/spec/locales/fa_spec.rb +0 -10
- data/spec/locales/fr_spec.rb +0 -9
- data/spec/locales/hu_spec.rb +0 -17
- data/spec/locales/it_spec.rb +0 -10
- data/spec/locales/no_spec.rb +0 -9
- data/spec/locales/pl_spec.rb +0 -23
- data/spec/locales/ru_spec.rb +0 -23
- data/spec/locales/sk_spec.rb +0 -23
- data/spec/locales/th_spec.rb +0 -9
- data/spec/locales/vi_spec.rb +0 -8
- data/spec/r18n_spec.rb +0 -172
- data/spec/spec_helper.rb +0 -41
- data/spec/translated_spec.rb +0 -163
- data/spec/translation_spec.rb +0 -164
- data/spec/translations/extension/deep/en.yml +0 -1
- data/spec/translations/extension/en.yml +0 -2
- data/spec/translations/extension/notransl.yml +0 -1
- data/spec/translations/general/en.yml +0 -47
- data/spec/translations/general/nolocale.yml +0 -6
- data/spec/translations/general/ru.yml +0 -7
- data/spec/translations/two/en.yml +0 -2
- data/spec/translations/two/fr.yml +0 -0
- data/spec/yaml_loader_spec.rb +0 -61
@@ -7,21 +7,24 @@ module R18n
|
|
7
7
|
set(
|
8
8
|
title: '中文',
|
9
9
|
|
10
|
+
sublocales: %w[zh-CN zh-TW],
|
11
|
+
|
10
12
|
wday_names: %w[星期日 星期一 星期二 星期三 星期四 星期五 星期六],
|
11
13
|
wday_abbrs: %w[周日 周一 周二 周三 周四 周五 周六],
|
12
14
|
|
13
|
-
month_names: %w[
|
14
|
-
|
15
|
+
month_names: %w[
|
16
|
+
一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月
|
17
|
+
],
|
15
18
|
|
16
19
|
date_format: '%Y年%m月%d日',
|
17
20
|
full_format: '%m月%d日',
|
18
21
|
year_format: '%Y年_',
|
19
22
|
|
20
23
|
number_decimal: '.',
|
21
|
-
number_group:
|
24
|
+
number_group: ' '
|
22
25
|
)
|
23
26
|
|
24
|
-
def pluralize(
|
27
|
+
def pluralize(_number)
|
25
28
|
'n'
|
26
29
|
end
|
27
30
|
end
|
data/lib/r18n-core/translated.rb
CHANGED
@@ -22,9 +22,9 @@ module R18n
|
|
22
22
|
# R18n plugin with out-of-box i18n support.
|
23
23
|
#
|
24
24
|
# Module can add proxy-methods to find translation in object methods. For
|
25
|
-
# example, if you class have
|
26
|
-
# proxy-method
|
27
|
-
#
|
25
|
+
# example, if you class have `title_en` and `title_ru` methods, you can add
|
26
|
+
# proxy-method `title`, which will use `title_ru` for Russian users and
|
27
|
+
# `title_en` for English:
|
28
28
|
#
|
29
29
|
# class Product
|
30
30
|
# include DataMapper::Resource
|
@@ -58,21 +58,21 @@ module R18n
|
|
58
58
|
# Proxy-method support all funtion from I18n: global and type filters,
|
59
59
|
# pluralization, variables. It also return TranslatedString or Untranslated.
|
60
60
|
#
|
61
|
-
# By default it use
|
62
|
-
# before use model), but you can overwrite object
|
61
|
+
# By default it use `R18n.get` to get I18n object (so, you must set it
|
62
|
+
# before use model), but you can overwrite object `r18n` method to change
|
63
63
|
# default logic.
|
64
64
|
#
|
65
65
|
# See R18n::Translated::Base for class method documentation.
|
66
66
|
#
|
67
67
|
# == Options
|
68
68
|
# You can set option for proxy-method as Hash with keys;
|
69
|
-
# *
|
70
|
-
# *
|
71
|
-
# *
|
69
|
+
# * `type` – YAML type for filters. For example, "markdown" or "escape_html".
|
70
|
+
# * `methods` – manual method map as Hash of locale codes to method names.
|
71
|
+
# * `no_params` – set it to true if you proxy-method must send it parameters
|
72
72
|
# only to filters.
|
73
|
-
# *
|
73
|
+
# * `no_write` – set it to true if you don't want to create proxy-setters.
|
74
74
|
#
|
75
|
-
# Method
|
75
|
+
# Method `translation` will be more useful for options:
|
76
76
|
#
|
77
77
|
# translation :title, methods: { ru: :russian, en: :english}
|
78
78
|
module Translated
|
@@ -81,54 +81,54 @@ module R18n
|
|
81
81
|
base.send :extend, Base
|
82
82
|
base.instance_variable_set '@unlocalized_getters', {}
|
83
83
|
base.instance_variable_set '@unlocalized_setters', {}
|
84
|
-
base.instance_variable_set '@translation_types', {}
|
85
84
|
end
|
86
85
|
end
|
87
86
|
|
88
87
|
# Access to I18n object. By default return global I18n object from
|
89
|
-
#
|
88
|
+
# `R18n.get`.
|
90
89
|
def r18n
|
91
90
|
R18n.get
|
92
91
|
end
|
93
92
|
|
94
93
|
# Module with class methods, which be added after R18n::Translated include.
|
95
94
|
module Base
|
96
|
-
# Hash of translation method names to it type for filters.
|
97
|
-
|
95
|
+
# `Hash` of translation method names to it type for filters.
|
96
|
+
def translation_types
|
97
|
+
@translation_types ||= {}
|
98
|
+
end
|
98
99
|
|
99
|
-
# Add several proxy
|
100
|
-
# It
|
100
|
+
# Add several proxy methods. See `R18n::Translated` for description.
|
101
|
+
# It's more compact, that `translation`.
|
101
102
|
#
|
102
103
|
# translations :title, :keywords, [:desciption, { type: 'markdown' }]
|
103
|
-
def translations(*
|
104
|
-
|
105
|
-
translation(*method)
|
106
|
-
end
|
104
|
+
def translations(*names)
|
105
|
+
names.each { |name| translation(*name) }
|
107
106
|
end
|
108
107
|
|
109
|
-
# Add proxy-method
|
110
|
-
# It
|
108
|
+
# Add proxy-method `name`. See `R18n::Translated` for description.
|
109
|
+
# It's more useful to set options.
|
111
110
|
#
|
112
|
-
# translation :
|
111
|
+
# translation :description, type: 'markdown'
|
113
112
|
def translation(name, options = {})
|
114
113
|
if options[:methods]
|
115
|
-
@unlocalized_getters[name] =
|
116
|
-
|
114
|
+
@unlocalized_getters[name] =
|
115
|
+
options[:methods].map { |l, i| [l.to_s, i.to_s] }.to_h
|
117
116
|
unless options[:no_write]
|
118
|
-
@unlocalized_setters[name] =
|
119
|
-
|
117
|
+
@unlocalized_setters[name] =
|
118
|
+
options[:methods].map { |l, i| [l.to_s, "#{i}="] }.to_h
|
120
119
|
end
|
121
120
|
end
|
122
121
|
|
123
|
-
|
122
|
+
translation_types[name] = options[:type]
|
124
123
|
|
125
124
|
define_method name do |*params|
|
126
125
|
unlocalized = self.class.unlocalized_getters(name)
|
127
126
|
result = nil
|
128
127
|
|
129
128
|
r18n.locales.each do |locale|
|
130
|
-
code = locale.
|
129
|
+
code = locale.downcased_code
|
131
130
|
next unless unlocalized.key? code
|
131
|
+
|
132
132
|
result = send(
|
133
133
|
unlocalized[code], *(params unless options[:no_params])
|
134
134
|
)
|
@@ -160,22 +160,23 @@ module R18n
|
|
160
160
|
r18n.locales.each do |locale|
|
161
161
|
code = locale.code
|
162
162
|
next unless unlocalized.key? code
|
163
|
+
|
163
164
|
return send unlocalized[code], *params
|
164
165
|
end
|
165
166
|
end
|
166
167
|
end
|
167
168
|
|
168
|
-
# Return array of methods to find
|
169
|
-
#
|
169
|
+
# Return array of methods to find `unlocalized_getters` or
|
170
|
+
# `unlocalized_setters`.
|
170
171
|
def unlocalized_methods
|
171
172
|
instance_methods
|
172
173
|
end
|
173
174
|
|
174
|
-
# Return Hash of locale code to getter method for proxy
|
175
|
-
# didn
|
175
|
+
# Return `Hash` of locale code to getter method for proxy `method`. If you
|
176
|
+
# didn't set map in `translation` option `methods`, it will be detect
|
176
177
|
# automatically.
|
177
178
|
def unlocalized_getters(method)
|
178
|
-
matcher = Regexp.new(
|
179
|
+
matcher = Regexp.new("^#{Regexp.escape(method.to_s)}_(\\w+)$")
|
179
180
|
unless @unlocalized_getters.key? method
|
180
181
|
@unlocalized_getters[method] = {}
|
181
182
|
unlocalized_methods.select { |i| i =~ matcher }.each do |i|
|
@@ -185,11 +186,11 @@ module R18n
|
|
185
186
|
@unlocalized_getters[method]
|
186
187
|
end
|
187
188
|
|
188
|
-
# Return Hash of locale code to setter method for proxy
|
189
|
-
# didn
|
189
|
+
# Return `Hash` of locale code to setter method for proxy `method`. If you
|
190
|
+
# didn't set map in `translation` option `methods`, it will be detect
|
190
191
|
# automatically.
|
191
192
|
def unlocalized_setters(method)
|
192
|
-
matcher = Regexp.new(
|
193
|
+
matcher = Regexp.new("^#{Regexp.escape(method.to_s)}_(\\w+)=$")
|
193
194
|
unless @unlocalized_setters.key? method
|
194
195
|
@unlocalized_setters[method] = {}
|
195
196
|
unlocalized_methods.select { |i| i =~ matcher }.each do |i|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'untranslated'
|
4
|
+
|
3
5
|
# Translation string for i18n support.
|
4
6
|
#
|
5
7
|
# Copyright (C) 2008 Andrey “A.I.” Sitnik <andrey@sitnik.ru>
|
@@ -26,8 +28,8 @@ module R18n
|
|
26
28
|
# Path for this translation.
|
27
29
|
attr_reader :path
|
28
30
|
|
29
|
-
# Returns a new string object containing a copy of
|
30
|
-
# for
|
31
|
+
# Returns a new string object containing a copy of `str`, which translated
|
32
|
+
# for `path` to `locale`
|
31
33
|
def initialize(value, locale, path, filters = nil)
|
32
34
|
super(value.to_s)
|
33
35
|
@filters = filters
|
@@ -45,14 +47,9 @@ module R18n
|
|
45
47
|
true
|
46
48
|
end
|
47
49
|
|
48
|
-
# Return true if `html_safe` method is defined, otherwise false.
|
49
|
-
def html_safe?
|
50
|
-
respond_to? :html_safe
|
51
|
-
end
|
52
|
-
|
53
50
|
# Override to_s to make string html safe if `html_safe` method is defined.
|
54
51
|
def to_s
|
55
|
-
if respond_to?
|
52
|
+
if respond_to?(:html_safe)
|
56
53
|
super.html_safe
|
57
54
|
else
|
58
55
|
String.new(super)
|
@@ -82,9 +79,23 @@ module R18n
|
|
82
79
|
Untranslated.new(translated, key, @locale, @filters)
|
83
80
|
end
|
84
81
|
|
82
|
+
NON_KEYS_METHODS = [
|
83
|
+
*Untranslated::NON_KEYS_METHODS,
|
84
|
+
:html_safe,
|
85
|
+
:to_text
|
86
|
+
].freeze
|
87
|
+
|
85
88
|
# Return untranslated, when user try to go deeper in translation.
|
86
89
|
def method_missing(name, *_params)
|
90
|
+
return super if NON_KEYS_METHODS.include?(name)
|
91
|
+
|
87
92
|
get_untranslated(name.to_s)
|
88
93
|
end
|
94
|
+
|
95
|
+
def respond_to_missing?(name, *args)
|
96
|
+
return super if NON_KEYS_METHODS.include?(name)
|
97
|
+
|
98
|
+
true
|
99
|
+
end
|
89
100
|
end
|
90
101
|
end
|
@@ -23,16 +23,16 @@ module R18n
|
|
23
23
|
|
24
24
|
# Translation is container of translated messages.
|
25
25
|
#
|
26
|
-
# You can load several locales and if translation willn
|
26
|
+
# You can load several locales and if translation willn't be found in first,
|
27
27
|
# r18n will be search it in next. Use R18n::I18n.new to load translations.
|
28
28
|
#
|
29
29
|
# To get translation value use method with same name. If translation name
|
30
|
-
# is equal with Object methods (
|
31
|
-
#
|
30
|
+
# is equal with Object methods (`new`, `to_s`, `methods`) use
|
31
|
+
# `[name, params…]`. If you want to get pluralizable value, just set
|
32
32
|
# value for pluralization in first argument of method. See samples below.
|
33
33
|
#
|
34
|
-
# Translated strings will have
|
35
|
-
# UnsupportedLocale, if locale file isn
|
34
|
+
# Translated strings will have `locale` methods, which return Locale or
|
35
|
+
# UnsupportedLocale, if locale file isn't exists.
|
36
36
|
#
|
37
37
|
# == Examples
|
38
38
|
# translations/ru.yml
|
@@ -51,7 +51,7 @@ module R18n
|
|
51
51
|
# comments: !!pl
|
52
52
|
# 0: no comments
|
53
53
|
# 1: one comment
|
54
|
-
# n: %1 comments
|
54
|
+
# n: '%1 comments'
|
55
55
|
#
|
56
56
|
# example.rb
|
57
57
|
#
|
@@ -68,7 +68,7 @@ module R18n
|
|
68
68
|
# i18n.comments(10) #=> "10 comments"
|
69
69
|
class Translation
|
70
70
|
# This is internal a constructor. To load translation use
|
71
|
-
#
|
71
|
+
# `R18n::I18n.new(locales, translations_dir)`.
|
72
72
|
def initialize(locale, path = '', options = {})
|
73
73
|
@data = {}
|
74
74
|
@locale = locale
|
@@ -78,8 +78,8 @@ module R18n
|
|
78
78
|
merge! options[:translations], options[:locale] if options[:translations]
|
79
79
|
end
|
80
80
|
|
81
|
-
# Add another hash with
|
82
|
-
# more priority, that new one in
|
81
|
+
# Add another hash with `translations` for some `locale`. Current data is
|
82
|
+
# more priority, that new one in `translations`.
|
83
83
|
def merge!(translations, locale)
|
84
84
|
(translations || {}).each_pair do |name, value|
|
85
85
|
if !@data.key?(name)
|
@@ -123,28 +123,27 @@ module R18n
|
|
123
123
|
|
124
124
|
# Return current translation keys.
|
125
125
|
#
|
126
|
-
# Deprecated. Use
|
126
|
+
# Deprecated. Use `to_hash.keys`.
|
127
127
|
def translation_keys
|
128
128
|
to_hash.keys
|
129
129
|
end
|
130
130
|
|
131
131
|
# Return hash of current translation node.
|
132
132
|
def to_hash
|
133
|
-
|
134
|
-
value
|
135
|
-
[key, value]
|
133
|
+
@data.transform_values do |value|
|
134
|
+
value.is_a?(Translation) ? value.to_hash : value
|
136
135
|
end
|
137
136
|
end
|
138
137
|
|
139
|
-
# Return
|
138
|
+
# Return `default`.
|
140
139
|
def |(other)
|
141
140
|
other
|
142
141
|
end
|
143
142
|
|
144
|
-
# Return translation with special
|
143
|
+
# Return translation with special `name`.
|
145
144
|
#
|
146
|
-
# Translation can contain variable part. Just set is as
|
147
|
-
#
|
145
|
+
# Translation can contain variable part. Just set is as `%1`,
|
146
|
+
# `%2`, etc in translations file and set values in next `params`.
|
148
147
|
def [](name, *params)
|
149
148
|
unless [String, Integer, TrueClass, FalseClass]
|
150
149
|
.any? { |klass| name.is_a?(klass) }
|
@@ -166,10 +165,16 @@ module R18n
|
|
166
165
|
end
|
167
166
|
alias method_missing []
|
168
167
|
|
169
|
-
# Return translation located at
|
168
|
+
# Return translation located at `keys`.
|
170
169
|
# @see Hash#dig
|
171
170
|
def dig(*keys)
|
172
|
-
keys.reduce(self
|
171
|
+
keys.reduce(self, :[])
|
172
|
+
end
|
173
|
+
|
174
|
+
# I think we don't need in the Ruby core method,
|
175
|
+
# but it can be handy as a key
|
176
|
+
def itself
|
177
|
+
self[__method__]
|
173
178
|
end
|
174
179
|
end
|
175
180
|
end
|
@@ -24,10 +24,13 @@ module R18n
|
|
24
24
|
# Locale, to get data and pluralization for unsupported locale.
|
25
25
|
attr_accessor :base
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
attr_reader :code, :downcased_code
|
28
|
+
|
29
|
+
# Create object for unsupported locale with `code` and load other locale
|
30
|
+
# data from `base` locale.
|
29
31
|
def initialize(code, _base = nil)
|
30
32
|
@code = code
|
33
|
+
@downcased_code = @code.downcase.tr('-', '_').freeze
|
31
34
|
@base = Locale.load(I18n.default) if @code != I18n.default
|
32
35
|
end
|
33
36
|
|
@@ -41,9 +44,6 @@ module R18n
|
|
41
44
|
"Unsupported locale #{@code}"
|
42
45
|
end
|
43
46
|
|
44
|
-
# Locale RFC 3066 code.
|
45
|
-
attr_reader :code
|
46
|
-
|
47
47
|
# Locale code as title.
|
48
48
|
def title
|
49
49
|
@code
|
@@ -56,7 +56,15 @@ module R18n
|
|
56
56
|
|
57
57
|
# Proxy to default locale object.
|
58
58
|
def method_missing(name, *params)
|
59
|
-
@base.
|
59
|
+
return super unless @base.respond_to? name
|
60
|
+
|
61
|
+
@base.public_send(name, *params)
|
62
|
+
end
|
63
|
+
|
64
|
+
def respond_to_missing?(name, *args)
|
65
|
+
return super unless @base
|
66
|
+
|
67
|
+
@base.send __method__, name, *args
|
60
68
|
end
|
61
69
|
end
|
62
70
|
end
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
module R18n
|
21
|
-
# Return if translation isn
|
21
|
+
# Return if translation isn't exists. Unlike nil, it didn't raise error when
|
22
22
|
# you try to access for subtranslations.
|
23
23
|
#
|
24
24
|
# You can set format to print untranslated string by filters. For example:
|
@@ -37,7 +37,7 @@ module R18n
|
|
37
37
|
#
|
38
38
|
# R18n::Filters.add(R18n::Untranslated, :hide_untranslated) { '' }
|
39
39
|
class Untranslated
|
40
|
-
# Path, that isn
|
40
|
+
# Path, that isn't in translation.
|
41
41
|
attr_reader :untranslated_path
|
42
42
|
|
43
43
|
# Path, that exists in translation.
|
@@ -73,18 +73,33 @@ module R18n
|
|
73
73
|
new arr[1], arr[2], R18n.locale(arr[0]), GlobalFilterList.instance
|
74
74
|
end
|
75
75
|
|
76
|
+
NON_KEYS_METHODS = %i[
|
77
|
+
to_ary
|
78
|
+
to_hash
|
79
|
+
marshal_dump
|
80
|
+
marshal_load
|
81
|
+
].freeze
|
82
|
+
|
76
83
|
def method_missing(name, *_params)
|
77
84
|
# It is need to fix some hack in specs
|
78
|
-
if name
|
79
|
-
raise NoMethodError, "undefined method `to_ary' for #{self}"
|
80
|
-
end
|
85
|
+
return super if NON_KEYS_METHODS.include?(name)
|
81
86
|
|
82
87
|
self[name]
|
83
88
|
end
|
84
89
|
|
90
|
+
def respond_to_missing?(name, *args)
|
91
|
+
return super if NON_KEYS_METHODS.include?(name)
|
92
|
+
|
93
|
+
true
|
94
|
+
end
|
95
|
+
|
85
96
|
def [](*params)
|
86
|
-
Untranslated.new(
|
87
|
-
|
97
|
+
Untranslated.new(
|
98
|
+
translated_path,
|
99
|
+
"#{@untranslated_path}.#{params.first}",
|
100
|
+
@locale,
|
101
|
+
@filters
|
102
|
+
)
|
88
103
|
end
|
89
104
|
|
90
105
|
def |(other)
|
@@ -106,6 +121,7 @@ module R18n
|
|
106
121
|
return false unless locale == other.locale
|
107
122
|
return false unless translated_path == other.translated_path
|
108
123
|
return false unless untranslated_path == other.untranslated_path
|
124
|
+
|
109
125
|
true
|
110
126
|
end
|
111
127
|
end
|