diff --git a/scripts/generate_js_licenses.cr b/scripts/generate_js_licenses.cr
index 1f4ffa624..7df70bf2a 100644
--- a/scripts/generate_js_licenses.cr
+++ b/scripts/generate_js_licenses.cr
@@ -24,7 +24,7 @@ def create_licence_tr(path, file_name, licence_name, licence_link, source_locati
"
-
#{translate(locale, "crash_page_you_found_a_bug")}
+
#{I18n.translate(locale, "crash_page_you_found_a_bug")}
-
#{translate(locale, "crash_page_before_reporting")}
+
#{I18n.translate(locale, "crash_page_before_reporting")}
- - #{translate(locale, "crash_page_refresh", env.request.resource)}
- - #{translate(locale, "crash_page_switch_instance", url_switch)}
- - #{translate(locale, "crash_page_read_the_faq", url_faq)}
- - #{translate(locale, "crash_page_search_issue", url_search_issues)}
+ - #{I18n.translate(locale, "crash_page_refresh", env.request.resource)}
+ - #{I18n.translate(locale, "crash_page_switch_instance", url_switch)}
+ - #{I18n.translate(locale, "crash_page_read_the_faq", url_faq)}
+ - #{I18n.translate(locale, "crash_page_search_issue", url_search_issues)}
-
#{translate(locale, "crash_page_report_issue", url_new_issue)}
+
#{I18n.translate(locale, "crash_page_report_issue", url_new_issue)}
#{issue_template}
@@ -95,7 +95,7 @@ def error_template_helper(env : HTTP::Server::Context, status_code : Int32, mess
locale = env.get("preferences").as(Preferences).locale
- error_message = translate(locale, message)
+ error_message = I18n.translate(locale, message)
next_steps = error_redirect_helper(env)
return templated "error"
@@ -186,10 +186,10 @@ def error_redirect_helper(env : HTTP::Server::Context)
if request_path.starts_with?("/search") || request_path.starts_with?("/watch") ||
request_path.starts_with?("/channel") || request_path.starts_with?("/playlist?list=PL")
- next_steps_text = translate(locale, "next_steps_error_message")
- refresh = translate(locale, "next_steps_error_message_refresh")
- go_to_youtube = translate(locale, "next_steps_error_message_go_to_youtube")
- switch_instance = translate(locale, "Switch Invidious Instance")
+ next_steps_text = I18n.translate(locale, "next_steps_error_message")
+ refresh = I18n.translate(locale, "next_steps_error_message_refresh")
+ go_to_youtube = I18n.translate(locale, "next_steps_error_message_go_to_youtube")
+ switch_instance = I18n.translate(locale, "Switch Invidious Instance")
return <<-END_HTML
#{next_steps_text}
diff --git a/src/invidious/helpers/i18n.cr b/src/invidious/helpers/i18n.cr
index bca2edda9..88aba2ffb 100644
--- a/src/invidious/helpers/i18n.cr
+++ b/src/invidious/helpers/i18n.cr
@@ -1,199 +1,203 @@
-# Languages requiring a better level of translation (at least 20%)
-# to be added to the list below:
-#
-# "af" => "", # Afrikaans
-# "az" => "", # Azerbaijani
-# "be" => "", # Belarusian
-# "bn_BD" => "", # Bengali (Bangladesh)
-# "ia" => "", # Interlingua
-# "or" => "", # Odia
-# "tk" => "", # Turkmen
-# "tok => "", # Toki Pona
-#
-LOCALES_LIST = {
- "ar" => "العربية", # Arabic
- "bg" => "български", # Bulgarian
- "bn" => "বাংলা", # Bengali
- "ca" => "Català", # Catalan
- "cs" => "Čeština", # Czech
- "cy" => "Cymraeg", # Welsh
- "da" => "Dansk", # Danish
- "de" => "Deutsch", # German
- "el" => "Ελληνικά", # Greek
- "en-US" => "English", # English
- "eo" => "Esperanto", # Esperanto
- "es" => "Español", # Spanish
- "et" => "Eesti keel", # Estonian
- "eu" => "Euskara", # Basque
- "fa" => "فارسی", # Persian
- "fi" => "Suomi", # Finnish
- "fr" => "Français", # French
- "he" => "עברית", # Hebrew
- "hi" => "हिन्दी", # Hindi
- "hr" => "Hrvatski", # Croatian
- "hu-HU" => "Magyar Nyelv", # Hungarian
- "id" => "Bahasa Indonesia", # Indonesian
- "is" => "Íslenska", # Icelandic
- "it" => "Italiano", # Italian
- "ja" => "日本語", # Japanese
- "ko" => "한국어", # Korean
- "lmo" => "Lombard", # Lombard
- "lt" => "Lietuvių", # Lithuanian
- "nb-NO" => "Norsk bokmål", # Norwegian Bokmål
- "nl" => "Nederlands", # Dutch
- "pl" => "Polski", # Polish
- "pt" => "Português", # Portuguese
- "pt-BR" => "Português Brasileiro", # Portuguese (Brazil)
- "pt-PT" => "Português de Portugal", # Portuguese (Portugal)
- "ro" => "Română", # Romanian
- "ru" => "Русский", # Russian
- "si" => "සිංහල", # Sinhala
- "sk" => "Slovenčina", # Slovak
- "sl" => "Slovenščina", # Slovenian
- "sq" => "Shqip", # Albanian
- "sr" => "Srpski (latinica)", # Serbian (Latin)
- "sr_Cyrl" => "Српски (ћирилица)", # Serbian (Cyrillic)
- "sv-SE" => "Svenska", # Swedish
- "ta" => "தமிழ்", # Tamil
- "tr" => "Türkçe", # Turkish
- "uk" => "Українська", # Ukrainian
- "vi" => "Tiếng Việt", # Vietnamese
- "zh-CN" => "汉语", # Chinese (Simplified)
- "zh-TW" => "漢語", # Chinese (Traditional)
-}
-
-LOCALES = load_all_locales()
-
-CONTENT_REGIONS = {
- "AE", "AR", "AT", "AU", "AZ", "BA", "BD", "BE", "BG", "BH", "BO", "BR", "BY",
- "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE",
- "EG", "ES", "FI", "FR", "GB", "GE", "GH", "GR", "GT", "HK", "HN", "HR", "HU",
- "ID", "IE", "IL", "IN", "IQ", "IS", "IT", "JM", "JO", "JP", "KE", "KR", "KW",
- "KZ", "LB", "LI", "LK", "LT", "LU", "LV", "LY", "MA", "ME", "MK", "MT", "MX",
- "MY", "NG", "NI", "NL", "NO", "NP", "NZ", "OM", "PA", "PE", "PG", "PH", "PK",
- "PL", "PR", "PT", "PY", "QA", "RO", "RS", "RU", "SA", "SE", "SG", "SI", "SK",
- "SN", "SV", "TH", "TN", "TR", "TW", "TZ", "UA", "UG", "US", "UY", "VE", "VN",
- "YE", "ZA", "ZW",
-}
-
-# Enum for the different types of number formats
-enum NumberFormatting
- None # Print the number as-is
- Separator # Use a separator for thousands
- Short # Use short notation (k/M/B)
- HtmlSpan # Surround with
-end
-
-def load_all_locales
- locales = {} of String => Hash(String, JSON::Any)
-
- LOCALES_LIST.each_key do |name|
- locales[name] = JSON.parse(File.read("locales/#{name}.json")).as_h
+module I18n
+ extend self
+
+ # Languages requiring a better level of translation (at least 20%)
+ # to be added to the list below:
+ #
+ # "af" => "", # Afrikaans
+ # "az" => "", # Azerbaijani
+ # "be" => "", # Belarusian
+ # "bn_BD" => "", # Bengali (Bangladesh)
+ # "ia" => "", # Interlingua
+ # "or" => "", # Odia
+ # "tk" => "", # Turkmen
+ # "tok => "", # Toki Pona
+ #
+ LOCALES_LIST = {
+ "ar" => "العربية", # Arabic
+ "bg" => "български", # Bulgarian
+ "bn" => "বাংলা", # Bengali
+ "ca" => "Català", # Catalan
+ "cs" => "Čeština", # Czech
+ "cy" => "Cymraeg", # Welsh
+ "da" => "Dansk", # Danish
+ "de" => "Deutsch", # German
+ "el" => "Ελληνικά", # Greek
+ "en-US" => "English", # English
+ "eo" => "Esperanto", # Esperanto
+ "es" => "Español", # Spanish
+ "et" => "Eesti keel", # Estonian
+ "eu" => "Euskara", # Basque
+ "fa" => "فارسی", # Persian
+ "fi" => "Suomi", # Finnish
+ "fr" => "Français", # French
+ "he" => "עברית", # Hebrew
+ "hi" => "हिन्दी", # Hindi
+ "hr" => "Hrvatski", # Croatian
+ "hu-HU" => "Magyar Nyelv", # Hungarian
+ "id" => "Bahasa Indonesia", # Indonesian
+ "is" => "Íslenska", # Icelandic
+ "it" => "Italiano", # Italian
+ "ja" => "日本語", # Japanese
+ "ko" => "한국어", # Korean
+ "lmo" => "Lombard", # Lombard
+ "lt" => "Lietuvių", # Lithuanian
+ "nb-NO" => "Norsk bokmål", # Norwegian Bokmål
+ "nl" => "Nederlands", # Dutch
+ "pl" => "Polski", # Polish
+ "pt" => "Português", # Portuguese
+ "pt-BR" => "Português Brasileiro", # Portuguese (Brazil)
+ "pt-PT" => "Português de Portugal", # Portuguese (Portugal)
+ "ro" => "Română", # Romanian
+ "ru" => "Русский", # Russian
+ "si" => "සිංහල", # Sinhala
+ "sk" => "Slovenčina", # Slovak
+ "sl" => "Slovenščina", # Slovenian
+ "sq" => "Shqip", # Albanian
+ "sr" => "Srpski (latinica)", # Serbian (Latin)
+ "sr_Cyrl" => "Српски (ћирилица)", # Serbian (Cyrillic)
+ "sv-SE" => "Svenska", # Swedish
+ "ta" => "தமிழ்", # Tamil
+ "tr" => "Türkçe", # Turkish
+ "uk" => "Українська", # Ukrainian
+ "vi" => "Tiếng Việt", # Vietnamese
+ "zh-CN" => "汉语", # Chinese (Simplified)
+ "zh-TW" => "漢語", # Chinese (Traditional)
+ }
+
+ LOCALES = load_all_locales()
+
+ CONTENT_REGIONS = {
+ "AE", "AR", "AT", "AU", "AZ", "BA", "BD", "BE", "BG", "BH", "BO", "BR", "BY",
+ "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE",
+ "EG", "ES", "FI", "FR", "GB", "GE", "GH", "GR", "GT", "HK", "HN", "HR", "HU",
+ "ID", "IE", "IL", "IN", "IQ", "IS", "IT", "JM", "JO", "JP", "KE", "KR", "KW",
+ "KZ", "LB", "LI", "LK", "LT", "LU", "LV", "LY", "MA", "ME", "MK", "MT", "MX",
+ "MY", "NG", "NI", "NL", "NO", "NP", "NZ", "OM", "PA", "PE", "PG", "PH", "PK",
+ "PL", "PR", "PT", "PY", "QA", "RO", "RS", "RU", "SA", "SE", "SG", "SI", "SK",
+ "SN", "SV", "TH", "TN", "TR", "TW", "TZ", "UA", "UG", "US", "UY", "VE", "VN",
+ "YE", "ZA", "ZW",
+ }
+
+ # Enum for the different types of number formats
+ enum NumberFormatting
+ None # Print the number as-is
+ Separator # Use a separator for thousands
+ Short # Use short notation (k/M/B)
+ HtmlSpan # Surround with
end
- return locales
-end
+ def load_all_locales
+ locales = {} of String => Hash(String, JSON::Any)
-def translate(locale : String?, key : String, text : String | Hash(String, String) | Nil = nil) : String
- # Log a warning if "key" doesn't exist in en-US locale and return
- # that key as the text, so this is more or less transparent to the user.
- if !LOCALES["en-US"].has_key?(key)
- LOGGER.warn("i18n: Missing translation key \"#{key}\"")
- return key
- end
+ LOCALES_LIST.each_key do |name|
+ locales[name] = JSON.parse(File.read("locales/#{name}.json")).as_h
+ end
- # Default to english, whenever the locale doesn't exist,
- # or the key requested has not been translated
- if locale && LOCALES.has_key?(locale) && LOCALES[locale].has_key?(key)
- raw_data = LOCALES[locale][key]
- else
- raw_data = LOCALES["en-US"][key]
+ return locales
end
- case raw_data
- when .as_h?
- # Init
- translation = ""
- match_length = 0
-
- raw_data.as_h.each do |hash_key, value|
- if text.is_a?(String)
- if md = text.try &.match(/#{hash_key}/)
- if md[0].size >= match_length
- translation = value.as_s
- match_length = md[0].size
+ def translate(locale : String?, key : String, text : String | Hash(String, String) | Nil = nil) : String
+ # Log a warning if "key" doesn't exist in en-US locale and return
+ # that key as the text, so this is more or less transparent to the user.
+ if !LOCALES["en-US"].has_key?(key)
+ LOGGER.warn("i18n: Missing translation key \"#{key}\"")
+ return key
+ end
+
+ # Default to english, whenever the locale doesn't exist,
+ # or the key requested has not been translated
+ if locale && LOCALES.has_key?(locale) && LOCALES[locale].has_key?(key)
+ raw_data = LOCALES[locale][key]
+ else
+ raw_data = LOCALES["en-US"][key]
+ end
+
+ case raw_data
+ when .as_h?
+ # Init
+ translation = ""
+ match_length = 0
+
+ raw_data.as_h.each do |hash_key, value|
+ if text.is_a?(String)
+ if md = text.try &.match(/#{hash_key}/)
+ if md[0].size >= match_length
+ translation = value.as_s
+ match_length = md[0].size
+ end
end
end
end
+ when .as_s?
+ translation = raw_data.as_s
+ else
+ raise "Invalid translation \"#{raw_data}\""
end
- when .as_s?
- translation = raw_data.as_s
- else
- raise "Invalid translation \"#{raw_data}\""
- end
- if text.is_a?(String)
- translation = translation.gsub("`x`", text)
- elsif text.is_a?(Hash(String, String))
- # adds support for multi string interpolation. Based on i18next https://www.i18next.com/translation-function/interpolation#basic
- text.each_key do |hash_key|
- translation = translation.gsub("{{#{hash_key}}}", text[hash_key])
+ if text.is_a?(String)
+ translation = translation.gsub("`x`", text)
+ elsif text.is_a?(Hash(String, String))
+ # adds support for multi string interpolation. Based on i18next https://www.i18next.com/translation-function/interpolation#basic
+ text.each_key do |hash_key|
+ translation = translation.gsub("{{#{hash_key}}}", text[hash_key])
+ end
end
+
+ return translation
end
- return translation
-end
+ def translate_count(locale : String, key : String, count : Int, format = NumberFormatting::None) : String
+ # Fallback on english if locale doesn't exist
+ locale = "en-US" if !LOCALES.has_key?(locale)
+
+ # Retrieve suffix
+ suffix = I18next::Plurals::RESOLVER.get_suffix(locale, count)
+ plural_key = key + suffix
-def translate_count(locale : String, key : String, count : Int, format = NumberFormatting::None) : String
- # Fallback on english if locale doesn't exist
- locale = "en-US" if !LOCALES.has_key?(locale)
-
- # Retrieve suffix
- suffix = I18next::Plurals::RESOLVER.get_suffix(locale, count)
- plural_key = key + suffix
-
- if LOCALES[locale].has_key?(plural_key)
- translation = LOCALES[locale][plural_key].as_s
- else
- # Try #1: Fallback to singular in the same locale
- singular_suffix = I18next::Plurals::RESOLVER.get_suffix(locale, 1)
-
- if LOCALES[locale].has_key?(key + singular_suffix)
- translation = LOCALES[locale][key + singular_suffix].as_s
- elsif locale != "en-US"
- # Try #2: Fallback to english
- translation = translate_count("en-US", key, count)
+ if LOCALES[locale].has_key?(plural_key)
+ translation = LOCALES[locale][plural_key].as_s
else
- # Return key if we're already in english, as the translation is missing
- LOGGER.warn("i18n: Missing translation key \"#{key}\"")
- return key
+ # Try #1: Fallback to singular in the same locale
+ singular_suffix = I18next::Plurals::RESOLVER.get_suffix(locale, 1)
+
+ if LOCALES[locale].has_key?(key + singular_suffix)
+ translation = LOCALES[locale][key + singular_suffix].as_s
+ elsif locale != "en-US"
+ # Try #2: Fallback to english
+ translation = self.translate_count("en-US", key, count)
+ else
+ # Return key if we're already in english, as the translation is missing
+ LOGGER.warn("i18n: Missing translation key \"#{key}\"")
+ return key
+ end
end
- end
- case format
- when .separator? then count_txt = number_with_separator(count)
- when .short? then count_txt = number_to_short_text(count)
- when .html_span? then count_txt = "
" + count.to_s + ""
- else count_txt = count.to_s
- end
+ case format
+ when .separator? then count_txt = number_with_separator(count)
+ when .short? then count_txt = number_to_short_text(count)
+ when .html_span? then count_txt = "
" + count.to_s + ""
+ else count_txt = count.to_s
+ end
- return translation.gsub("{{count}}", count_txt)
-end
+ return translation.gsub("{{count}}", count_txt)
+ end
-def translate_bool(locale : String?, translation : Bool)
- case translation
- when true
- return translate(locale, "Yes")
- when false
- return translate(locale, "No")
+ def translate_bool(locale : String?, translation : Bool)
+ case translation
+ when true
+ return self.translate(locale, "Yes")
+ when false
+ return self.translate(locale, "No")
+ end
end
-end
-def locale_is_rtl?(locale : String?)
- # Fallback to en-US
- return false if locale.nil?
+ def locale_is_rtl?(locale : String?)
+ # Fallback to en-US
+ return false if locale.nil?
- # Arabic, Persian, Hebrew
- # See https://en.wikipedia.org/wiki/Right-to-left_script#List_of_RTL_scripts
- return {"ar", "fa", "he"}.includes? locale
+ # Arabic, Persian, Hebrew
+ # See https://en.wikipedia.org/wiki/Right-to-left_script#List_of_RTL_scripts
+ return {"ar", "fa", "he"}.includes? locale
+ end
end
diff --git a/src/invidious/helpers/serialized_yt_data.cr b/src/invidious/helpers/serialized_yt_data.cr
index 2796a8dc6..df040d063 100644
--- a/src/invidious/helpers/serialized_yt_data.cr
+++ b/src/invidious/helpers/serialized_yt_data.cr
@@ -115,9 +115,9 @@ struct SearchVideo
json.field "descriptionHtml", self.description_html
json.field "viewCount", self.views
- json.field "viewCountText", translate_count(locale, "generic_views_count", self.views, NumberFormatting::Short)
+ json.field "viewCountText", I18n.translate_count(locale, "generic_views_count", self.views, I18n::NumberFormatting::Short)
json.field "published", self.published.to_unix
- json.field "publishedText", translate(locale, "`x` ago", recode_date(self.published, locale))
+ json.field "publishedText", I18n.translate(locale, "`x` ago", recode_date(self.published, locale))
json.field "lengthSeconds", self.length_seconds
json.field "liveNow", self.badges.live_now?
json.field "premium", self.badges.premium?
@@ -327,8 +327,8 @@ struct ProblematicTimelineItem
xml.element("content", type: "xhtml") do
xml.element("div", xmlns: "http://www.w3.org/1999/xhtml") do
xml.element("div") do
- xml.element("h4") { translate(locale, "timeline_parse_error_placeholder_heading") }
- xml.element("p") { translate(locale, "timeline_parse_error_placeholder_message") }
+ xml.element("h4") { I18n.translate(locale, "timeline_parse_error_placeholder_heading") }
+ xml.element("p") { I18n.translate(locale, "timeline_parse_error_placeholder_message") }
end
xml.element("pre") do
diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr
index 24b20ed96..7a262f849 100644
--- a/src/invidious/helpers/utils.cr
+++ b/src/invidious/helpers/utils.cr
@@ -146,19 +146,19 @@ def recode_date(time : Time, locale)
span = Time.utc - time
if span.total_days > 365.0
- return translate_count(locale, "generic_count_years", span.total_days.to_i // 365)
+ return I18n.translate_count(locale, "generic_count_years", span.total_days.to_i // 365)
elsif span.total_days > 30.0
- return translate_count(locale, "generic_count_months", span.total_days.to_i // 30)
+ return I18n.translate_count(locale, "generic_count_months", span.total_days.to_i // 30)
elsif span.total_days > 7.0
- return translate_count(locale, "generic_count_weeks", span.total_days.to_i // 7)
+ return I18n.translate_count(locale, "generic_count_weeks", span.total_days.to_i // 7)
elsif span.total_hours > 24.0
- return translate_count(locale, "generic_count_days", span.total_days.to_i)
+ return I18n.translate_count(locale, "generic_count_days", span.total_days.to_i)
elsif span.total_minutes > 60.0
- return translate_count(locale, "generic_count_hours", span.total_hours.to_i)
+ return I18n.translate_count(locale, "generic_count_hours", span.total_hours.to_i)
elsif span.total_seconds > 60.0
- return translate_count(locale, "generic_count_minutes", span.total_minutes.to_i)
+ return I18n.translate_count(locale, "generic_count_minutes", span.total_minutes.to_i)
else
- return translate_count(locale, "generic_count_seconds", span.total_seconds.to_i)
+ return I18n.translate_count(locale, "generic_count_seconds", span.total_seconds.to_i)
end
end
diff --git a/src/invidious/jsonify/api_v1/video_json.cr b/src/invidious/jsonify/api_v1/video_json.cr
index ff9ea70ac..e02e06173 100644
--- a/src/invidious/jsonify/api_v1/video_json.cr
+++ b/src/invidious/jsonify/api_v1/video_json.cr
@@ -22,7 +22,7 @@ module Invidious::JSONify::APIv1
json.field "description", video.description
json.field "descriptionHtml", video.description_html
json.field "published", video.published.to_unix
- json.field "publishedText", translate(locale, "`x` ago", recode_date(video.published, locale))
+ json.field "publishedText", I18n.translate(locale, "`x` ago", recode_date(video.published, locale))
json.field "keywords", video.keywords
json.field "viewCount", video.views
@@ -268,7 +268,7 @@ module Invidious::JSONify::APIv1
json.field "viewCountText", rv["short_view_count"]?
json.field "published", rv["published"]?
if rv["published"]?.try &.presence
- json.field "publishedText", translate(locale, "`x` ago", recode_date(Time.parse_rfc3339(rv["published"].to_s), locale))
+ json.field "publishedText", I18n.translate(locale, "`x` ago", recode_date(Time.parse_rfc3339(rv["published"].to_s), locale))
else
json.field "publishedText", ""
end
diff --git a/src/invidious/routes/before_all.cr b/src/invidious/routes/before_all.cr
index 6d374fff0..45b8c91c7 100644
--- a/src/invidious/routes/before_all.cr
+++ b/src/invidious/routes/before_all.cr
@@ -19,7 +19,7 @@ module Invidious::Routes::BeforeAll
preferences = Preferences.from_json(URI.decode_www_form(prefs_cookie.value))
else
if language_header = env.request.headers["Accept-Language"]?
- if language = ANG.language_negotiator.best(language_header, LOCALES.keys)
+ if language = ANG.language_negotiator.best(language_header, I18n::LOCALES.keys)
preferences.locale = language.header
end
end
diff --git a/src/invidious/routes/channels.cr b/src/invidious/routes/channels.cr
index 968d38dc5..a9b476bc8 100644
--- a/src/invidious/routes/channels.cr
+++ b/src/invidious/routes/channels.cr
@@ -354,7 +354,7 @@ module Invidious::Routes::Channels
resolved_url = YoutubeAPI.resolve_url("https://youtube.com#{env.request.path}#{yt_url_params.size > 0 ? "?#{yt_url_params}" : ""}")
ucid = resolved_url["endpoint"]["browseEndpoint"]["browseId"]
rescue ex : InfoException | KeyError
- return error_template(404, translate(locale, "This channel does not exist."))
+ return error_template(404, I18n.translate(locale, "This channel does not exist."))
end
selected_tab = env.params.url["tab"]?
diff --git a/src/invidious/routes/embed.cr b/src/invidious/routes/embed.cr
index ec5a58046..ccd4136fe 100644
--- a/src/invidious/routes/embed.cr
+++ b/src/invidious/routes/embed.cr
@@ -10,7 +10,7 @@ module Invidious::Routes::Embed
videos = get_playlist_videos(playlist, offset: offset)
if videos.empty?
url = "/playlist?list=#{plid}"
- raise NotFoundException.new(translate(locale, "error_video_not_in_playlist", url))
+ raise NotFoundException.new(I18n.translate(locale, "error_video_not_in_playlist", url))
end
first_playlist_video = videos[0].as(PlaylistVideo)
@@ -71,7 +71,7 @@ module Invidious::Routes::Embed
videos = get_playlist_videos(playlist, offset: offset)
if videos.empty?
url = "/playlist?list=#{plid}"
- raise NotFoundException.new(translate(locale, "error_video_not_in_playlist", url))
+ raise NotFoundException.new(I18n.translate(locale, "error_video_not_in_playlist", url))
end
first_playlist_video = videos[0].as(PlaylistVideo)
diff --git a/src/invidious/routes/feeds.cr b/src/invidious/routes/feeds.cr
index ce173760a..a8247d786 100644
--- a/src/invidious/routes/feeds.cr
+++ b/src/invidious/routes/feeds.cr
@@ -37,7 +37,7 @@ module Invidious::Routes::Feeds
if CONFIG.popular_enabled
templated "feeds/popular"
else
- message = translate(locale, "The Popular feed has been disabled by the administrator.")
+ message = I18n.translate(locale, "The Popular feed has been disabled by the administrator.")
templated "message"
end
end
@@ -259,7 +259,7 @@ module Invidious::Routes::Feeds
xml.element("link", "type": "text/html", rel: "alternate", href: "#{HOST_URL}/feed/subscriptions")
xml.element("link", "type": "application/atom+xml", rel: "self",
href: "#{HOST_URL}#{env.request.resource}")
- xml.element("title") { xml.text translate(locale, "Invidious Private Feed for `x`", user.email) }
+ xml.element("title") { xml.text I18n.translate(locale, "Invidious Private Feed for `x`", user.email) }
(notifications + videos).each do |video|
video.to_xml(locale, params, xml)
diff --git a/src/invidious/routes/login.cr b/src/invidious/routes/login.cr
index 674f0a465..01a199d32 100644
--- a/src/invidious/routes/login.cr
+++ b/src/invidious/routes/login.cr
@@ -112,7 +112,7 @@ module Invidious::Routes::Login
user, sid = create_user(sid, email, password)
if language_header = env.request.headers["Accept-Language"]?
- if language = ANG.language_negotiator.best(language_header, LOCALES.keys)
+ if language = ANG.language_negotiator.best(language_header, I18n::LOCALES.keys)
user.preferences.locale = language.header
end
end
diff --git a/src/invidious/views/add_playlist_items.ecr b/src/invidious/views/add_playlist_items.ecr
index 6aea82aec..4d73bdc43 100644
--- a/src/invidious/views/add_playlist_items.ecr
+++ b/src/invidious/views/add_playlist_items.ecr
@@ -8,12 +8,12 @@
diff --git a/src/invidious/views/community.ecr b/src/invidious/views/community.ecr
index 132e636ce..a0fc47f57 100644
--- a/src/invidious/views/community.ecr
+++ b/src/invidious/views/community.ecr
@@ -35,10 +35,10 @@
<%=
{
"ucid" => ucid,
- "youtube_comments_text" => HTML.escape(translate(locale, "View YouTube comments")),
- "comments_text" => HTML.escape(translate(locale, "View `x` comments", "{commentCount}")),
- "hide_replies_text" => HTML.escape(translate(locale, "Hide replies")),
- "show_replies_text" => HTML.escape(translate(locale, "Show replies")),
+ "youtube_comments_text" => HTML.escape(I18n.translate(locale, "View YouTube comments")),
+ "comments_text" => HTML.escape(I18n.translate(locale, "View `x` comments", "{commentCount}")),
+ "hide_replies_text" => HTML.escape(I18n.translate(locale, "Hide replies")),
+ "show_replies_text" => HTML.escape(I18n.translate(locale, "Show replies")),
"preferences" => env.get("preferences").as(Preferences)
}.to_pretty_json
%>
diff --git a/src/invidious/views/components/channel_info.ecr b/src/invidious/views/components/channel_info.ecr
index 97a2d7da2..9395000a4 100644
--- a/src/invidious/views/components/channel_info.ecr
+++ b/src/invidious/views/components/channel_info.ecr
@@ -27,7 +27,7 @@
@@ -40,10 +40,10 @@
<%= Invidious::Frontend::ChannelPage.generate_tabs_links(locale, channel, selected_tab) %>
@@ -53,9 +53,9 @@
<% sort_options.each do |sort| %>
<% end %>
diff --git a/src/invidious/views/components/feed_menu.ecr b/src/invidious/views/components/feed_menu.ecr
index 3dbeaf371..aeaf183b7 100644
--- a/src/invidious/views/components/feed_menu.ecr
+++ b/src/invidious/views/components/feed_menu.ecr
@@ -5,7 +5,7 @@
<% end %>
<% feed_menu.each do |feed| %>
<% end %>
diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr
index a24423df9..ece2efe8a 100644
--- a/src/invidious/views/components/item.ecr
+++ b/src/invidious/views/components/item.ecr
@@ -27,8 +27,8 @@
<% if !item.channel_handle.nil? %>
<%= item.channel_handle %>
<% end %>
-
<%= translate_count(locale, "generic_subscribers_count", item.subscriber_count, NumberFormatting::Separator) %>
- <% if !item.auto_generated && item.channel_handle.nil? %>
<%= translate_count(locale, "generic_videos_count", item.video_count, NumberFormatting::Separator) %>
<% end %>
+
<%= I18n.translate_count(locale, "generic_subscribers_count", item.subscriber_count, I18n::NumberFormatting::Separator) %>
+ <% if !item.auto_generated && item.channel_handle.nil? %>
<%= I18n.translate_count(locale, "generic_videos_count", item.video_count, I18n::NumberFormatting::Separator) %>
<% end %>
<%= item.description_html %>
<% when SearchHashtag %>
<% if !thin_mode %>
@@ -45,13 +45,13 @@
<%- if item.video_count != 0 -%>
-
<%= translate_count(locale, "generic_videos_count", item.video_count, NumberFormatting::Separator) %>
+
<%= I18n.translate_count(locale, "generic_videos_count", item.video_count, I18n::NumberFormatting::Separator) %>
<%- end -%>
<%- if item.channel_count != 0 -%>
-
<%= translate_count(locale, "generic_channels_count", item.channel_count, NumberFormatting::Separator) %>
+
<%= I18n.translate_count(locale, "generic_channels_count", item.channel_count, I18n::NumberFormatting::Separator) %>
<%- end -%>
<% when SearchPlaylist, InvidiousPlaylist %>
@@ -73,7 +73,7 @@
<%- end -%>
-
<%= translate_count(locale, "generic_videos_count", item.video_count, NumberFormatting::Separator) %>
+
<%= I18n.translate_count(locale, "generic_videos_count", item.video_count, I18n::NumberFormatting::Separator) %>
@@ -101,11 +101,11 @@
-
<%=translate(locale, "timeline_parse_error_placeholder_heading")%>
-
<%=translate(locale, "timeline_parse_error_placeholder_message")%>
+
<%=I18n.translate(locale, "timeline_parse_error_placeholder_heading")%>
+
<%=I18n.translate(locale, "timeline_parse_error_placeholder_message")%>
- <%=translate(locale, "timeline_parse_error_show_technical_details")%>
+ <%=I18n.translate(locale, "timeline_parse_error_show_technical_details")%>
<%=get_issue_template(env, item.parse_exception)[1]%>
@@ -168,7 +168,7 @@
<%- if item.responds_to?(:live_now) && item.live_now -%>
-
<%= translate(locale, "LIVE") %>
+
<%= I18n.translate(locale, "LIVE") %>
<%- elsif item.length_seconds != 0 -%>
<%= recode_length_seconds(item.length_seconds) %>
<%- end -%>
@@ -200,15 +200,15 @@
<% if item.responds_to?(:premiere_timestamp) && item.premiere_timestamp.try &.> Time.utc %>
-
<%= translate(locale, "Premieres in `x`", recode_date((item.premiere_timestamp.as(Time) - Time.utc).ago, locale)) %>
+
<%= I18n.translate(locale, "Premieres in `x`", recode_date((item.premiere_timestamp.as(Time) - Time.utc).ago, locale)) %>
<% elsif item.responds_to?(:published) && (Time.utc - item.published) > 1.minute %>
-
<%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %>
+
<%= I18n.translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %>
<% end %>
<% if item.responds_to?(:views) && item.views %>
-
<%= translate_count(locale, "generic_views_count", item.views || 0, NumberFormatting::Short) %>
+
<%= I18n.translate_count(locale, "generic_views_count", item.views || 0, I18n::NumberFormatting::Short) %>
<% end %>
diff --git a/src/invidious/views/components/items_paginated.ecr b/src/invidious/views/components/items_paginated.ecr
index f69df3fe0..bb630d621 100644
--- a/src/invidious/views/components/items_paginated.ecr
+++ b/src/invidious/views/components/items_paginated.ecr
@@ -11,9 +11,9 @@
diff --git a/src/invidious/views/components/search_box.ecr b/src/invidious/views/components/search_box.ecr
index 29da2c523..f957c25cd 100644
--- a/src/invidious/views/components/search_box.ecr
+++ b/src/invidious/views/components/search_box.ecr
@@ -2,11 +2,11 @@
-
diff --git a/src/invidious/views/create_playlist.ecr b/src/invidious/views/create_playlist.ecr
index 807244e6d..feff65221 100644
--- a/src/invidious/views/create_playlist.ecr
+++ b/src/invidious/views/create_playlist.ecr
@@ -1,5 +1,5 @@
<% content_for "header" do %>
-
<%= translate(locale, "Create playlist") %> - Invidious
+
<%= I18n.translate(locale, "Create playlist") %> - Invidious
<% end %>