Properly localize numbers (#2557)

* localize numbers properly

* Remove tostring

Co-authored-by: Aiz <66974576+Aiz0@users.noreply.github.com>

Co-authored-by: Aiz <66974576+Aiz0@users.noreply.github.com>
This commit is contained in:
ChunkyProgrammer 2022-09-19 08:14:53 -04:00 committed by GitHub
parent d9ab06d243
commit 8fa182e246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 10 deletions

View File

@ -1,4 +1,5 @@
import Vue from 'vue' import Vue from 'vue'
import i18n from '../../i18n/index'
export default Vue.extend({ export default Vue.extend({
name: 'FtListChannel', name: 'FtListChannel',
@ -32,6 +33,9 @@ export default Vue.extend({
}, },
hideChannelSubscriptions: function () { hideChannelSubscriptions: function () {
return this.$store.getters.getHideChannelSubscriptions return this.$store.getters.getHideChannelSubscriptions
},
currentLocale: function () {
return i18n.locale.replace('_', '-')
} }
}, },
mounted: function () { mounted: function () {
@ -59,7 +63,7 @@ export default Vue.extend({
if (this.data.videos === null) { if (this.data.videos === null) {
this.videoCount = 0 this.videoCount = 0
} else { } 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 this.description = this.data.descriptionShort
@ -81,9 +85,9 @@ export default Vue.extend({
if (this.hideChannelSubscriptions) { if (this.hideChannelSubscriptions) {
this.subscriberCount = null this.subscriberCount = null
} else { } 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 this.description = this.data.description
} }
} }

View File

@ -1,6 +1,7 @@
import Vue from 'vue' import Vue from 'vue'
import FtIconButton from '../ft-icon-button/ft-icon-button.vue' import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
import i18n from '../../i18n/index'
export default Vue.extend({ export default Vue.extend({
name: 'FtListVideo', name: 'FtListVideo',
@ -249,6 +250,10 @@ export default Vue.extend({
saveWatchedProgress: function () { saveWatchedProgress: function () {
return this.$store.getters.getSaveWatchedProgress return this.$store.getters.getSaveWatchedProgress
},
currentLocale: function () {
return i18n.locale.replace('_', '-')
} }
}, },
mounted: function () { mounted: function () {
@ -424,7 +429,7 @@ export default Vue.extend({
if (this.hideVideoViews) { if (this.hideVideoViews) {
this.hideViews = true this.hideViews = true
} else if (typeof (this.data.viewCount) !== 'undefined' && this.data.viewCount !== null) { } 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') { } else if (typeof (this.data.viewCountText) !== 'undefined') {
this.parsedViewCount = this.data.viewCountText.replace(' views', '') this.parsedViewCount = this.data.viewCountText.replace(' views', '')
} else { } else {

View File

@ -1,6 +1,7 @@
import Vue from 'vue' import Vue from 'vue'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
import FtListDropdown from '../ft-list-dropdown/ft-list-dropdown.vue' import FtListDropdown from '../ft-list-dropdown/ft-list-dropdown.vue'
import i18n from '../../i18n/index'
export default Vue.extend({ export default Vue.extend({
name: 'PlaylistInfo', name: 'PlaylistInfo',
@ -75,6 +76,9 @@ export default Vue.extend({
default: default:
return `https://i.ytimg.com/vi/${this.firstVideoId}/mqdefault.jpg` return `https://i.ytimg.com/vi/${this.firstVideoId}/mqdefault.jpg`
} }
},
currentLocale: function () {
return i18n.locale.replace('_', '-')
} }
}, },
mounted: function () { mounted: function () {
@ -91,11 +95,11 @@ export default Vue.extend({
// Causes errors if not put inside of a check // Causes errors if not put inside of a check
if (typeof (this.data.viewCount) !== 'undefined') { 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') { 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 this.lastUpdated = this.data.lastUpdated

View File

@ -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 FtIconButton from '../ft-icon-button/ft-icon-button.vue'
import FtShareButton from '../ft-share-button/ft-share-button.vue' import FtShareButton from '../ft-share-button/ft-share-button.vue'
import { MAIN_PROFILE_ID } from '../../../constants' import { MAIN_PROFILE_ID } from '../../../constants'
import i18n from '../../i18n/index'
export default Vue.extend({ export default Vue.extend({
name: 'WatchVideoInfo', name: 'WatchVideoInfo',
@ -135,7 +136,7 @@ export default Vue.extend({
}, },
currentLocale: function () { currentLocale: function () {
return this.$store.getters.getCurrentLocale return i18n.locale.replace('_', '-')
}, },
profileList: function () { profileList: function () {
@ -238,7 +239,7 @@ export default Vue.extend({
if (this.hideVideoViews) { if (this.hideVideoViews) {
return null 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 () { isSubscribed: function () {

View File

@ -13,6 +13,7 @@ import FtAgeRestricted from '../../components/ft-age-restricted/ft-age-restricte
import ytch from 'yt-channel-info' import ytch from 'yt-channel-info'
import autolinker from 'autolinker' import autolinker from 'autolinker'
import { MAIN_PROFILE_ID } from '../../../constants' import { MAIN_PROFILE_ID } from '../../../constants'
import i18n from '../../i18n/index'
export default Vue.extend({ export default Vue.extend({
name: 'Search', name: 'Search',
@ -132,11 +133,15 @@ export default Vue.extend({
] ]
}, },
currentLocale: function () {
return i18n.locale.replace('_', '-')
},
formattedSubCount: function () { formattedSubCount: function () {
if (this.hideChannelSubscriptions) { if (this.hideChannelSubscriptions) {
return null return null
} }
return this.subCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') return Intl.NumberFormat(this.currentLocale).format(this.subCount)
}, },
showFetchMoreButton: function () { showFetchMoreButton: function () {

View File

@ -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 WatchVideoPlaylist from '../../components/watch-video-playlist/watch-video-playlist.vue'
import WatchVideoRecommendations from '../../components/watch-video-recommendations/watch-video-recommendations.vue' import WatchVideoRecommendations from '../../components/watch-video-recommendations/watch-video-recommendations.vue'
import FtAgeRestricted from '../../components/ft-age-restricted/ft-age-restricted.vue' import FtAgeRestricted from '../../components/ft-age-restricted/ft-age-restricted.vue'
import i18n from '../../i18n/index'
export default Vue.extend({ export default Vue.extend({
name: 'Watch', name: 'Watch',
@ -160,6 +161,9 @@ export default Vue.extend({
}, },
theatrePossible: function () { theatrePossible: function () {
return !this.hideRecommendedVideos || (!this.hideLiveChat && this.isLive) || this.watchingPlaylist return !this.hideRecommendedVideos || (!this.hideLiveChat && this.isLive) || this.watchingPlaylist
},
currentLocale: function () {
return i18n.locale.replace('_', '-')
} }
}, },
watch: { watch: {
@ -354,7 +358,7 @@ export default Vue.extend({
} else if (subCount >= 10000) { } else if (subCount >= 10000) {
this.channelSubscriptionCountText = `${subCount / 1000}K` this.channelSubscriptionCountText = `${subCount / 1000}K`
} else { } else {
this.channelSubscriptionCountText = subCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') this.channelSubscriptionCountText = Intl.NumberFormat(this.currentLocale).format(subCount)
} }
} }