Sha256: e5fa81ae83f4f711a8fc1731199db3efb07faa5e53406769491d59216388b868

Contents?: true

Size: 698 Bytes

Versions: 14

Compression:

Stored size: 698 Bytes

Contents

# frozen_string_literal: true

class Bridgetown::Site
  module Localizable
    # Returns the current and/or default configured locale
    # @return String
    def locale
      if @locale
        @locale
      else
        @locale = ENV.fetch("BRIDGETOWN_LOCALE", config[:default_locale]).to_sym
        I18n.load_path << Dir[in_source_dir("_locales") + "/*.yml"]
        I18n.available_locales = config[:available_locales]
        I18n.default_locale = @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

14 entries across 14 versions & 1 rubygems

Version Path
bridgetown-core-0.21.0.beta2 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.21.0.beta1 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.20.0 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.19.3 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.19.2 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.19.1 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.19.0 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.18.6 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.18.5 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.18.4 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.18.3 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.18.2 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.18.1 lib/bridgetown-core/concerns/site/localizable.rb
bridgetown-core-0.18.0 lib/bridgetown-core/concerns/site/localizable.rb