summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/invidious/helpers/i18n.cr20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/invidious/helpers/i18n.cr b/src/invidious/helpers/i18n.cr
index 5acdcfc5..c3d3fbf4 100644
--- a/src/invidious/helpers/i18n.cr
+++ b/src/invidious/helpers/i18n.cr
@@ -7,8 +7,24 @@ def translate(locale : Hash(String, JSON::Any) | Nil, translation : String, text
# puts "Could not find translation for #{translation.dump}"
# end
- if locale && locale[translation]? && !locale[translation].as_s.empty?
- translation = locale[translation].as_s
+ if locale && locale[translation]?
+ case locale[translation]
+ when .as_h?
+ match_length = 0
+
+ locale[translation].as_h.each do |key, value|
+ if md = text.try &.match(/#{key}/)
+ if md[0].size >= match_length
+ translation = value.as_s
+ match_length = md[0].size
+ end
+ end
+ end
+ when .as_s?
+ if !locale[translation].as_s.empty?
+ translation = locale[translation].as_s
+ end
+ end
end
if text