Merge pull request #2576 from SamantazFox/fix-locales-handling

Fix locales handling
This commit is contained in:
Samantaz Fox 2021-12-12 22:26:22 +01:00 committed by GitHub
commit ee91effb7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 225 additions and 181 deletions

View file

@ -69,11 +69,28 @@
"preferences_local_label": "Proxy videos: ", "preferences_local_label": "Proxy videos: ",
"preferences_speed_label": "Default speed: ", "preferences_speed_label": "Default speed: ",
"preferences_quality_label": "Preferred video quality: ", "preferences_quality_label": "Preferred video quality: ",
"preferences_quality_option_dash": "DASH (adaptative quality)",
"preferences_quality_option_hd720": "HD720",
"preferences_quality_option_medium": "Medium",
"preferences_quality_option_small": "Small",
"preferences_quality_dash_label": "Preferred dash video quality: ", "preferences_quality_dash_label": "Preferred dash video quality: ",
"preferences_quality_dash_option_auto": "Auto",
"preferences_quality_dash_option_best": "Best",
"preferences_quality_dash_option_worst": "Worst",
"preferences_quality_dash_option_4320p": "4320p",
"preferences_quality_dash_option_2160p": "2160p",
"preferences_quality_dash_option_1440p": "1440p",
"preferences_quality_dash_option_1080p": "1080p",
"preferences_quality_dash_option_720p": "720p",
"preferences_quality_dash_option_480p": "480p",
"preferences_quality_dash_option_360p": "360p",
"preferences_quality_dash_option_240p": "240p",
"preferences_quality_dash_option_144p": "144p",
"preferences_volume_label": "Player volume: ", "preferences_volume_label": "Player volume: ",
"preferences_comments_label": "Default comments: ", "preferences_comments_label": "Default comments: ",
"youtube": "YouTube", "youtube": "YouTube",
"reddit": "Reddit", "reddit": "Reddit",
"invidious": "Invidious",
"preferences_captions_label": "Default captions: ", "preferences_captions_label": "Default captions: ",
"Fallback captions: ": "Fallback captions: ", "Fallback captions: ": "Fallback captions: ",
"preferences_related_videos_label": "Show related videos: ", "preferences_related_videos_label": "Show related videos: ",
@ -423,6 +440,8 @@
"4k": "4K", "4k": "4K",
"location": "Location", "location": "Location",
"hdr": "HDR", "hdr": "HDR",
"purchased" : "Purchased",
"360" : "360°",
"filter": "Filter", "filter": "Filter",
"Current version: ": "Current version: ", "Current version: ": "Current version: ",
"next_steps_error_message": "After which you should try to: ", "next_steps_error_message": "After which you should try to: ",
@ -433,5 +452,14 @@
"footer_source_code": "Source code", "footer_source_code": "Source code",
"footer_original_source_code": "Original source code", "footer_original_source_code": "Original source code",
"footer_modfied_source_code": "Modified Source code", "footer_modfied_source_code": "Modified Source code",
"adminprefs_modified_source_code_url_label": "URL to modified source code repository" "adminprefs_modified_source_code_url_label": "URL to modified source code repository",
"none": "none",
"videoinfo_started_streaming_x_ago": "Started streaming `x` ago",
"videoinfo_watch_on_youTube": "Watch on YouTube",
"videoinfo_youTube_embed_link": "Embed",
"videoinfo_invidious_embed_link": "Embed Link",
"download_subtitles": "Subtitles - `x` (.vtt)",
"user_created_playlists": "`x` created playlists",
"user_saved_playlists": "`x` saved playlists",
"Video unavailable": "Video unavailable"
} }

View file

@ -408,7 +408,7 @@ define_video_playback_routes()
# Users # Users
post "/watch_ajax" do |env| post "/watch_ajax" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -478,7 +478,7 @@ end
# /modify_notifications?receive_all_updates=false&receive_no_updates=false # /modify_notifications?receive_all_updates=false&receive_no_updates=false
# will "unding" all subscriptions. # will "unding" all subscriptions.
get "/modify_notifications" do |env| get "/modify_notifications" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -551,7 +551,7 @@ get "/modify_notifications" do |env|
end end
post "/subscription_ajax" do |env| post "/subscription_ajax" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -621,7 +621,7 @@ post "/subscription_ajax" do |env|
end end
get "/subscription_manager" do |env| get "/subscription_manager" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -724,7 +724,7 @@ get "/subscription_manager" do |env|
end end
get "/data_control" do |env| get "/data_control" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
referer = get_referer(env) referer = get_referer(env)
@ -739,7 +739,7 @@ get "/data_control" do |env|
end end
post "/data_control" do |env| post "/data_control" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
referer = get_referer(env) referer = get_referer(env)
@ -902,7 +902,7 @@ post "/data_control" do |env|
end end
get "/change_password" do |env| get "/change_password" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -920,7 +920,7 @@ get "/change_password" do |env|
end end
post "/change_password" do |env| post "/change_password" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -976,7 +976,7 @@ post "/change_password" do |env|
end end
get "/delete_account" do |env| get "/delete_account" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -994,7 +994,7 @@ get "/delete_account" do |env|
end end
post "/delete_account" do |env| post "/delete_account" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -1028,7 +1028,7 @@ post "/delete_account" do |env|
end end
get "/clear_watch_history" do |env| get "/clear_watch_history" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -1046,7 +1046,7 @@ get "/clear_watch_history" do |env|
end end
post "/clear_watch_history" do |env| post "/clear_watch_history" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -1071,7 +1071,7 @@ post "/clear_watch_history" do |env|
end end
get "/authorize_token" do |env| get "/authorize_token" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -1099,7 +1099,7 @@ get "/authorize_token" do |env|
end end
post "/authorize_token" do |env| post "/authorize_token" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -1147,7 +1147,7 @@ post "/authorize_token" do |env|
end end
get "/token_manager" do |env| get "/token_manager" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -1165,7 +1165,7 @@ get "/token_manager" do |env|
end end
post "/token_ajax" do |env| post "/token_ajax" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -1225,7 +1225,7 @@ end
{"/channel/:ucid/live", "/user/:user/live", "/c/:user/live"}.each do |route| {"/channel/:ucid/live", "/user/:user/live", "/c/:user/live"}.each do |route|
get route do |env| get route do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
# Appears to be a bug in routing, having several routes configured # Appears to be a bug in routing, having several routes configured
# as `/a/:a`, `/b/:a`, `/c/:a` results in 404 # as `/a/:a`, `/b/:a`, `/c/:a` results in 404
@ -1347,7 +1347,7 @@ error 404 do |env|
end end
error 500 do |env, ex| error 500 do |env, ex|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
error_template(500, ex) error_template(500, ex)
end end

