mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-03 03:46:04 -04:00
Add support for plurlization to locales
This commit is contained in:
parent
03891b66b6
commit
6cdb6ec711
3 changed files with 79 additions and 18 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue