Module: Bridgetown::Site::Localizable

Included in:
Bridgetown::Site
Defined in:
lib/bridgetown-core/concerns/site/localizable.rb

Instance Method Summary collapse

Instance Method Details

#localeObject

Returns the current and/or default configured locale

Returns:

  • String



8
9
10
11
12
13
14
15
16
17
# File 'lib/bridgetown-core/concerns/site/localizable.rb', line 8

def locale
  @locale ||= begin
    locale = ENV.fetch("BRIDGETOWN_LOCALE", config[:default_locale]).to_sym
    I18n.load_path += Dir["#{in_source_dir("_locales")}/**/*.{json,rb,yml}"]
    I18n.available_locales = config[:available_locales]
    I18n.default_locale = locale
    I18n.fallbacks = [locale, :en].uniq
    locale
  end
end

#locale=(new_locale) ⇒ Object

Sets the current locale for the site

Parameters:

  • new_locale (String)

    for example: "en" for English, "es" for Spanish



22
23
24
# File 'lib/bridgetown-core/concerns/site/localizable.rb', line 22

def locale=(new_locale)
  I18n.locale = @locale = new_locale.to_sym
end