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

Properly localize numbers #2557

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions src/renderer/components/ft-list-channel/ft-list-channel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Vue from 'vue'
import i18n from '../../i18n/index'

export default Vue.extend({
name: 'FtListChannel',
Expand Down Expand Up @@ -32,6 +33,9 @@ export default Vue.extend({
},
hideChannelSubscriptions: function () {
return this.$store.getters.getHideChannelSubscriptions
},
currentLocale: function () {
return i18n.locale.replace('_', '-')
}
},
mounted: function () {
Expand Down Expand Up @@ -59,7 +63,7 @@ export default Vue.extend({
if (this.data.videos === null) {
this.videoCount = 0
} else {
this.videoCount = this.data.videos.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
this.videoCount = Intl.NumberFormat(this.currentLocale).format(this.data.videos)
}

this.description = this.data.descriptionShort
Expand All @@ -81,9 +85,9 @@ export default Vue.extend({
if (this.hideChannelSubscriptions) {
this.subscriberCount = null
} else {
this.subscriberCount = this.data.subCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
this.subscriberCount = Intl.NumberFormat(this.currentLocale).format(this.data.subCount)
}
this.videoCount = this.data.videoCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
this.videoCount = Intl.NumberFormat(this.currentLocale).format(this.data.videoCount)
this.description = this.data.description
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/components/ft-list-video/ft-list-video.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue'
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
import { mapActions } from 'vuex'
import i18n from '../../i18n/index'

export default Vue.extend({
name: 'FtListVideo',
Expand Down Expand Up @@ -249,6 +250,10 @@ export default Vue.extend({

saveWatchedProgress: function () {
return this.$store.getters.getSaveWatchedProgress
},

currentLocale: function () {
return i18n.locale.replace('_', '-')
}
},
mounted: function () {
Expand Down Expand Up @@ -424,7 +429,7 @@ export default Vue.extend({
if (this.hideVideoViews) {
this.hideViews = true
} else if (typeof (this.data.viewCount) !== 'undefined' && this.data.viewCount !== null) {
this.parsedViewCount = this.data.viewCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
this.parsedViewCount = Intl.NumberFormat(this.currentLocale).format(this.data.viewCount)
} else if (typeof (this.data.viewCountText) !== 'undefined') {
this.parsedViewCount = this.data.viewCountText.replace(' views', '')
} else {
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/components/playlist-info/playlist-info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vue from 'vue'
import { mapActions } from 'vuex'
import FtListDropdown from '../ft-list-dropdown/ft-list-dropdown.vue'
import i18n from '../../i18n/index'

export default Vue.extend({
name: 'PlaylistInfo',
Expand Down Expand Up @@ -75,6 +76,9 @@ export default Vue.extend({
default:
return `https://i.ytimg.com/vi/${this.firstVideoId}/mqdefault.jpg`
}
},
currentLocale: function () {
return i18n.locale.replace('_', '-')
}
},
mounted: function () {
Expand All @@ -91,11 +95,11 @@ export default Vue.extend({

// Causes errors if not put inside of a check
if (typeof (this.data.viewCount) !== 'undefined') {
this.viewCount = this.hideViews ? null : this.data.viewCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
this.viewCount = this.hideViews ? null : Intl.NumberFormat(this.currentLocale).format(this.data.viewCount)
}

if (typeof (this.data.videoCount) !== 'undefined') {
this.videoCount = this.data.videoCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
this.videoCount = Intl.NumberFormat(this.currentLocale).format(this.data.videoCount)
}

this.lastUpdated = this.data.lastUpdated
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/components/watch-video-info/watch-video-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
import FtShareButton from '../ft-share-button/ft-share-button.vue'
import { MAIN_PROFILE_ID } from '../../../constants'
import i18n from '../../i18n/index'

export default Vue.extend({
name: 'WatchVideoInfo',
Expand Down Expand Up @@ -135,7 +136,7 @@ export default Vue.extend({
},

currentLocale: function () {
return this.$store.getters.getCurrentLocale
return i18n.locale.replace('_', '-')
},

profileList: function () {
Expand Down Expand Up @@ -238,7 +239,7 @@ export default Vue.extend({
if (this.hideVideoViews) {
return null
}
return this.viewCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ` ${this.$t('Video.Views').toLowerCase()}`
return Intl.NumberFormat(this.currentLocale).format(this.viewCount) + ` ${this.$t('Video.Views').toLowerCase()}`
},

isSubscribed: function () {
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/views/Channel/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import FtAgeRestricted from '../../components/ft-age-restricted/ft-age-restricte
import ytch from 'yt-channel-info'
import autolinker from 'autolinker'
import { MAIN_PROFILE_ID } from '../../../constants'
import i18n from '../../i18n/index'

export default Vue.extend({
name: 'Search',
Expand Down Expand Up @@ -136,11 +137,15 @@ export default Vue.extend({
]
},

currentLocale: function () {
return i18n.locale.replace('_', '-')
},

formattedSubCount: function () {
if (this.hideChannelSubscriptions) {
return null
}
return this.subCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
return Intl.NumberFormat(this.currentLocale).format(this.subCount)
},

showFetchMoreButton: function () {
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import WatchVideoLiveChat from '../../components/watch-video-live-chat/watch-vid
import WatchVideoPlaylist from '../../components/watch-video-playlist/watch-video-playlist.vue'
import WatchVideoRecommendations from '../../components/watch-video-recommendations/watch-video-recommendations.vue'
import FtAgeRestricted from '../../components/ft-age-restricted/ft-age-restricted.vue'
import i18n from '../../i18n/index'

export default Vue.extend({
name: 'Watch',
Expand Down Expand Up @@ -163,6 +164,9 @@ export default Vue.extend({
},
theatrePossible: function () {
return !this.hideRecommendedVideos || (!this.hideLiveChat && this.isLive) || this.watchingPlaylist
},
currentLocale: function () {
return i18n.locale.replace('_', '-')
}
},
watch: {
Expand Down Expand Up @@ -364,7 +368,7 @@ export default Vue.extend({
} else if (subCount >= 10000) {
this.channelSubscriptionCountText = `${subCount / 1000}K`
} else {
this.channelSubscriptionCountText = subCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
this.channelSubscriptionCountText = Intl.NumberFormat(this.currentLocale).format(subCount)
}
}

Expand Down