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

27 lines
627 B
Ruby
Raw Permalink Normal View History

2023-10-08 00:16:37 +02:00
# frozen_string_literal: true
2024-06-22 02:47:20 +02:00
##
2024-06-22 04:43:31 +02:00
# The {Utils::T Utils::T} module provides a method that
2024-06-22 02:47:20 +02:00
# can render user-facing text strings in different
# locales / languages
2024-06-22 04:43:31 +02:00
module Utils::T
2024-06-22 02:47:20 +02:00
##
# @param [String] locale
# Locale (eg "en")
# @param [String] key
# Translation key (eg "TheNobleQuran")
# @param [Hash] local_assigns
# Template variables
# @return [String]
2023-10-07 15:09:53 +02:00
def t(locale, key, local_assigns = {})
str = [locale, *key.split(".")].inject(tdata) { _1[_2] }
2023-10-07 15:09:53 +02:00
format(str, local_assigns)
2023-10-07 08:21:48 +02:00
end
2024-06-22 02:47:20 +02:00
private
def tdata
2024-06-22 00:04:17 +02:00
@tdata ||= Ryo.from_json(path: File.join(dirs.content, "json", "t.json"))
2023-10-07 08:21:48 +02:00
end
end