Class: Scribo::I18nStore

Inherits:
Object
  • Object
show all
Defined in:
lib/scribo/i18n_store.rb

Instance Method Summary collapse

Constructor Details

#initializeI18nStore

Returns a new instance of I18nStore.



25
# File 'lib/scribo/i18n_store.rb', line 25

def initialize; end

Instance Method Details

#[](key) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/scribo/i18n_store.rb', line 37

def [](key)
  return unless content

  result = {}
  locales.each do |locale|
    hash = flat_hash(YAML.safe_load(locale.data)).transform_values { |v| JSON.encode(v) }
    result.merge! hash
  end
  result[key]
end

#[]=(key, value) ⇒ Object



48
49
50
# File 'lib/scribo/i18n_store.rb', line 48

def []=(key, value)
  # NOOP
end

#contentObject



60
61
62
# File 'lib/scribo/i18n_store.rb', line 60

def content
  Thread.current[:scribo_i18n_store_content]
end

#content=(content) ⇒ Object



64
65
66
# File 'lib/scribo/i18n_store.rb', line 64

def content=(content)
  Thread.current[:scribo_i18n_store_content] = content
end

#keysObject



27
28
29
30
31
32
33
34
35
# File 'lib/scribo/i18n_store.rb', line 27

def keys
  return [] unless content

  result = []
  locales.each do |locale|
    result += flat_hash(YAML.safe_load(locale.data)).keys
  end
  result
end

#with(content) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/scribo/i18n_store.rb', line 52

def with(content)
  with_custom_backend do
    self.content = content
    yield(content)
    self.content = nil
  end
end