From 6cdb6ec711794c2887da03c0e5d3cfac67bded3f Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sun, 28 Apr 2019 14:50:17 -0500 Subject: Add support for plurlization to locales --- src/invidious/helpers/i18n.cr | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src') 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 -- cgit v1.2.3