al-quran.reflectslight.io/nanoc/lib/mixin/t.rb

16 lines
322 B
Ruby
Raw Normal View History

2023-10-07 08:21:48 +02:00
module Mixin::T
2023-10-07 22:44:58 +02:00
extend Memoize
2023-10-07 15:09:53 +02:00
def t(locale, key, local_assigns = {})
str = [locale, *key.split(".")].inject(i18n) { _1[_2] }
format(str, local_assigns)
2023-10-07 08:21:48 +02:00
end
def i18n
2023-10-07 22:44:58 +02:00
path = File.join(Dir.getwd, "src", "i18n.json")
json = File.binread(path)
Ryo.from JSON.parse(json)
2023-10-07 08:21:48 +02:00
end
2023-10-07 22:44:58 +02:00
memoize :i18n
2023-10-07 08:21:48 +02:00
end