Class: SgtnClient::Translation
- Inherits:
- 
      Object
      
        - Object
- SgtnClient::Translation
 
- Defined in:
- lib/sgtn-client/api/translation.rb
Direct Known Subclasses
Class Method Summary collapse
- .getString(component, key, locale) ⇒ Object
- .getString_f(component, key, args, locale) ⇒ Object
- .getStrings(component, locale) ⇒ Object
Class Method Details
.getString(component, key, locale) ⇒ Object
| 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | # File 'lib/sgtn-client/api/translation.rb', line 14 def self.getString(component, key, locale) flocale = SgtnClient::LocaleUtil.fallback(locale) cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale) items = SgtnClient::CacheUtil.get_cache(cache_key) if items.nil? items = getTranslations(component, flocale) SgtnClient::CacheUtil.write_cache(cache_key, items) else SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key end default = SgtnClient::Config.configurations.default if items.nil? || items["messages"] == nil return SgtnClient::Source.getSource(component, key, default) end str = items["messages"][key] if str.nil? return SgtnClient::Source.getSource(component, key, default) else return str end end | 
.getString_f(component, key, args, locale) ⇒ Object
| 37 38 39 40 41 42 43 44 45 46 47 48 | # File 'lib/sgtn-client/api/translation.rb', line 37 def self.getString_f(component, key, args, locale) s = getString(component, key, locale) if is_json?(args) jsonstr = MultiJson.load(args) jsonstr.each do |source, arg| s.gsub! "{#{source}}", arg end elsif args.is_a?(Array) s = sprintf s % args end return s end | 
.getStrings(component, locale) ⇒ Object
| 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | # File 'lib/sgtn-client/api/translation.rb', line 50 def self.getStrings(component, locale) flocale = SgtnClient::LocaleUtil.fallback(locale) cache_key = SgtnClient::CacheUtil.get_cachekey(component, flocale) items = SgtnClient::CacheUtil.get_cache(cache_key) if items.nil? items = getTranslations(component, flocale) SgtnClient::CacheUtil.write_cache(cache_key, items) else SgtnClient.logger.debug "Getting translations from cache with key: " + cache_key end default = SgtnClient::Config.configurations.default if items.nil? || items["messages"] == nil items = SgtnClient::Source.getSources(component, default) end return items end |