Method: Twine::Formatters::Android#format_value
- Defined in:
- lib/twine/formatters/android.rb
#format_value(value) ⇒ Object
see developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling however unescaped HTML markup like in “Welcome to Android!” is stripped when retrieved with getString() (stackoverflow.com/questions/9891996/)
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/twine/formatters/android.rb', line 147 def format_value(value) value = value.dup # convert placeholders (e.g. %@ -> %s) value = convert_placeholders_from_twine_to_android(value) # capture xliff tags and replace them with a placeholder = [] value.gsub! /<xliff:g.+?<\/xliff:g>/ do << $& 'TWINE_XLIFF_TAG_PLACEHOLDER' end # escape everything outside xliff tags value = escape_value(value) # put xliff tags back into place .each do |xliff_tag| # escape content of xliff tags xliff_tag.gsub! /(<xliff:g.*?>)(.*)(<\/xliff:g>)/ do "#{$1}#{escape_value($2)}#{$3}" end value.sub! 'TWINE_XLIFF_TAG_PLACEHOLDER', xliff_tag end # replace beginning and end spaces with \u0020. Otherwise Android strips them. value.gsub(/\A *| *\z/) { |spaces| '\u0020' * spaces.length } end |