Sha256: aa83ed16b4b8cfef2589f73f853c337e43764be5e658aa484395fb6512f8ccaf

Contents?: true

Size: 984 Bytes

Versions: 1

Compression:

Stored size: 984 Bytes

Contents

class NSString
  def _localized(value=nil, table=nil)
    @localized = NSBundle.mainBundle.localizedStringForKey(self, value:value, table:table)
    storeTranslation(self, @localized, value, table) if phraseEnabled?
    @localized
  end
  alias __ _localized

private
  def storeTranslation(key, localized, defaultValue=nil, table=nil)
    @client = MotionPhrase::ApiClient.sharedClient
    @client.storeTranslation(key, localized, defaultValue, currentLocaleName)
  end

  def phraseEnabled?
    PHRASE_ENABLED == true && development?
  end

  def currentLocaleName
    currentLocale.localeIdentifier
  end

  # @return [NSLocale] locale of user settings
  def currentLocale
    languages = NSLocale.preferredLanguages
    if languages.count > 0
      return NSLocale.alloc.initWithLocaleIdentifier(languages.first)
    else
      return NSLocale.currentLocale
    end
  end

  def environment
    RUBYMOTION_ENV
  end

  def development?
    environment == 'development'
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
motion-phrase-0.0.6 lib/motion-phrase/nsstring.rb