Class: I18n::Backend::Jargon

Inherits:
Object
  • Object
show all
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.3"

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Jargon

Returns a new instance of Jargon.

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/i18n/backend/jargon.rb', line 14

def initialize(options)
@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(options)
  raise ArgumentError if @config[:uuid].nil?
end

Instance Method Details

#available_localesObject



41
42
43
# File 'lib/i18n/backend/jargon.rb', line 41

def available_locales
  @available_locales ||= download_available_locales
end

#initialized?Boolean

Returns:

  • (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_pathObject



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_pollingObject



32
33
34
# File 'lib/i18n/backend/jargon.rb', line 32

def stop_polling
  @stop_polling = true
end

#translate(locale, key, options = {}) ⇒ Object

Raises:

  • (InvalidLocale)


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, options = {})
  raise InvalidLocale.new(locale) unless locale
  entry = key && lookup(locale, key, options[:scope], options)

  if options.empty?
    entry = resolve(locale, key, entry, options)
  else
    count, default = options.values_at(:count, :default)
    values         = options.except(*RESERVED_KEYS)
    entry          = entry.nil? && default ?
    default(locale, key, default, options) : resolve(locale, key, entry, options)
  end

  throw(:exception, I18n::MissingTranslation.new(locale, key, options)) 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