Sha256: 296ccbca9411d6063a27eac6bbd0f85797008db7f3e4b96e721b20e39dc83687

Contents?: true

Size: 446 Bytes

Versions: 5

Compression:

Stored size: 446 Bytes

Contents

# frozen_string_literal: true

module Phlex
	module Translation
		def self.included(view)
			view.extend(ClassMethods)
		end

		module ClassMethods
			attr_writer :translation_path

			def translation_path
				@translation_path ||= name&.split("::")&.join(".")&.downcase.to_s
			end
		end

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

			::I18n.translate(key, **options)
		end
	end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
phlex-translation-0.1.0 lib/phlex/translation.rb
phlex-0.5.3 lib/phlex/translation.rb
phlex-0.5.2 lib/phlex/translation.rb
phlex-0.5.1 lib/phlex/translation.rb
phlex-0.5.0 lib/phlex/translation.rb