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

Fix localization of counts #4011

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
23 changes: 15 additions & 8 deletions src/renderer/components/ft-list-channel/ft-list-channel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineComponent } from 'vue'
import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious'
import { formatNumber } from '../../helpers/utils'
import { parseLocalSubscriberCount } from '../../helpers/api/local'

export default defineComponent({
name: 'FtListChannel',
Expand All @@ -20,7 +21,9 @@ export default defineComponent({
thumbnail: '',
channelName: '',
subscriberCount: 0,
videoCount: '',
videoCount: 0,
formattedSubscriberCount: '',
formattedVideoCount: '',
handle: null,
description: ''
}
Expand Down Expand Up @@ -53,14 +56,16 @@ export default defineComponent({

this.channelName = this.data.name
this.id = this.data.id
this.subscriberCount = this.data.subscribers != null ? this.data.subscribers.replace(/ subscriber(s)?/, '') : null

if (this.data.videos === null) {
this.videoCount = 0
if (this.data.subscribers != null) {
this.subscriberCount = parseLocalSubscriberCount(this.data.subscribers.replace(/ subscriber(s)?/, ''))
this.formattedSubscriberCount = formatNumber(this.subscriberCount)
} else {
this.videoCount = formatNumber(this.data.videos)
this.subscriberCount = null
}

this.videoCount = this.data.videos ?? 0
this.formattedVideoCount = formatNumber(this.videoCount)

if (this.data.handle) {
this.handle = this.data.handle
}
Expand All @@ -76,8 +81,10 @@ export default defineComponent({

this.channelName = this.data.author
this.id = this.data.authorId
this.subscriberCount = formatNumber(this.data.subCount)
this.videoCount = formatNumber(this.data.videoCount)
this.subscriberCount = this.data.subCount
this.videoCount = this.data.videoCount
this.formattedVideoCount = formatNumber(this.data.videoCount)
this.formattedSubscriberCount = formatNumber(this.data.subCount)
this.description = this.data.description
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/ft-list-channel/ft-list-channel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
v-if="subscriberCount !== null && !hideChannelSubscriptions"
class="subscriberCount"
>
{{ subscriberCount }} subscribers -
{{ $tc('Global.Counts.Subscriber Count', subscriberCount, {count: formattedSubscriberCount}) }}
</span>
<router-link
v-if="handle !== null"
Expand All @@ -47,7 +47,7 @@
v-else
class="videoCount"
>
{{ videoCount }} videos
{{ $tc('Global.Counts.Video Count', videoCount, {count: formattedVideoCount}) }}
</span>
</div>
<p
Expand Down
6 changes: 2 additions & 4 deletions src/renderer/components/ft-list-video/ft-list-video.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@
<span>{{ channelName }}</span>
</router-link>
<template v-if="!isLive && !isUpcoming && !isPremium && !hideViews">
<span class="viewCount"><template v-if="channelId !== null"> •</template> {{ parsedViewCount }} </span>
<span v-if="viewCount === 1">{{ $t("Video.View").toLowerCase() }}</span>
<span v-else>{{ $t("Video.Views").toLowerCase() }}</span>
<span class="viewCount"><template v-if="channelId !== null"> •</template>{{ $tc('Global.Counts.View Count', viewCount, {count: parsedViewCount}) }}</span>
ChunkyProgrammer marked this conversation as resolved.
Show resolved Hide resolved
</template>
<span
v-if="uploadedTime !== '' && !isLive && !inHistory"
Expand All @@ -105,7 +103,7 @@
<span
v-if="isLive && !hideViews"
class="viewCount"
> • {{ parsedViewCount }} {{ $t("Video.Watching").toLowerCase() }}</span>
> • {{ $tc('Global.Counts.Watching Count', viewCount, {count: parsedViewCount}) }}</span>
</div>
<ft-icon-button
class="optionsButton"
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/components/watch-video-info/watch-video-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ export default defineComponent({
if (this.hideVideoViews) {
return null
}
return formatNumber(this.viewCount) + ` ${this.$t('Video.Views').toLowerCase()}`

return this.$tc('Global.Counts.View Count', this.viewCount, { count: formatNumber(this.viewCount) })
},

dateString: function () {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function calculatePublishedDate(publishedText) {

export function toLocalePublicationString ({ publishText, isLive = false, isUpcoming = false, isRSS = false }) {
if (isLive) {
return '0' + i18n.t('Video.Watching')
return i18n.tc('Global.Counts.Watching Count', 0, { count: 0 })
} else if (isUpcoming || publishText === null) {
// the check for null is currently just an inferring of knowledge, because there is no other possibility left
return `${i18n.t('Video.Published.Upcoming')}: ${publishText}`
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/views/Channel/Channel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
v-if="subCount !== null && !hideChannelSubscriptions"
class="channelSubCount"
>
{{ formattedSubCount }}
<span v-if="subCount === 1">{{ $t("Channel.Subscriber") }}</span>
<span v-else>{{ $t("Channel.Subscribers") }}</span>
{{ $tc('Global.Counts.Subscriber Count', subCount, { count: formattedSubCount }) }}
</p>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Global:
Videos: Videos
Shorts: Shorts
Live: Live
Counts:
Video Count: 1 video | {count} videos
Channel Count: 1 channel | {count} channels
Subscriber Count: 1 subscriber | {count} subscribers
View Count: 1 view | {count} views
Watching Count: 1 watching | {count} watching
Comment on lines +51 to +53
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though not mentioned by
https://kazupon.github.io/vue-i18n/guide/pluralization.html#pluralization

When zero value not provided and count is zero, the plural version is used (I tested locally) (for en at least)


# Search Bar
Search / Go to URL: Search / Go to URL
Expand Down