Sha256: a76f6316238abb1212594578ae3c40ed9ba5b537703ede76b47761cf3563394a

Contents?: true

Size: 732 Bytes

Versions: 1

Compression:

Stored size: 732 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
        Dir[in_source_dir("_locales") + "/*.yml"].each do |locale_path|
          I18n.load_path << locale_path
        end
        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

1 entries across 1 versions & 1 rubygems

Version Path
bridgetown-core-1.0.0.alpha1 lib/bridgetown-core/concerns/site/localizable.rb