Sha256: 067b2f040be15d737797dcb875233704bd5d381abc2a2fd7f572cf9723c48bbf

Contents?: true

Size: 748 Bytes

Versions: 16

Compression:

Stored size: 748 Bytes

Contents

# frozen_string_literal: true

class Bridgetown::Site
  module Localizable
    # Returns the current and/or default configured locale
    # @return String
    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

    # Sets the current locale for the site
    # @param new_locale [String] for example: "en" for English, "es" for Spanish
    def locale=(new_locale)
      I18n.locale = @locale = new_locale.to_sym
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
bridgetown-core-2.0.0.beta2 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-2.0.0.beta1 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.3.4 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.3.3 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.3.2 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.3.1 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.3.0 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.3.0.beta3 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.3.0.beta2 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.3.0.beta1 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.2.0 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.2.0.beta5 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.2.0.beta4 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.2.0.beta3 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.2.0.beta2 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-1.2.0.beta1 lib/bridgetown-core/concerns/site/localizable.rb