Sha256: fc14c512d4cc402a36d67450cce63146ccedb0f08dc86cdc8e90fa0003f2d9c5

Contents?: true

Size: 574 Bytes

Versions: 3

Compression:

Stored size: 574 Bytes

Contents

# frozen_string_literal: true

module Bridgetown
  module Filters
    module TranslationFilters
      def t(input, options = "")
        options = string_to_hash(options)
        locale = options.delete(:locale)
        count = options.delete(:count)
        options[:count] = count.to_i unless count.nil?

        I18n.t(input.to_s, locale:, **options)
      rescue ArgumentError
        input
      end

      private

      def string_to_hash(options)
        options.split(",").to_h { |e| e.split(":").map(&:strip) }.transform_keys(&:to_sym)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bridgetown-core-2.0.0.beta3 lib/bridgetown-core/filters/translation_filters.rb
bridgetown-core-2.0.0.beta2 lib/bridgetown-core/filters/translation_filters.rb
bridgetown-core-2.0.0.beta1 lib/bridgetown-core/filters/translation_filters.rb