Feature Request: Localization for trending iv-org#331

This commit is contained in:
Dmitry Sandalov 2021-10-21 14:54:15 +03:00
parent 129779a757
commit d9c58c4837
No known key found for this signature in database
GPG Key ID: 718627D28520CA65
8 changed files with 34 additions and 1 deletions

View File

@ -504,6 +504,21 @@ default_user_preferences:
## ##
#locale: en-US #locale: en-US
##
## Default language for content.
##
## Accepted values:
## 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
##
## Default: US
##
#region: US
## ##
## Top 3 prefered languages for video captions. ## Top 3 prefered languages for video captions.
## ##

View File

@ -80,6 +80,7 @@
"Automatically extend video description: ": "Automatically extend video description: ", "Automatically extend video description: ": "Automatically extend video description: ",
"Interactive 360 degree videos: ": "Interactive 360 degree videos: ", "Interactive 360 degree videos: ": "Interactive 360 degree videos: ",
"Visual preferences": "Visual preferences", "Visual preferences": "Visual preferences",
"Content country: ": "Content country: ",
"Player style: ": "Player style: ", "Player style: ": "Player style: ",
"Dark mode: ": "Dark mode: ", "Dark mode: ": "Dark mode: ",
"Theme: ": "Theme: ", "Theme: ": "Theme: ",

View File

@ -31,6 +31,7 @@ struct ConfigPreferences
property default_home : String? = "Popular" property default_home : String? = "Popular"
property feed_menu : Array(String) = ["Popular", "Trending", "Subscriptions", "Playlists"] property feed_menu : Array(String) = ["Popular", "Trending", "Subscriptions", "Playlists"]
property automatic_instance_redirect : Bool = false property automatic_instance_redirect : Bool = false
property region : String = "US"
property related_videos : Bool = true property related_videos : Bool = true
property sort : String = "published" property sort : String = "published"
property speed : Float32 = 1.0_f32 property speed : Float32 = 1.0_f32
@ -72,6 +73,7 @@ class Config
property captcha_enabled : Bool = true property captcha_enabled : Bool = true
property login_enabled : Bool = true property login_enabled : Bool = true
property registration_enabled : Bool = true property registration_enabled : Bool = true
property region : String?
property statistics_enabled : Bool = false property statistics_enabled : Bool = false
property admins : Array(String) = [] of String property admins : Array(String) = [] of String
property external_port : Int32? = nil property external_port : Int32? = nil

View File

@ -48,7 +48,7 @@ module Invidious::Routes::Feeds
trending_type ||= "Default" trending_type ||= "Default"
region = env.params.query["region"]? region = env.params.query["region"]?
region ||= "US" region ||= env.get("preferences").as(Preferences).region
begin begin
trending, plid = fetch_trending(trending_type, region, locale) trending, plid = fetch_trending(trending_type, region, locale)

View File

@ -102,6 +102,8 @@ module Invidious::Routes::PreferencesRoute
automatic_instance_redirect ||= "off" automatic_instance_redirect ||= "off"
automatic_instance_redirect = automatic_instance_redirect == "on" automatic_instance_redirect = automatic_instance_redirect == "on"
region = env.params.body["region"]?.try &.as(String)
locale = env.params.body["locale"]?.try &.as(String) locale = env.params.body["locale"]?.try &.as(String)
locale ||= CONFIG.default_user_preferences.locale locale ||= CONFIG.default_user_preferences.locale
@ -152,6 +154,7 @@ module Invidious::Routes::PreferencesRoute
default_home: default_home, default_home: default_home,
feed_menu: feed_menu, feed_menu: feed_menu,
automatic_instance_redirect: automatic_instance_redirect, automatic_instance_redirect: automatic_instance_redirect,
region: region,
related_videos: related_videos, related_videos: related_videos,
sort: sort, sort: sort,
speed: speed, speed: speed,

View File

@ -28,6 +28,7 @@ struct Preferences
@[JSON::Field(converter: Preferences::ProcessString)] @[JSON::Field(converter: Preferences::ProcessString)]
property locale : String = CONFIG.default_user_preferences.locale property locale : String = CONFIG.default_user_preferences.locale
property region : String? = CONFIG.region != nil ? CONFIG.region : CONFIG.default_user_preferences.region
@[JSON::Field(converter: Preferences::ClampInt)] @[JSON::Field(converter: Preferences::ClampInt)]
property max_results : Int32 = CONFIG.default_user_preferences.max_results property max_results : Int32 = CONFIG.default_user_preferences.max_results

View File

@ -110,6 +110,8 @@ CAPTION_LANGUAGES = {
REGIONS = {"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"} REGIONS = {"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"}
TRENDING_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"}
# See https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L380-#L476 # See https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L380-#L476
VIDEO_FORMATS = { VIDEO_FORMATS = {
"5" => {"ext" => "flv", "width" => 400, "height" => 240, "acodec" => "mp3", "abr" => 64, "vcodec" => "h263"}, "5" => {"ext" => "flv", "width" => 400, "height" => 240, "acodec" => "mp3", "abr" => 64, "vcodec" => "h263"},

View File

@ -127,6 +127,15 @@
</select> </select>
</div> </div>
<div class="pure-control-group">
<label for="region"><%= translate(locale, "Content country: ") %></label>
<select name="region" id="region">
<% TRENDING_REGIONS.each do |option| %>
<option value="<%= option %>" <% if preferences.region == option %> selected <% end %>><%= option %></option>
<% end %>
</select>
</div>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="player_style"><%= translate(locale, "Player style: ") %></label> <label for="player_style"><%= translate(locale, "Player style: ") %></label>
<select name="player_style" id="player_style"> <select name="player_style" id="player_style">