View file

@ -22,7 +22,7 @@ def github_details(summary : String, content : String)
return HTML.escape(details) return HTML.escape(details)
end end
def error_template_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception) def error_template_helper(env : HTTP::Server::Context, locale : String?, status_code : Int32, exception : Exception)
if exception.is_a?(InfoException) if exception.is_a?(InfoException)
return error_template_helper(env, locale, status_code, exception.message || "") return error_template_helper(env, locale, status_code, exception.message || "")
end end
@ -46,7 +46,7 @@ def error_template_helper(env : HTTP::Server::Context, locale : Hash(String, JSO
return templated "error" return templated "error"
end end
def error_template_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String) def error_template_helper(env : HTTP::Server::Context, locale : String?, status_code : Int32, message : String)
env.response.content_type = "text/html" env.response.content_type = "text/html"
env.response.status_code = status_code env.response.status_code = status_code
error_message = translate(locale, message) error_message = translate(locale, message)
@ -58,7 +58,7 @@ macro error_atom(*args)
error_atom_helper(env, locale, {{*args}}) error_atom_helper(env, locale, {{*args}})
end end
def error_atom_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception) def error_atom_helper(env : HTTP::Server::Context, locale : String?, status_code : Int32, exception : Exception)
if exception.is_a?(InfoException) if exception.is_a?(InfoException)
return error_atom_helper(env, locale, status_code, exception.message || "") return error_atom_helper(env, locale, status_code, exception.message || "")
end end
@ -67,7 +67,7 @@ def error_atom_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::A
return "<error>#{exception.inspect_with_backtrace}</error>" return "<error>#{exception.inspect_with_backtrace}</error>"
end end
def error_atom_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String) def error_atom_helper(env : HTTP::Server::Context, locale : String?, status_code : Int32, message : String)
env.response.content_type = "application/atom+xml" env.response.content_type = "application/atom+xml"
env.response.status_code = status_code env.response.status_code = status_code
return "<error>#{message}</error>" return "<error>#{message}</error>"
@ -77,7 +77,7 @@ macro error_json(*args)
error_json_helper(env, locale, {{*args}}) error_json_helper(env, locale, {{*args}})
end end
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception, additional_fields : Hash(String, Object) | Nil) def error_json_helper(env : HTTP::Server::Context, locale : String?, status_code : Int32, exception : Exception, additional_fields : Hash(String, Object) | Nil)
if exception.is_a?(InfoException) if exception.is_a?(InfoException)
return error_json_helper(env, locale, status_code, exception.message || "", additional_fields) return error_json_helper(env, locale, status_code, exception.message || "", additional_fields)
end end
@ -90,11 +90,11 @@ def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::A
return error_message.to_json return error_message.to_json
end end
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, exception : Exception) def error_json_helper(env : HTTP::Server::Context, locale : String?, status_code : Int32, exception : Exception)
return error_json_helper(env, locale, status_code, exception, nil) return error_json_helper(env, locale, status_code, exception, nil)
end end
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String, additional_fields : Hash(String, Object) | Nil) def error_json_helper(env : HTTP::Server::Context, locale : String?, status_code : Int32, message : String, additional_fields : Hash(String, Object) | Nil)
env.response.content_type = "application/json" env.response.content_type = "application/json"
env.response.status_code = status_code env.response.status_code = status_code
error_message = {"error" => message} error_message = {"error" => message}
@ -104,11 +104,11 @@ def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::A
return error_message.to_json return error_message.to_json
end end
def error_json_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil, status_code : Int32, message : String) def error_json_helper(env : HTTP::Server::Context, locale : String?, status_code : Int32, message : String)
error_json_helper(env, locale, status_code, message, nil) error_json_helper(env, locale, status_code, message, nil)
end end
def error_redirect_helper(env : HTTP::Server::Context, locale : Hash(String, JSON::Any) | Nil) def error_redirect_helper(env : HTTP::Server::Context, locale : String?)
request_path = env.request.path request_path = env.request.path
if request_path.starts_with?("/search") || request_path.starts_with?("/watch") || if request_path.starts_with?("/search") || request_path.starts_with?("/watch") ||

View file

@ -190,7 +190,7 @@ def create_notification_stream(env, topics, connection_channel)
connection = Channel(PQ::Notification).new(8) connection = Channel(PQ::Notification).new(8)
connection_channel.send({true, connection}) connection_channel.send({true, connection})
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
since = env.params.query["since"]?.try &.to_i? since = env.params.query["since"]?.try &.to_i?
id = 0 id = 0

View file

