Module: I18nContextGenerator::AndroidResource
- Defined in:
- lib/i18n_context_generator/android_resource.rb
Overview
Canonical Android string-resource identity and source-span indexing.
Defined Under Namespace
Constant Summary collapse
- TAG_TYPES =
{ 'string' => :string, 'plurals' => :plural, 'string-array' => :array }.freeze
- TYPE_TAGS =
TAG_TYPES.invert.freeze
- RESOURCE_OPEN_PATTERN =
/<(?<tag>string-array|plurals|string)\b(?<attributes>[^>]*?)>/m- ITEM_OPEN_PATTERN =
/<item\b(?<attributes>[^>]*?)>/m
Class Method Summary collapse
- .base_key(key) ⇒ Object
- .composite_key(name, type:, quantity: nil, index: nil) ⇒ Object
- .index(content) ⇒ Object
- .tag_for_type(type) ⇒ Object
- .type_for(key, explicit: nil) ⇒ Object
- .type_for_tag(tag) ⇒ Object
Class Method Details
.base_key(key) ⇒ Object
58 59 60 |
# File 'lib/i18n_context_generator/android_resource.rb', line 58 def base_key(key) key.to_s.sub(/:[a-z]+$/, '').sub(/\[\d+\]$/, '') end |
.composite_key(name, type:, quantity: nil, index: nil) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/i18n_context_generator/android_resource.rb', line 70 def composite_key(name, type:, quantity: nil, index: nil) case type.to_sym when :plural then "#{name}:#{quantity}" when :array then "#{name}[#{index}]" else name end end |
.index(content) ⇒ Object
86 87 88 |
# File 'lib/i18n_context_generator/android_resource.rb', line 86 def index(content) Scanner.new(content).index end |
.tag_for_type(type) ⇒ Object
82 83 84 |
# File 'lib/i18n_context_generator/android_resource.rb', line 82 def tag_for_type(type) TYPE_TAGS[type.to_sym] end |
.type_for(key, explicit: nil) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/i18n_context_generator/android_resource.rb', line 62 def type_for(key, explicit: nil) return explicit.to_sym if explicit return :plural if key.to_s.match?(/:[a-z]+$/) return :array if key.to_s.match?(/\[\d+\]$/) :string end |
.type_for_tag(tag) ⇒ Object
78 79 80 |
# File 'lib/i18n_context_generator/android_resource.rb', line 78 def type_for_tag(tag) TAG_TYPES[tag] end |