Module: Clacky::I18n

Defined in:
lib/clacky/locales/i18n.rb

Constant Summary collapse

LOCALES =
{
  "zh" => Clacky::Locales::ZH,
  "en" => Clacky::Locales::EN
}.freeze

Class Method Summary collapse

Class Method Details

.localeObject



19
20
21
22
23
24
# File 'lib/clacky/locales/i18n.rb', line 19

def self.locale
  return Thread.current[:lang] if Thread.current[:lang]

  lang = ENV["LC_ALL"] || ENV["LC_MESSAGES"] || ENV["LANG"] || ""
  lang.match?(/\Azh/i) ? "zh" : "en"
end

.t(key, **vars) ⇒ Object



13
14
15
16
17
# File 'lib/clacky/locales/i18n.rb', line 13

def self.t(key, **vars)
  table = LOCALES[locale] || LOCALES["en"]
  msg   = table[key] || LOCALES["en"][key] || key
  vars.empty? ? msg : format(msg, **vars)
end