mirror of
https://github.com/iv-org/invidious.git
synced 2025-06-12 13:17:48 +02:00
i18n: Use plurals for video/view/subscriber/subscription counts
This commit is contained in:
@ -158,7 +158,7 @@ def fetch_channel_community(ucid, continuation, locale, format, thin_mode)
|
||||
view_count = attachment["viewCountText"]?.try &.["simpleText"].as_s.gsub(/\D/, "").to_i64? || 0_i64
|
||||
|
||||
json.field "viewCount", view_count
|
||||
json.field "viewCountText", translate(locale, "`x` views", number_to_short_text(view_count))
|
||||
json.field "viewCountText", translate_count(locale, "generic_views_count", view_count, NumberFormatting::Short)
|
||||
end
|
||||
when .has_key?("backstageImageRenderer")
|
||||
attachment = attachment["backstageImageRenderer"]
|
||||
|
@ -54,6 +54,14 @@ CONTENT_REGIONS = {
|
||||
"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 <span id="count"></span>
|
||||
end
|
||||
|
||||
def load_all_locales
|
||||
locales = {} of String => Hash(String, JSON::Any)
|
||||
|
||||
@ -107,7 +115,7 @@ def translate(locale : String?, key : String, text : String | Nil = nil) : Strin
|
||||
return translation
|
||||
end
|
||||
|
||||
def translate_count(locale : String, key : String, count : Int) : String
|
||||
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)
|
||||
|
||||
@ -134,7 +142,14 @@ def translate_count(locale : String, key : String, count : Int) : String
|
||||
end
|
||||
end
|
||||
|
||||
return translation.gsub("{{count}}", count.to_s)
|
||||
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 = "<span id=\"count\">" + count.to_s + "</span>"
|
||||
else count_txt = count.to_s
|
||||
end
|
||||
|
||||
return translation.gsub("{{count}}", count_txt)
|
||||
end
|
||||
|
||||
def translate_bool(locale : String?, translation : Bool)
|
||||
|
@ -10,8 +10,8 @@
|
||||
<% end %>
|
||||
<p dir="auto"><%= HTML.escape(item.author) %></p>
|
||||
</a>
|
||||
<p><%= translate(locale, "`x` subscribers", number_with_separator(item.subscriber_count)) %></p>
|
||||
<% if !item.auto_generated %><p><%= translate(locale, "`x` videos", number_with_separator(item.video_count)) %></p><% end %>
|
||||
<p><%= translate_count(locale, "generic_subscribers_count", item.subscriber_count, NumberFormatting::Separator) %></p>
|
||||
<% if !item.auto_generated %><p><%= translate_count(locale, "generic_videos_count", item.video_count, NumberFormatting::Separator) %></p><% end %>
|
||||
<h5><%= item.description_html %></h5>
|
||||
<% when SearchPlaylist, InvidiousPlaylist %>
|
||||
<% if item.id.starts_with? "RD" %>
|
||||
@ -24,7 +24,7 @@
|
||||
<% if !env.get("preferences").as(Preferences).thin_mode %>
|
||||
<div class="thumbnail">
|
||||
<img loading="lazy" class="thumbnail" src="<%= URI.parse(item.thumbnail || "/").request_target %>"/>
|
||||
<p class="length"><%= number_with_separator(item.video_count) %> videos</p>
|
||||
<p class="length"><%= translate_count(locale, "generic_videos_count", item.video_count, NumberFormatting::Separator) %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
<p dir="auto"><%= HTML.escape(item.title) %></p>
|
||||
@ -94,7 +94,7 @@
|
||||
|
||||
<% if item.responds_to?(:views) && item.views %>
|
||||
<div class="flex-right">
|
||||
<p dir="auto"><%= translate(locale, "`x` views", number_to_short_text(item.views || 0)) %></p>
|
||||
<p dir="auto"><%= translate_count(locale, "generic_views_count", item.views || 0, NumberFormatting::Short) %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
@ -160,7 +160,7 @@
|
||||
|
||||
<% if item.responds_to?(:views) && item.views %>
|
||||
<div class="flex-right">
|
||||
<p class="video-data" dir="auto"><%= translate(locale, "`x` views", number_to_short_text(item.views || 0)) %></p>
|
||||
<p class="video-data" dir="auto"><%= translate_count(locale, "generic_views_count", item.views || 0, NumberFormatting::Short) %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
@ -11,7 +11,7 @@
|
||||
<h3><input class="pure-input-1" maxlength="150" name="title" type="text" value="<%= title %>"></h3>
|
||||
<b>
|
||||
<%= HTML.escape(playlist.author) %> |
|
||||
<%= translate(locale, "`x` videos", "#{playlist.video_count}") %> |
|
||||
<%= translate_count(locale, "generic_videos_count", playlist.video_count) %> |
|
||||
<%= translate(locale, "Updated `x` ago", recode_date(playlist.updated, locale)) %> |
|
||||
<i class="icon <%= {"ion-md-globe", "ion-ios-unlock", "ion-ios-lock"}[playlist.privacy.value] %>"></i>
|
||||
<select name="privacy">
|
||||
|
@ -4,11 +4,11 @@
|
||||
|
||||
<div class="pure-g h-box">
|
||||
<div class="pure-u-1-3">
|
||||
<h3><%= translate(locale, "`x` videos", %(<span id="count">#{user.watched.size}</span>)) %></h3>
|
||||
<h3><%= translate_count(locale, "generic_videos_count", user.watched.size, NumberFormatting::HtmlSpan) %></h3>
|
||||
</div>
|
||||
<div class="pure-u-1-3">
|
||||
<h3 style="text-align:center">
|
||||
<a href="/feed/subscriptions"><%= translate(locale, "`x` subscriptions", %(<span id="count">#{user.subscriptions.size}</span>)) %></a>
|
||||
<a href="/feed/subscriptions"><%= translate_count(locale, "generic_subscriptions_count", user.subscriptions.size, NumberFormatting::HtmlSpan) %></a>
|
||||
</h3>
|
||||
</div>
|
||||
<div class="pure-u-1-3">
|
||||
|
@ -16,7 +16,7 @@
|
||||
<% else %>
|
||||
<%= author %> |
|
||||
<% end %>
|
||||
<%= translate(locale, "`x` videos", "#{playlist.video_count}") %> |
|
||||
<%= translate_count(locale, "generic_videos_count", playlist.video_count) %> |
|
||||
<%= translate(locale, "Updated `x` ago", recode_date(playlist.updated, locale)) %> |
|
||||
<% case playlist.as(InvidiousPlaylist).privacy when %>
|
||||
<% when PlaylistPrivacy::Public %>
|
||||
@ -30,7 +30,7 @@
|
||||
<% else %>
|
||||
<b>
|
||||
<a href="/channel/<%= playlist.ucid %>"><%= author %></a> |
|
||||
<%= translate(locale, "`x` videos", "#{playlist.video_count}") %> |
|
||||
<%= translate_count(locale, "generic_videos_count", playlist.video_count) %> |
|
||||
<%= translate(locale, "Updated `x` ago", recode_date(playlist.updated, locale)) %>
|
||||
</b>
|
||||
<% end %>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<div class="pure-u-1-3">
|
||||
<h3>
|
||||
<a href="/feed/subscriptions">
|
||||
<%= translate(locale, "`x` subscriptions", %(<span id="count">#{subscriptions.size}</span>)) %>
|
||||
<%= translate_count(locale, "generic_subscriptions_count", subscriptions.size, NumberFormatting::HtmlSpan) %>
|
||||
</a>
|
||||
</h3>
|
||||
</div>
|
||||
|
@ -323,7 +323,7 @@ we're going to need to do it here in order to allow for translations.
|
||||
<div class="pure-u-10-24" style="text-align:right">
|
||||
<% if views = rv["short_view_count_text"]?.try &.delete(", views watching") %>
|
||||
<% if !views.empty? %>
|
||||
<b class="width:100%"><%= translate(locale, "`x` views", views) %></b>
|
||||
<b class="width:100%"><%= translate_count(locale, "generic_views_count", views.to_i? || 0) %></b>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user