2018-12-20 15:32:09 -06:00
|
|
|
def load_locale(name)
|
|
|
|
return JSON.parse(File.read("locales/#{name}.json")).as_h
|
|
|
|
end
|
|
|
|
|
|
|
|
def translate(locale : Hash(String, JSON::Any) | Nil, translation : String, text : String | Nil = nil)
|
2018-12-20 17:41:42 -06:00
|
|
|
# if locale && !locale[translation]?
|
|
|
|
# puts "Could not find translation for #{translation.dump}"
|
2018-12-20 15:32:09 -06:00
|
|
|
# end
|
|
|
|
|
2018-12-20 16:59:46 -06:00
|
|
|
if locale && locale[translation]? && !locale[translation].as_s.empty?
|
2018-12-20 15:32:09 -06:00
|
|
|
translation = locale[translation].as_s
|
|
|
|
end
|
|
|
|
|
|
|
|
if text
|
|
|
|
translation = translation.gsub("`x`", text)
|
|
|
|
end
|
|
|
|
|
|
|
|
return translation
|
|
|
|
end
|