forked from midou/invidious
Add support for translations
This commit is contained in:
23
src/invidious/helpers/i18n.cr
Normal file
23
src/invidious/helpers/i18n.cr
Normal file
@@ -0,0 +1,23 @@
|
||||
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)
|
||||
if !locale
|
||||
return translation
|
||||
end
|
||||
|
||||
# if !locale[translation]?
|
||||
# puts "Could not find translation for #{translation}"
|
||||
# end
|
||||
|
||||
if locale[translation]? && !locale[translation].as_s.empty?
|
||||
translation = locale[translation].as_s
|
||||
end
|
||||
|
||||
if text
|
||||
translation = translation.gsub("`x`", text)
|
||||
end
|
||||
|
||||
return translation
|
||||
end
|
||||
Reference in New Issue
Block a user