Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Localization for trending iv-org#331 #2529

Merged
merged 6 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions config/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,21 @@ default_user_preferences:
##
#locale: en-US

##
## Default language for content.
SamantazFox marked this conversation as resolved.
Show resolved Hide resolved
##
## 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.
##
Expand Down
1 change: 1 addition & 0 deletions locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"Automatically extend video description: ": "Automatically extend video description: ",
"Interactive 360 degree videos: ": "Interactive 360 degree videos: ",
"Visual preferences": "Visual preferences",
"Content country: ": "Content country: ",
"Player style: ": "Player style: ",
"Dark mode: ": "Dark mode: ",
"Theme: ": "Theme: ",
Expand Down
2 changes: 2 additions & 0 deletions src/invidious/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct ConfigPreferences
property default_home : String? = "Popular"
property feed_menu : Array(String) = ["Popular", "Trending", "Subscriptions", "Playlists"]
property automatic_instance_redirect : Bool = false
property region : String = "US"
property related_videos : Bool = true
property sort : String = "published"
property speed : Float32 = 1.0_f32
Expand Down Expand Up @@ -72,6 +73,7 @@ class Config
property captcha_enabled : Bool = true
property login_enabled : Bool = true
property registration_enabled : Bool = true
property region : String?
SamantazFox marked this conversation as resolved.
Show resolved Hide resolved
property statistics_enabled : Bool = false
property admins : Array(String) = [] of String
property external_port : Int32? = nil
Expand Down
2 changes: 1 addition & 1 deletion src/invidious/routes/feeds.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Invidious::Routes::Feeds
trending_type ||= "Default"

region = env.params.query["region"]?
region ||= "US"
region ||= env.get("preferences").as(Preferences).region

begin
trending, plid = fetch_trending(trending_type, region, locale)
Expand Down
3 changes: 3 additions & 0 deletions src/invidious/routes/preferences.cr
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ module Invidious::Routes::PreferencesRoute
automatic_instance_redirect ||= "off"
automatic_instance_redirect = automatic_instance_redirect == "on"

region = env.params.body["region"]?.try &.as(String)

locale = env.params.body["locale"]?.try &.as(String)
locale ||= CONFIG.default_user_preferences.locale

Expand Down Expand Up @@ -152,6 +154,7 @@ module Invidious::Routes::PreferencesRoute
default_home: default_home,
feed_menu: feed_menu,
automatic_instance_redirect: automatic_instance_redirect,
region: region,
related_videos: related_videos,
sort: sort,
speed: speed,
Expand Down
1 change: 1 addition & 0 deletions src/invidious/user/preferences.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct Preferences

@[JSON::Field(converter: Preferences::ProcessString)]
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)]
property max_results : Int32 = CONFIG.default_user_preferences.max_results
Expand Down
2 changes: 2 additions & 0 deletions src/invidious/videos.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

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"}
SamantazFox marked this conversation as resolved.
Show resolved Hide resolved

# See https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L380-#L476
VIDEO_FORMATS = {
"5" => {"ext" => "flv", "width" => 400, "height" => 240, "acodec" => "mp3", "abr" => 64, "vcodec" => "h263"},
Expand Down
9 changes: 9 additions & 0 deletions src/invidious/views/preferences.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@
</select>
</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">
<label for="player_style"><%= translate(locale, "Player style: ") %></label>
<select name="player_style" id="player_style">
Expand Down