This commit is contained in:
0x1eef 2024-06-21 21:47:20 -03:00
parent 7442884594
commit 7c5fccce20
2 changed files with 23 additions and 0 deletions

View file

@ -1,6 +1,15 @@
# frozen_string_literal: true
##
# The {Mixin::ERB Mixin::ERB} module provides a method
# that can render an ERB template
module Mixin::ERB
##
# @param [String] file
# The path to an ERB template
# @param [Hash] local_assigns
# Template variables
# @return [String]
def erb(file, local_assigns = {})
erb = File.binread File.join(dirs.content, "html", file)
ctx = binding

View file

@ -1,11 +1,25 @@
# frozen_string_literal: true
##
# The {Mixin::T Mixin::T} module provides a method that
# can render user-facing text strings in different
# locales / languages
module Mixin::T
##
# @param [String] locale
# Locale (eg "en")
# @param [String] key
# Translation key (eg "TheNobleQuran")
# @param [Hash] local_assigns
# Template variables
# @return [String]
def t(locale, key, local_assigns = {})
str = [locale, *key.split(".")].inject(tdata) { _1[_2] }
format(str, local_assigns)
end
private
def tdata
@tdata ||= Ryo.from_json(path: File.join(dirs.content, "json", "t.json"))
end