Sha256: beb7d77f3176eaa17e0df35f9b3684f597f646bfcf3a798591473cfbdfe6c7b6

Contents?: true

Size: 473 Bytes

Versions: 3

Compression:

Stored size: 473 Bytes

Contents

# frozen_string_literal: true

module Phlex::Rails::Helpers::Translate
	module ClassMethods
		def translation_path
			@translation_path ||= name&.dup.tap do |n|
				n.gsub!("::", ".")
				n.gsub!(/([a-z])([A-Z])/, '\1_\2')
				n.downcase!
			end
		end
	end

	def self.included(base)
		base.extend(ClassMethods)
	end

	def translate(key, **)
		key = "#{self.class.translation_path}#{key}" if key.start_with?(".")

		helpers.t(key, **)
	end

	alias_method :t, :translate
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
phlex-rails-2.0.0.rc1 lib/phlex/rails/helpers/translate.rb
phlex-rails-2.0.0.beta2 lib/phlex/rails/helpers/translate.rb
phlex-rails-2.0.0.beta1 lib/phlex/rails/helpers/translate.rb