mirror of
				https://github.com/iv-org/invidious.git
				synced 2025-11-04 06:31:57 +00:00 
			
		
		
		
	Merge pull request #2529 from DmitrySandalov/master
Feature Request: Localization for trending iv-org#331
This commit is contained in:
		@@ -504,6 +504,21 @@ default_user_preferences:
 | 
			
		||||
  ##
 | 
			
		||||
  #locale: en-US
 | 
			
		||||
 | 
			
		||||
  ##
 | 
			
		||||
  ## Default geographical location 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.
 | 
			
		||||
  ##
 | 
			
		||||
 
 | 
			
		||||
@@ -80,6 +80,7 @@
 | 
			
		||||
    "preferences_extend_desc_label": "Automatically extend video description: ",
 | 
			
		||||
    "preferences_vr_mode_label": "Interactive 360 degree videos: ",
 | 
			
		||||
    "preferences_category_visual": "Visual preferences",
 | 
			
		||||
    "preferences_region_label": "Content country: ",
 | 
			
		||||
    "preferences_player_style_label": "Player style: ",
 | 
			
		||||
    "Dark mode: ": "Dark mode: ",
 | 
			
		||||
    "preferences_dark_mode_label": "Theme: ",
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -41,6 +41,18 @@ LOCALES = {
 | 
			
		||||
  "zh-TW" => load_locale("zh-TW"), # Chinese (Traditional)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
def load_locale(name)
 | 
			
		||||
  return JSON.parse(File.read("locales/#{name}.json")).as_h
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,7 @@ struct Preferences
 | 
			
		||||
 | 
			
		||||
  @[JSON::Field(converter: Preferences::ProcessString)]
 | 
			
		||||
  property locale : String = CONFIG.default_user_preferences.locale
 | 
			
		||||
  property region : String? = CONFIG.default_user_preferences.region
 | 
			
		||||
 | 
			
		||||
  @[JSON::Field(converter: Preferences::ClampInt)]
 | 
			
		||||
  property max_results : Int32 = CONFIG.default_user_preferences.max_results
 | 
			
		||||
 
 | 
			
		||||
@@ -127,6 +127,15 @@
 | 
			
		||||
                </select>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <div class="pure-control-group">
 | 
			
		||||
                <label for="region"><%= translate(locale, "preferences_region_label") %></label>
 | 
			
		||||
                <select name="region" id="region">
 | 
			
		||||
                    <% CONTENT_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, "preferences_player_style_label") %></label>
 | 
			
		||||
                <select name="player_style" id="player_style">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user