class Twine::TwineDefinition

Attributes

comment[RW]
ios_comment[RW]
key[R]
reference[RW]
reference_key[RW]
tags[RW]
translations[R]

Public Class Methods

new(key) click to toggle source
# File lib/twine/twine_file.rb, line 11
def initialize(key)
  @key = key
  @comment = nil
  @ios_comment = nil
  @tags = nil
  @translations = {}
end

Public Instance Methods

matches_tags?(tags, include_untagged) click to toggle source
['tag1', 'tag2'], ['~tag3']

(tag1 OR tag2) AND (!tag3)

# File lib/twine/twine_file.rb, line 36
def matches_tags?(tags, include_untagged)
  if tags == nil || tags.empty?  # The user did not specify any tags. Everything passes.
    return true
  elsif @tags == nil  # This definition has no tags -> check reference (if any)
    return reference ? reference.matches_tags?(tags, include_untagged) : include_untagged
  elsif @tags.empty?
    return include_untagged
  else
    return tags.all? do |set|
      regular_tags, negated_tags = set.partition { |tag| tag[0] != '~' }
      negated_tags.map! { |tag| tag[1..-1] }
      matches_regular_tags = (!regular_tags.empty? && !(regular_tags & @tags).empty?)
      matches_negated_tags = (!negated_tags.empty? && (negated_tags & @tags).empty?)
      matches_regular_tags or matches_negated_tags
    end
  end

  return false
end
raw_comment() click to toggle source
# File lib/twine/twine_file.rb, line 23
def raw_comment
  @comment
end
raw_ios_comment() click to toggle source
# File lib/twine/twine_file.rb, line 31
def raw_ios_comment
  @ios_comment
end
translation_for_lang(lang) click to toggle source
# File lib/twine/twine_file.rb, line 56
def translation_for_lang(lang)
  translation = [lang].flatten.map { |l| @translations[l] }.first

  translation = reference.translation_for_lang(lang) if translation.nil? && reference

  return translation
end
translation_for_lang_or_nil(lang, dev_lang) click to toggle source

Twine adds a copy of the dev language's translation if there is no definition provided for the language, which is useful in the main Localizable.strings file because iOS doesn't auto use the Base language's value, but we don't want that behaviour in our plurals

# File lib/twine/twine_file.rb, line 67
def translation_for_lang_or_nil(lang, dev_lang)
  translation = [lang].flatten.map { |l| @translations[l] }.first

  # translation never comes back as nil because Twine fills with the dev_lang string
  if lang != dev_lang
    [lang].flatten.map do |l|
      if @translations[l] == @translations[dev_lang]
        return nil
      end
    end
  end

  return translation
end