@ -1,46 +1,47 @@
# "bn_BD" => load_locale("bn_BD"), # Bengali (Bangladesh) [Incomplete] # "bn_BD" => load_locale("bn_BD"), # Bengali (Bangladesh) [Incomplete]
# "eu" => load_locale("eu"), # Basque [Incomplete] # "eu" => load_locale("eu"), # Basque [Incomplete]
# "si" => load_locale("si"), # Sinhala [Incomplete]
# "sk" => load_locale("sk"), # Slovak [Incomplete] # "sk" => load_locale("sk"), # Slovak [Incomplete]
# "sr" => load_locale("sr"), # Serbian [Incomplete] # "sr" => load_locale("sr"), # Serbian [Incomplete]
# "sr_Cyrl" => load_locale("sr_Cyrl"), # Serbian (cyrillic) [Incomplete] # "sr_Cyrl" => load_locale("sr_Cyrl"), # Serbian (cyrillic) [Incomplete]
LOCALES = { LOCALES_LIST = {
"ar" => load_locale("ar"), # Arabic "ar" => "العربية", # Arabic
"cs" => load_locale("cs"), # Czech "cs" => "Čeština", # Czech
"da" => load_locale("da"), # Danish "da" => "Dansk", # Danish
"de" => load_locale("de"), # German "de" => "Deutsch", # German
"el" => load_locale("el"), # Greek "el" => "Ελληνικά", # Greek
"en-US" => load_locale("en-US"), # English (US) "en-US" => "English", # English
"eo" => load_locale("eo"), # Esperanto "eo" => "Esperanto", # Esperanto
"es" => load_locale("es"), # Spanish "es" => "Español", # Spanish
"fa" => load_locale("fa"), # Persian "fa" => "فارسی", # Persian
"fi" => load_locale("fi"), # Finnish "fi" => "Suomi", # Finnish
"fr" => load_locale("fr"), # French "fr" => "Français", # French
"he" => load_locale("he"), # Hebrew "he" => "עברית", # Hebrew
"hr" => load_locale("hr"), # Croatian "hr" => "Hrvatski", # Croatian
"hu-HU" => load_locale("hu-HU"), # Hungarian "hu-HU" => "Magyar Nyelv", # Hungarian
"id" => load_locale("id"), # Indonesian "id" => "Bahasa Indonesia", # Indonesian
"is" => load_locale("is"), # Icelandic "is" => "Íslenska", # Icelandic
"it" => load_locale("it"), # Italian "it" => "Italiano", # Italian
"ja" => load_locale("ja"), # Japanese "ja" => "日本語", # Japanese
"ko" => load_locale("ko"), # Korean "ko" => "한국어", # Korean
"lt" => load_locale("lt"), # Lithuanian "lt" => "Lietuvių", # Lithuanian
"nb-NO" => load_locale("nb-NO"), # Norwegian Bokmål "nb-NO" => "Norsk bokmål", # Norwegian Bokmål
"nl" => load_locale("nl"), # Dutch "nl" => "Nederlands", # Dutch
"pl" => load_locale("pl"), # Polish "pl" => "Polski", # Polish
"pt" => load_locale("pt"), # Portuguese "pt" => "Português", # Portuguese
"pt-BR" => load_locale("pt-BR"), # Portuguese (Brazil) "pt-BR" => "Português Brasileiro", # Portuguese (Brazil)
"pt-PT" => load_locale("pt-PT"), # Portuguese (Portugal) "pt-PT" => "Português de Portugal", # Portuguese (Portugal)
"ro" => load_locale("ro"), # Romanian "ro" => "Română", # Romanian
"ru" => load_locale("ru"), # Russian "ru" => "русский", # Russian
"sv-SE" => load_locale("sv-SE"), # Swedish "sv-SE" => "Svenska", # Swedish
"tr" => load_locale("tr"), # Turkish "tr" => "Türkçe", # Turkish
"uk" => load_locale("uk"), # Ukrainian "uk" => "Українська", # Ukrainian
"vi" => load_locale("vi"), # Vietnamese "vi" => "Tiếng Việt", # Vietnamese
"zh-CN" => load_locale("zh-CN"), # Chinese (Simplified) "zh-CN" => "汉语", # Chinese (Simplified)
"zh-TW" => load_locale("zh-TW"), # Chinese (Traditional) "zh-TW" => "漢語", # Chinese (Traditional)
} }
LOCALES = load_all_locales()
CONTENT_REGIONS = { CONTENT_REGIONS = {
"AE", "AR", "AT", "AU", "AZ", "BA", "BD", "BE", "BG", "BH", "BO", "BR", "BY", "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", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "DZ", "EC", "EE",
@ -53,21 +54,39 @@ CONTENT_REGIONS = {
"YE", "ZA", "ZW", "YE", "ZA", "ZW",
} }
def load_locale(name) def load_all_locales
return JSON.parse(File.read("locales/#{name}.json")).as_h locales = {} of String => Hash(String, JSON::Any)
LOCALES_LIST.each_key do |name|
locales[name] = JSON.parse(File.read("locales/#{name}.json")).as_h
end
return locales
end end
def translate(locale : Hash(String, JSON::Any) | Nil, translation : String, text : String | Nil = nil) def translate(locale : String?, key : String, text : String | Nil = nil) : String
# if locale && !locale[translation]? # Log a warning if "key" doesn't exist in en-US locale and return
# puts "Could not find translation for #{translation.dump}" # that key as the text, so this is more or less transparent to the user.
# end if !LOCALES["en-US"].has_key?(key)
LOGGER.warn("i18n: Missing translation key \"#{key}\"")
return key
end
if locale && locale[translation]? # Default to english, whenever the locale doesn't exist,
case locale[translation] # 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? when .as_h?
# Init
translation = ""
match_length = 0 match_length = 0
locale[translation].as_h.each do |key, value| raw_data.as_h.each do |key, value|
if md = text.try &.match(/#{key}/) if md = text.try &.match(/#{key}/)
if md[0].size >= match_length if md[0].size >= match_length
translation = value.as_s translation = value.as_s
@ -76,12 +95,9 @@ def translate(locale : Hash(String, JSON::Any) | Nil, translation : String, text
end end
end end
when .as_s? when .as_s?
if !locale[translation].as_s.empty? translation = raw_data.as_s
translation = locale[translation].as_s
end
else else
raise "Invalid translation #{translation}" raise "Invalid translation \"#{raw_data}\""
end
end end
if text if text
@ -91,7 +107,7 @@ def translate(locale : Hash(String, JSON::Any) | Nil, translation : String, text
return translation return translation
end end
def translate_bool(locale : Hash(String, JSON::Any) | Nil, translation : Bool) def translate_bool(locale : String?, translation : Bool)
case translation case translation
when true when true
return translate(locale, "Yes") return translate(locale, "Yes")

View file

@ -64,7 +64,7 @@ struct SearchVideo
end end
end end
def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) def to_json(locale : String?, json : JSON::Builder)
json.object do json.object do
json.field "type", "video" json.field "type", "video"
json.field "title", self.title json.field "title", self.title
@ -96,7 +96,7 @@ struct SearchVideo
end end
# TODO: remove the locale and follow the crystal convention # TODO: remove the locale and follow the crystal convention
def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) def to_json(locale : String?, _json : Nil)
JSON.build do |json| JSON.build do |json|
to_json(locale, json) to_json(locale, json)
end end
@ -130,7 +130,7 @@ struct SearchPlaylist
property videos : Array(SearchPlaylistVideo) property videos : Array(SearchPlaylistVideo)
property thumbnail : String? property thumbnail : String?
def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) def to_json(locale : String?, json : JSON::Builder)
json.object do json.object do
json.field "type", "playlist" json.field "type", "playlist"
json.field "title", self.title json.field "title", self.title
@ -161,7 +161,7 @@ struct SearchPlaylist
end end
# TODO: remove the locale and follow the crystal convention # TODO: remove the locale and follow the crystal convention
def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) def to_json(locale : String?, _json : Nil)
JSON.build do |json| JSON.build do |json|
to_json(locale, json) to_json(locale, json)
end end
@ -183,7 +183,7 @@ struct SearchChannel
property description_html : String property description_html : String
property auto_generated : Bool property auto_generated : Bool
def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) def to_json(locale : String?, json : JSON::Builder)
json.object do json.object do
json.field "type", "channel" json.field "type", "channel"
json.field "author", self.author json.field "author", self.author
@ -214,7 +214,7 @@ struct SearchChannel
end end
# TODO: remove the locale and follow the crystal convention # TODO: remove the locale and follow the crystal convention
def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) def to_json(locale : String?, _json : Nil)
JSON.build do |json| JSON.build do |json|
to_json(locale, json) to_json(locale, json)
end end
@ -234,7 +234,7 @@ class Category
property description_html : String property description_html : String
property badges : Array(Tuple(String, String))? property badges : Array(Tuple(String, String))?
def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) def to_json(locale : String?, json : JSON::Builder)
json.object do json.object do
json.field "type", "category" json.field "type", "category"
json.field "title", self.title json.field "title", self.title
@ -249,7 +249,7 @@ class Category
end end
# TODO: remove the locale and follow the crystal convention # TODO: remove the locale and follow the crystal convention
def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) def to_json(locale : String?, _json : Nil)
JSON.build do |json| JSON.build do |json|
to_json(locale, json) to_json(locale, json)
end end

