class PolyglotFlutter::Resource::TranslationKey

Public Instance Methods

clean_translation(language) click to toggle source
# File lib/flutter_polyglot_cli/api/translation_key.rb, line 4
def clean_translation(language)
  translation_value = name
  translation = translations.find { |key| key.language.id == language.id }
  translation_value = translation.value if translation&.value
  escape_translation(translation_value)
  if translation_value.include? '%'
    translation_value = convert_aruments(translation_value)
  end
  translation_value
end

Private Instance Methods

convert_aruments(translation) click to toggle source
# File lib/flutter_polyglot_cli/api/translation_key.rb, line 22
def convert_aruments(translation)
  new_translation = translation
  translation.scan(/(%\w)/).each_with_index do |match, index|
    new_translation = new_translation.sub(match[0], '{arg' + String(index) + '}')
  end

  new_translation
end
escape_translation(translation) click to toggle source
# File lib/flutter_polyglot_cli/api/translation_key.rb, line 17
def escape_translation(translation)
  translation
    .gsub('"', '\\"')
end