forked from translation/rails
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyaml_entry.rb
70 lines (59 loc) · 1.7 KB
/
yaml_entry.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module TranslationIO
module YamlEntry
IGNORED_KEY_PREFIXES = [
'faker'
]
LOCALIZATION_KEY_PREFIXES = [
'date.formats',
'date.order',
'time.formats',
'support.array',
'number.format',
'number.currency',
'number.percentage',
'number.precision',
'number.human.format',
'number.human.storage_units.format',
'number.human.decimal_units.format',
'number.human.decimal_units.units.unit',
'i18n.transliterate'
]
class << self
def string?(key, value)
key.present? && value.is_a?(String)
end
def from_locale?(key, locale)
key.present? && key.start_with?("#{locale}.")
end
def ignored?(key)
key.present? && ignored_key_prefixes.any? { |prefix| key_without_locale(key).match(/^#{Regexp.escape(prefix)}\b/) != nil }
end
def localization?(key, value)
key.present? && (localization_prefix?(key) || (!string?(key, value) && !value.nil?))
end
def localization_prefix?(key)
localization_key_prefixes.any? do |prefix|
key_without_locale(key).match(/^#{Regexp.escape(prefix)}\b/) != nil
end
end
private
def localization_key_prefixes
if TranslationIO.config
LOCALIZATION_KEY_PREFIXES + TranslationIO.config.localization_key_prefixes
else
LOCALIZATION_KEY_PREFIXES
end
end
def ignored_key_prefixes
if TranslationIO.config
IGNORED_KEY_PREFIXES + TranslationIO.config.ignored_key_prefixes
else
IGNORED_KEY_PREFIXES
end
end
def key_without_locale(key)
key.split('.', 2).last
end
end
end
end