Class: I18n::Backend::Jargon
- Inherits:
-
Object
- Object
- I18n::Backend::Jargon
- Includes:
- Base
- Defined in:
- lib/i18n/backend/jargon.rb,
lib/i18n/backend/jargon/version.rb,
lib/i18n/backend/jargon/null_cache.rb,
lib/i18n/backend/jargon/etag_http_client.rb
Defined Under Namespace
Classes: EtagHttpClient, NullCache
Constant Summary collapse
- VERSION =
Version = "0.2.4"
Instance Method Summary collapse
- #available_locales ⇒ Object
-
#initialize(options) ⇒ Jargon
constructor
A new instance of Jargon.
- #initialized? ⇒ Boolean
- #locale_path(locale) ⇒ Object
- #localization_path ⇒ Object
- #reload! ⇒ Object
- #stop_polling ⇒ Object
- #translate(locale, key, options = {}) ⇒ Object
Constructor Details
#initialize(options) ⇒ Jargon
Returns a new instance of Jargon.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/i18n/backend/jargon.rb', line 14 def initialize() @config = { host: 'http://localhost', http_open_timeout: 1, http_read_timeout: 1, polling_interval: 10*60, cache: NullCache.new, poll: true, exception_handler: lambda{|e| $stderr.puts e }, memory_cache_size: 10 }.merge() raise ArgumentError if @config[:uuid].nil? end |
Instance Method Details
#available_locales ⇒ Object
41 42 43 |
# File 'lib/i18n/backend/jargon.rb', line 41 def available_locales @available_locales ||= download_available_locales end |
#initialized? ⇒ Boolean
28 29 30 |
# File 'lib/i18n/backend/jargon.rb', line 28 def initialized? @initialized ||= false end |
#locale_path(locale) ⇒ Object
45 46 47 |
# File 'lib/i18n/backend/jargon.rb', line 45 def locale_path(locale) localization_path + "/#{locale}" end |
#localization_path ⇒ Object
49 50 51 |
# File 'lib/i18n/backend/jargon.rb', line 49 def localization_path "api/uuid/#{@config[:uuid]}" end |
#reload! ⇒ Object
36 37 38 39 |
# File 'lib/i18n/backend/jargon.rb', line 36 def reload! @initialized = false @translations = nil end |
#stop_polling ⇒ Object
32 33 34 |
# File 'lib/i18n/backend/jargon.rb', line 32 def stop_polling @stop_polling = true end |
#translate(locale, key, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/i18n/backend/jargon.rb', line 53 def translate(locale, key, = {}) raise InvalidLocale.new(locale) unless locale entry = key && lookup(locale, key, [:scope], ) if .empty? entry = resolve(locale, key, entry, ) else count, default = .values_at(:count, :default) values = .except(*RESERVED_KEYS) entry = entry.nil? && default ? default(locale, key, default, ) : resolve(locale, key, entry, ) end throw(:exception, I18n::MissingTranslation.new(locale, key, )) if entry.nil? entry = entry.dup if entry.is_a?(String) entry = pluralize(locale, entry, count) if count entry = interpolate(locale, entry, values) if values entry end |