View file

@ -36,7 +36,7 @@ module Invidious::Routes::API::V1::Authenticated
env.response.content_type = "application/json" env.response.content_type = "application/json"
user = env.get("user").as(User) user = env.get("user").as(User)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
max_results = env.params.query["max_results"]?.try &.to_i? max_results = env.params.query["max_results"]?.try &.to_i?
max_results ||= user.preferences.max_results max_results ||= user.preferences.max_results
@ -122,7 +122,7 @@ module Invidious::Routes::API::V1::Authenticated
end end
def self.list_playlists(env) def self.list_playlists(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
user = env.get("user").as(User) user = env.get("user").as(User)
@ -141,7 +141,7 @@ module Invidious::Routes::API::V1::Authenticated
def self.create_playlist(env) def self.create_playlist(env)
env.response.content_type = "application/json" env.response.content_type = "application/json"
user = env.get("user").as(User) user = env.get("user").as(User)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
title = env.params.json["title"]?.try &.as(String).delete("<>").byte_slice(0, 150) title = env.params.json["title"]?.try &.as(String).delete("<>").byte_slice(0, 150)
if !title if !title
@ -167,7 +167,7 @@ module Invidious::Routes::API::V1::Authenticated
end end
def self.update_playlist_attribute(env) def self.update_playlist_attribute(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
user = env.get("user").as(User) user = env.get("user").as(User)
@ -200,7 +200,7 @@ module Invidious::Routes::API::V1::Authenticated
end end
def self.delete_playlist(env) def self.delete_playlist(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
user = env.get("user").as(User) user = env.get("user").as(User)
@ -223,7 +223,7 @@ module Invidious::Routes::API::V1::Authenticated
end end
def self.insert_video_into_playlist(env) def self.insert_video_into_playlist(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
user = env.get("user").as(User) user = env.get("user").as(User)
@ -281,7 +281,7 @@ module Invidious::Routes::API::V1::Authenticated
end end
def self.delete_video_in_playlist(env) def self.delete_video_in_playlist(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
user = env.get("user").as(User) user = env.get("user").as(User)
@ -334,7 +334,7 @@ module Invidious::Routes::API::V1::Authenticated
def self.register_token(env) def self.register_token(env)
user = env.get("user").as(User) user = env.get("user").as(User)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
case env.request.headers["Content-Type"]? case env.request.headers["Content-Type"]?
when "application/x-www-form-urlencoded" when "application/x-www-form-urlencoded"
@ -396,7 +396,7 @@ module Invidious::Routes::API::V1::Authenticated
end end
def self.unregister_token(env) def self.unregister_token(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
user = env.get("user").as(User) user = env.get("user").as(User)
scopes = env.get("scopes").as(Array(String)) scopes = env.get("scopes").as(Array(String))

View file

@ -1,6 +1,6 @@
module Invidious::Routes::API::V1::Channels module Invidious::Routes::API::V1::Channels
def self.home(env) def self.home(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
@ -124,7 +124,7 @@ module Invidious::Routes::API::V1::Channels
end end
def self.latest(env) def self.latest(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
@ -146,7 +146,7 @@ module Invidious::Routes::API::V1::Channels
end end
def self.videos(env) def self.videos(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
@ -182,7 +182,7 @@ module Invidious::Routes::API::V1::Channels
end end
def self.playlists(env) def self.playlists(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
@ -219,7 +219,7 @@ module Invidious::Routes::API::V1::Channels
end end
def self.community(env) def self.community(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
@ -242,7 +242,7 @@ module Invidious::Routes::API::V1::Channels
end end
def self.search(env) def self.search(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"

View file

@ -1,6 +1,6 @@
module Invidious::Routes::API::V1::Feeds module Invidious::Routes::API::V1::Feeds
def self.trending(env) def self.trending(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
@ -25,7 +25,7 @@ module Invidious::Routes::API::V1::Feeds
end end
def self.popular(env) def self.popular(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"

View file

@ -1,7 +1,7 @@
module Invidious::Routes::API::V1::Misc module Invidious::Routes::API::V1::Misc
# Stats API endpoint for Invidious # Stats API endpoint for Invidious
def self.stats(env) def self.stats(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
if !CONFIG.statistics_enabled if !CONFIG.statistics_enabled
@ -15,7 +15,7 @@ module Invidious::Routes::API::V1::Misc
# user playlists and Invidious playlists. This means that we can't # user playlists and Invidious playlists. This means that we can't
# reasonably split them yet. This should be addressed in APIv2 # reasonably split them yet. This should be addressed in APIv2
def self.get_playlist(env) def self.get_playlist(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
plid = env.params.url["plid"] plid = env.params.url["plid"]
@ -84,7 +84,7 @@ module Invidious::Routes::API::V1::Misc
end end
def self.mixes(env) def self.mixes(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"

View file

@ -1,6 +1,6 @@
module Invidious::Routes::API::V1::Search module Invidious::Routes::API::V1::Search
def self.search(env) def self.search(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
region = env.params.query["region"]? region = env.params.query["region"]?
env.response.content_type = "application/json" env.response.content_type = "application/json"
@ -43,7 +43,7 @@ module Invidious::Routes::API::V1::Search
end end
def self.search_suggestions(env) def self.search_suggestions(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
region = env.params.query["region"]? region = env.params.query["region"]?
env.response.content_type = "application/json" env.response.content_type = "application/json"

View file

@ -1,6 +1,6 @@
module Invidious::Routes::API::V1::Videos module Invidious::Routes::API::V1::Videos
def self.videos(env) def self.videos(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
@ -20,7 +20,7 @@ module Invidious::Routes::API::V1::Videos
end end
def self.captions(env) def self.captions(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
@ -149,7 +149,7 @@ module Invidious::Routes::API::V1::Videos
# thumbnails for individual scenes in a video. # thumbnails for individual scenes in a video.
# See https://support.jwplayer.com/articles/how-to-add-preview-thumbnails # See https://support.jwplayer.com/articles/how-to-add-preview-thumbnails
def self.storyboards(env) def self.storyboards(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/json" env.response.content_type = "application/json"
@ -223,7 +223,7 @@ module Invidious::Routes::API::V1::Videos
end end
def self.annotations(env) def self.annotations(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "text/xml" env.response.content_type = "text/xml"
@ -293,7 +293,7 @@ module Invidious::Routes::API::V1::Videos
end end
def self.comments(env) def self.comments(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
region = env.params.query["region"]? region = env.params.query["region"]?
env.response.content_type = "application/json" env.response.content_type = "application/json"

View file

@ -104,7 +104,7 @@ module Invidious::Routes::Channels
# Redirects brand url channels to a normal /channel/:ucid route # Redirects brand url channels to a normal /channel/:ucid route
def self.brand_redirect(env) def self.brand_redirect(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
# /attribution_link endpoint needs both the `a` and `u` parameter # /attribution_link endpoint needs both the `a` and `u` parameter
# and in order to avoid detection from YouTube we should only send the required ones # and in order to avoid detection from YouTube we should only send the required ones
@ -148,7 +148,7 @@ module Invidious::Routes::Channels
end end
private def self.fetch_basic_information(env) private def self.fetch_basic_information(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
if user if user

View file

@ -2,7 +2,7 @@
module Invidious::Routes::Embed module Invidious::Routes::Embed
def self.redirect(env) def self.redirect(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
if plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "") if plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")
begin begin
@ -26,7 +26,7 @@ module Invidious::Routes::Embed
end end
def self.show(env) def self.show(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
id = env.params.url["id"] id = env.params.url["id"]
plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "") plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")

View file

@ -6,7 +6,7 @@ module Invidious::Routes::Feeds
end end
def self.playlists(env) def self.playlists(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
referer = get_referer(env) referer = get_referer(env)
@ -31,7 +31,7 @@ module Invidious::Routes::Feeds
end end
def self.popular(env) def self.popular(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
if CONFIG.popular_enabled if CONFIG.popular_enabled
templated "feeds/popular" templated "feeds/popular"
@ -42,7 +42,7 @@ module Invidious::Routes::Feeds
end end
def self.trending(env) def self.trending(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
trending_type = env.params.query["type"]? trending_type = env.params.query["type"]?
trending_type ||= "Default" trending_type ||= "Default"
@ -60,7 +60,7 @@ module Invidious::Routes::Feeds
end end
def self.subscriptions(env) def self.subscriptions(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -108,7 +108,7 @@ module Invidious::Routes::Feeds
end end
def self.history(env) def self.history(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
referer = get_referer(env) referer = get_referer(env)
@ -137,7 +137,7 @@ module Invidious::Routes::Feeds
# RSS feeds # RSS feeds
def self.rss_channel(env) def self.rss_channel(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.headers["Content-Type"] = "application/atom+xml" env.response.headers["Content-Type"] = "application/atom+xml"
env.response.content_type = "application/atom+xml" env.response.content_type = "application/atom+xml"
@ -209,7 +209,7 @@ module Invidious::Routes::Feeds
end end
def self.rss_private(env) def self.rss_private(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.headers["Content-Type"] = "application/atom+xml" env.response.headers["Content-Type"] = "application/atom+xml"
env.response.content_type = "application/atom+xml" env.response.content_type = "application/atom+xml"
@ -253,7 +253,7 @@ module Invidious::Routes::Feeds
end end
def self.rss_playlist(env) def self.rss_playlist(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.headers["Content-Type"] = "application/atom+xml" env.response.headers["Content-Type"] = "application/atom+xml"
env.response.content_type = "application/atom+xml" env.response.content_type = "application/atom+xml"
@ -374,7 +374,7 @@ module Invidious::Routes::Feeds
end end
def self.push_notifications_post(env) def self.push_notifications_post(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
token = env.params.url["token"] token = env.params.url["token"]
body = env.request.body.not_nil!.gets_to_end body = env.request.body.not_nil!.gets_to_end

View file

@ -2,7 +2,7 @@
module Invidious::Routes::Login module Invidious::Routes::Login
def self.login_page(env) def self.login_page(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
@ -31,7 +31,7 @@ module Invidious::Routes::Login
end end
def self.login(env) def self.login(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
referer = get_referer(env, "/feed/subscriptions") referer = get_referer(env, "/feed/subscriptions")
@ -491,7 +491,7 @@ module Invidious::Routes::Login
end end
def self.signout(env) def self.signout(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"

View file

@ -3,7 +3,7 @@
module Invidious::Routes::Misc module Invidious::Routes::Misc
def self.home(env) def self.home(env)
preferences = env.get("preferences").as(Preferences) preferences = env.get("preferences").as(Preferences)
locale = LOCALES[preferences.locale]? locale = preferences.locale
user = env.get? "user" user = env.get? "user"
case preferences.default_home case preferences.default_home
@ -29,12 +29,12 @@ module Invidious::Routes::Misc
end end
def self.privacy(env) def self.privacy(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
templated "privacy" templated "privacy"
end end
def self.licenses(env) def self.licenses(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
rendered "licenses" rendered "licenses"
end end

View file

@ -2,7 +2,7 @@
module Invidious::Routes::Playlists module Invidious::Routes::Playlists
def self.new(env) def self.new(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -18,7 +18,7 @@ module Invidious::Routes::Playlists
end end
def self.create(env) def self.create(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -56,7 +56,7 @@ module Invidious::Routes::Playlists
end end
def self.subscribe(env) def self.subscribe(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
referer = get_referer(env) referer = get_referer(env)
@ -73,7 +73,7 @@ module Invidious::Routes::Playlists
end end
def self.delete_page(env) def self.delete_page(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -96,7 +96,7 @@ module Invidious::Routes::Playlists
end end
def self.delete(env) def self.delete(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -129,7 +129,7 @@ module Invidious::Routes::Playlists
end end
def self.edit(env) def self.edit(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -169,7 +169,7 @@ module Invidious::Routes::Playlists
end end
def self.update(env) def self.update(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -213,7 +213,7 @@ module Invidious::Routes::Playlists
end end
def self.add_playlist_items_page(env) def self.add_playlist_items_page(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -260,7 +260,7 @@ module Invidious::Routes::Playlists
end end
def self.playlist_ajax(env) def self.playlist_ajax(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get? "user" user = env.get? "user"
sid = env.get? "sid" sid = env.get? "sid"
@ -387,7 +387,7 @@ module Invidious::Routes::Playlists
end end
def self.show(env) def self.show(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
user = env.get?("user").try &.as(User) user = env.get?("user").try &.as(User)
referer = get_referer(env) referer = get_referer(env)
@ -435,7 +435,7 @@ module Invidious::Routes::Playlists
end end
def self.mix(env) def self.mix(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
rdid = env.params.query["list"]? rdid = env.params.query["list"]?
if !rdid if !rdid

View file

@ -2,7 +2,7 @@
module Invidious::Routes::PreferencesRoute module Invidious::Routes::PreferencesRoute
def self.show(env) def self.show(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
referer = get_referer(env) referer = get_referer(env)
@ -12,7 +12,7 @@ module Invidious::Routes::PreferencesRoute
end end
def self.update(env) def self.update(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
referer = get_referer(env) referer = get_referer(env)
video_loop = env.params.body["video_loop"]?.try &.as(String) video_loop = env.params.body["video_loop"]?.try &.as(String)
@ -227,7 +227,7 @@ module Invidious::Routes::PreferencesRoute
end end
def self.toggle_theme(env) def self.toggle_theme(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
referer = get_referer(env, unroll: false) referer = get_referer(env, unroll: false)
redirect = env.params.query["redirect"]? redirect = env.params.query["redirect"]?

View file

@ -2,7 +2,7 @@
module Invidious::Routes::Search module Invidious::Routes::Search
def self.opensearch(env) def self.opensearch(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
env.response.content_type = "application/opensearchdescription+xml" env.response.content_type = "application/opensearchdescription+xml"
XML.build(indent: " ", encoding: "UTF-8") do |xml| XML.build(indent: " ", encoding: "UTF-8") do |xml|
@ -18,7 +18,7 @@ module Invidious::Routes::Search
end end
def self.results(env) def self.results(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
query = env.params.query["search_query"]? query = env.params.query["search_query"]?
query ||= env.params.query["q"]? query ||= env.params.query["q"]?
@ -37,7 +37,7 @@ module Invidious::Routes::Search
end end
def self.search(env) def self.search(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
region = env.params.query["region"]? region = env.params.query["region"]?
query = env.params.query["search_query"]? query = env.params.query["search_query"]?

View file

@ -1,7 +1,7 @@
module Invidious::Routes::VideoPlayback module Invidious::Routes::VideoPlayback
# /videoplayback # /videoplayback
def self.get_video_playback(env) def self.get_video_playback(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
query_params = env.params.query query_params = env.params.query
fvip = query_params["fvip"]? || "3" fvip = query_params["fvip"]? || "3"

View file

@ -2,7 +2,7 @@
module Invidious::Routes::Watch module Invidious::Routes::Watch
def self.handle(env) def self.handle(env)
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = env.get("preferences").as(Preferences).locale
region = env.params.query["region"]? region = env.params.query["region"]?
if env.params.query.to_s.includes?("%20") || env.params.query.to_s.includes?("+") if env.params.query.to_s.includes?("%20") || env.params.query.to_s.includes?("+")

View file

@ -275,7 +275,7 @@ struct Video
end end
end end
def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder) def to_json(locale : String?, json : JSON::Builder)
json.object do json.object do
json.field "type", "video" json.field "type", "video"
@ -475,7 +475,7 @@ struct Video
end end
# TODO: remove the locale and follow the crystal convention # TODO: remove the locale and follow the crystal convention
def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil) def to_json(locale : String?, _json : Nil)
JSON.build { |json| to_json(locale, json) } JSON.build { |json| to_json(locale, json) }
end end

View file

@ -32,13 +32,11 @@
<% end %> <% end %>
<% preferred_captions.each do |caption| %> <% preferred_captions.each do |caption| %>
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption.name %>&hl=<%= env.get("preferences").as(Preferences).locale %>" <track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption.name %>" label="<%= caption.name %>">
label="<%= caption.name %>">
<% end %> <% end %>
<% captions.each do |caption| %> <% captions.each do |caption| %>
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption.name %>&hl=<%= env.get("preferences").as(Preferences).locale %>" <track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption.name %>" label="<%= caption.name %>">
label="<%= caption.name %>">
<% end %> <% end %>
<% end %> <% end %>
</video> </video>

View file

@ -1,6 +1,6 @@
<div class="flex-right"> <div class="flex-right">
<div class="icon-buttons"> <div class="icon-buttons">
<a title="<%=translate(locale, "Watch on YouTube")%>" href="https://www.youtube.com/watch<%=endpoint_params%>"> <a title="<%=translate(locale, "videoinfo_watch_on_youTube")%>" href="https://www.youtube.com/watch<%=endpoint_params%>">
<i class="icon ion-logo-youtube"></i> <i class="icon ion-logo-youtube"></i>
</a> </a>
<a title="<%=translate(locale, "Audio mode")%>" href="/watch<%=endpoint_params%>&listen=1"> <a title="<%=translate(locale, "Audio mode")%>" href="/watch<%=endpoint_params%>&listen=1">

View file

@ -6,7 +6,7 @@
<div class="pure-g h-box"> <div class="pure-g h-box">
<div class="pure-u-2-3"> <div class="pure-u-2-3">
<h3><%= translate(locale, "`x` created playlists", %(<span id="count">#{items_created.size}</span>)) %></h3> <h3><%= translate(locale, "user_created_playlists", %(<span id="count">#{items_created.size}</span>)) %></h3>
</div> </div>
<div class="pure-u-1-3" style="text-align:right"> <div class="pure-u-1-3" style="text-align:right">
<h3> <h3>
@ -23,7 +23,7 @@
<div class="pure-g h-box"> <div class="pure-g h-box">
<div class="pure-u-1"> <div class="pure-u-1">
<h3><%= translate(locale, "`x` saved playlists", %(<span id="count">#{items_saved.size}</span>)) %></h3> <h3><%= translate(locale, "user_saved_playlists", %(<span id="count">#{items_saved.size}</span>)) %></h3>
</div> </div>
</div> </div>

View file

@ -51,7 +51,7 @@
<select name="quality" id="quality"> <select name="quality" id="quality">
<% {"dash", "hd720", "medium", "small"}.each do |option| %> <% {"dash", "hd720", "medium", "small"}.each do |option| %>
<% if !(option == "dash" && CONFIG.disabled?("dash")) %> <% if !(option == "dash" && CONFIG.disabled?("dash")) %>
<option value="<%= option %>" <% if preferences.quality == option %> selected <% end %>><%= translate(locale, option) %></option> <option value="<%= option %>" <% if preferences.quality == option %> selected <% end %>><%= translate(locale, "preferences_quality_option_" + option) %></option>
<% end %> <% end %>
<% end %> <% end %>
</select> </select>
@ -62,7 +62,7 @@
<label for="quality_dash"><%= translate(locale, "preferences_quality_dash_label") %></label> <label for="quality_dash"><%= translate(locale, "preferences_quality_dash_label") %></label>
<select name="quality_dash" id="quality_dash"> <select name="quality_dash" id="quality_dash">
<% {"auto", "best", "4320p", "2160p", "1440p", "1080p", "720p", "480p", "360p", "240p", "144p", "worst"}.each do |option| %> <% {"auto", "best", "4320p", "2160p", "1440p", "1080p", "720p", "480p", "360p", "240p", "144p", "worst"}.each do |option| %>
<option value="<%= option %>" <% if preferences.quality_dash == option %> selected <% end %>><%= translate(locale, option) %></option> <option value="<%= option %>" <% if preferences.quality_dash == option %> selected <% end %>><%= translate(locale, "preferences_quality_dash_option_" + option) %></option>
<% end %> <% end %>
</select> </select>
</div> </div>
@ -121,8 +121,8 @@
<div class="pure-control-group"> <div class="pure-control-group">
<label for="locale"><%= translate(locale, "preferences_locale_label") %></label> <label for="locale"><%= translate(locale, "preferences_locale_label") %></label>
<select name="locale" id="locale"> <select name="locale" id="locale">
<% LOCALES.each_key do |option| %> <% LOCALES_LIST.each do |iso_name, full_name| %>
<option value="<%= option %>" <% if preferences.locale == option %> selected <% end %>><%= option %></option> <option value="<%= iso_name %>" <% if preferences.locale == iso_name %> selected <% end %>><%= HTML.escape(full_name) %></option>
<% end %> <% end %>
</select> </select>
</div> </div>

View file

@ -19,8 +19,10 @@
<link rel="stylesheet" href="/css/default.css?v=<%= ASSET_COMMIT %>"> <link rel="stylesheet" href="/css/default.css?v=<%= ASSET_COMMIT %>">
</head> </head>
<% locale = LOCALES[env.get("preferences").as(Preferences).locale]? %> <%
<% dark_mode = env.get("preferences").as(Preferences).dark_mode %> locale = env.get("preferences").as(Preferences).locale
dark_mode = env.get("preferences").as(Preferences).dark_mode
%>
<body class="<%= dark_mode.blank? ? "no" : dark_mode %>-theme"> <body class="<%= dark_mode.blank? ? "no" : dark_mode %>-theme">
<span style="display:none" id="dark_mode_pref"><%= env.get("preferences").as(Preferences).dark_mode %></span> <span style="display:none" id="dark_mode_pref"><%= env.get("preferences").as(Preferences).dark_mode %></span>

View file

@ -103,7 +103,7 @@ we're going to need to do it here in order to allow for translations.
</h3> </h3>
<% elsif video.live_now %> <% elsif video.live_now %>
<h3> <h3>
<%= video.premiere_timestamp.try { |t| translate(locale, "Started streaming `x` ago", recode_date((Time.utc - t).ago, locale)) } %> <%= video.premiere_timestamp.try { |t| translate(locale, "videoinfo_started_streaming_x_ago", recode_date((Time.utc - t).ago, locale)) } %>
</h3> </h3>
<% end %> <% end %>
</div> </div>
@ -112,8 +112,8 @@ we're going to need to do it here in order to allow for translations.
<div class="pure-u-1 pure-u-lg-1-5"> <div class="pure-u-1 pure-u-lg-1-5">
<div class="h-box"> <div class="h-box">
<span id="watch-on-youtube"> <span id="watch-on-youtube">
<a href="https://www.youtube.com/watch?v=<%= video.id %>"><%= translate(locale, "Watch on YouTube") %></a> <a href="https://www.youtube.com/watch?v=<%= video.id %>"><%= translate(locale, "videoinfo_watch_on_youTube") %></a>
(<a href="https://www.youtube.com/embed/<%= video.id %>"><%= translate(locale, "Embed") %></a>) (<a href="https://www.youtube.com/embed/<%= video.id %>"><%= translate(locale, "videoinfo_youTube_embed_link") %></a>)
</span> </span>
<p id="watch-on-another-invidious-instance"> <p id="watch-on-another-invidious-instance">
<% if env.get("preferences").as(Preferences).automatic_instance_redirect%> <% if env.get("preferences").as(Preferences).automatic_instance_redirect%>
@ -123,7 +123,7 @@ we're going to need to do it here in order to allow for translations.
<% end %> <% end %>
</p> </p>
<p id="embed-link"> <p id="embed-link">
<a href="<%= embed_link %>"><%= translate(locale, "Embed Link") %></a> <a href="<%= embed_link %>"><%= translate(locale, "videoinfo_invidious_embed_link") %></a>
</p> </p>
<p id="annotations"> <p id="annotations">
<% if params.annotations %> <% if params.annotations %>
@ -189,7 +189,7 @@ we're going to need to do it here in order to allow for translations.
<% end %> <% end %>
<% captions.each do |caption| %> <% captions.each do |caption| %>
<option value='{"id":"<%= video.id %>","label":"<%= caption.name %>","title":"<%= URI.encode_www_form(video.title) %>-<%= video.id %>.<%= caption.language_code %>.vtt"}'> <option value='{"id":"<%= video.id %>","label":"<%= caption.name %>","title":"<%= URI.encode_www_form(video.title) %>-<%= video.id %>.<%= caption.language_code %>.vtt"}'>
<%= translate(locale, "Subtitles - `x` (.vtt)", caption.name) %> <%= translate(locale, "download_subtitles", translate(locale, caption.name)) %>
</option> </option>
<% end %> <% end %>
</select> </select>