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



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

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



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

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