Module: Rosetta::Base

Included in:
Rosetta
Defined in:
lib/rosetta-rails.rb

Instance Method Summary collapse

Instance Method Details

#available_localesObject



42
43
44
# File 'lib/rosetta-rails.rb', line 42

def available_locales
  Locale.available_locales
end

#configObject



46
47
48
# File 'lib/rosetta-rails.rb', line 46

def config
  @configuration ||= Configuration.new
end

#configureObject



50
51
52
# File 'lib/rosetta-rails.rb', line 50

def configure
  config.tap { |config| yield(config) }
end

#localeObject



14
15
16
# File 'lib/rosetta-rails.rb', line 14

def locale
  locale_session.locale
end

#locale=(code) ⇒ Object



18
19
20
# File 'lib/rosetta-rails.rb', line 18

def locale=(code)
  locale_session.locale = code
end

#locale_sessionObject



33
34
35
# File 'lib/rosetta-rails.rb', line 33

def locale_session
  Thread.current[:rosetta_locale_session] ||= LocaleSession.new
end

#translate(content, locale: Rosetta.locale) ⇒ Object



37
38
39
40
# File 'lib/rosetta-rails.rb', line 37

def translate(content, locale: Rosetta.locale)
  store = Store.for_locale(locale)
  store.lookup(content)
end

#with_locale(locale, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/rosetta-rails.rb', line 22

def with_locale(locale, &block)
  locale_was = Rosetta.locale
  self.locale = locale

  begin
    yield
  ensure
    self.locale = locale_was
  end
end