diff --git a/_scripts/getRegions.mjs b/_scripts/getRegions.mjs index 482b20470..842bd7cb1 100644 --- a/_scripts/getRegions.mjs +++ b/_scripts/getRegions.mjs @@ -46,13 +46,6 @@ for (const language of youTubeLanguages) { youTube: language, freeTube: language }) - } else if (activeLanguages.includes(language.replace('-', '_'))) { - const withUnderScore = language.replace('-', '_') - foundLanguageNames.push(withUnderScore) - languagesToScrape.push({ - youTube: language, - freeTube: withUnderScore - }) } // special cases else if (language === 'de') { @@ -70,10 +63,10 @@ for (const language of youTubeLanguages) { } else if (language === 'no') { // according to https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes // "no" is the macro language for "nb" and "nn" - foundLanguageNames.push('nb_NO', 'nn') + foundLanguageNames.push('nb-NO', 'nn') languagesToScrape.push({ youTube: 'no', - freeTube: 'nb_NO' + freeTube: 'nb-NO' }) languagesToScrape.push({ youTube: 'no', @@ -88,10 +81,10 @@ for (const language of youTubeLanguages) { freeTube: 'he' }) } else if (language === 'es-419') { - foundLanguageNames.push('es_AR', 'es-MX') + foundLanguageNames.push('es-AR', 'es-MX') languagesToScrape.push({ youTube: 'es-419', - freeTube: 'es_AR' + freeTube: 'es-AR' }) languagesToScrape.push({ youTube: 'es-419', diff --git a/_scripts/getShakaLocales.js b/_scripts/getShakaLocales.js index 5e495bcd3..5beb42407 100644 --- a/_scripts/getShakaLocales.js +++ b/_scripts/getShakaLocales.js @@ -41,15 +41,10 @@ function getMappings(shakaLocales, freeTubeLocales) { locale, locale ]) - } else if (shakaLocales.has(locale.replace('_', '-'))) { + } else if (shakaLocales.has(locale.split('-')[0])) { mappings.push([ locale, - locale.replace('_', '-') - ]) - } else if (shakaLocales.has(locale.split(/[-_]/)[0])) { - mappings.push([ - locale, - locale.split(/[-_]/)[0] + locale.split('-')[0] ]) } } @@ -60,7 +55,7 @@ function getMappings(shakaLocales, freeTubeLocales) { // according to https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes // "no" is the macro language for "nb" and "nn" [ - 'nb_NO', + 'nb-NO', 'no' ], [ diff --git a/src/datastores/handlers/base.js b/src/datastores/handlers/base.js index 32457d3c9..614b21cd2 100644 --- a/src/datastores/handlers/base.js +++ b/src/datastores/handlers/base.js @@ -1,7 +1,15 @@ import * as db from '../index' class Settings { - static find() { + static async find() { + const currentLocale = await db.settings.findOneAsync({ _id: 'currentLocale' }) + + // In FreeTube 0.21.3 and earlier the locales 'en-GB', 'es-AR' and 'nb-NO' had underscores instead of a hyphens + // This is a one time migration for users that are using one of those locales + if (currentLocale?.value.includes('_')) { + await this.upsert('currentLocale', currentLocale.value.replace('_', '-')) + } + return db.settings.findAsync({ _id: { $ne: 'bounds' } }) } diff --git a/src/renderer/App.js b/src/renderer/App.js index 0308944cb..36611d193 100644 --- a/src/renderer/App.js +++ b/src/renderer/App.js @@ -122,7 +122,7 @@ export default defineComponent({ }, locale: function() { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, systemTheme: function () { diff --git a/src/renderer/components/channel-about/channel-about.js b/src/renderer/components/channel-about/channel-about.js index 3eb151e1b..4e5360e47 100644 --- a/src/renderer/components/channel-about/channel-about.js +++ b/src/renderer/components/channel-about/channel-about.js @@ -55,7 +55,7 @@ export default defineComponent({ }, currentLocale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, formattedJoined: function () { diff --git a/src/renderer/components/ft-list-video/ft-list-video.js b/src/renderer/components/ft-list-video/ft-list-video.js index c90e1fa9c..cffc195fa 100644 --- a/src/renderer/components/ft-list-video/ft-list-video.js +++ b/src/renderer/components/ft-list-video/ft-list-video.js @@ -364,7 +364,7 @@ export default defineComponent({ }, currentLocale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, externalPlayer: function () { diff --git a/src/renderer/components/ft-playlist-add-video-prompt/ft-playlist-add-video-prompt.js b/src/renderer/components/ft-playlist-add-video-prompt/ft-playlist-add-video-prompt.js index 0753f7ff1..09fb1a20f 100644 --- a/src/renderer/components/ft-playlist-add-video-prompt/ft-playlist-add-video-prompt.js +++ b/src/renderer/components/ft-playlist-add-video-prompt/ft-playlist-add-video-prompt.js @@ -119,7 +119,7 @@ export default defineComponent({ return this.$store.getters.getNewPlaylistDefaultProperties }, locale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, processedQuery: function() { return this.query.trim().toLowerCase() diff --git a/src/renderer/components/ft-profile-bubble/ft-profile-bubble.js b/src/renderer/components/ft-profile-bubble/ft-profile-bubble.js index 39d4e226e..c0926f978 100644 --- a/src/renderer/components/ft-profile-bubble/ft-profile-bubble.js +++ b/src/renderer/components/ft-profile-bubble/ft-profile-bubble.js @@ -26,7 +26,7 @@ export default defineComponent({ emits: ['click'], computed: { locale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, isMainProfile: function () { return this.profileId === MAIN_PROFILE_ID diff --git a/src/renderer/components/ft-profile-channel-list/ft-profile-channel-list.js b/src/renderer/components/ft-profile-channel-list/ft-profile-channel-list.js index c9b859008..96cefa269 100644 --- a/src/renderer/components/ft-profile-channel-list/ft-profile-channel-list.js +++ b/src/renderer/components/ft-profile-channel-list/ft-profile-channel-list.js @@ -66,7 +66,7 @@ export default defineComponent({ ] }, locale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, }, watch: { diff --git a/src/renderer/components/ft-profile-edit/ft-profile-edit.js b/src/renderer/components/ft-profile-edit/ft-profile-edit.js index 5b9e5b439..a46a6d7d5 100644 --- a/src/renderer/components/ft-profile-edit/ft-profile-edit.js +++ b/src/renderer/components/ft-profile-edit/ft-profile-edit.js @@ -49,7 +49,7 @@ export default defineComponent({ }, computed: { locale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, colorValues: function () { return colors.map(color => color.value) diff --git a/src/renderer/components/ft-profile-filter-channels-list/ft-profile-filter-channels-list.js b/src/renderer/components/ft-profile-filter-channels-list/ft-profile-filter-channels-list.js index 57beae3b2..b18f57b70 100644 --- a/src/renderer/components/ft-profile-filter-channels-list/ft-profile-filter-channels-list.js +++ b/src/renderer/components/ft-profile-filter-channels-list/ft-profile-filter-channels-list.js @@ -49,7 +49,7 @@ export default defineComponent({ return this.$t('Profile.{number} selected', { number: this.selectedLength }) }, locale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale } }, watch: { diff --git a/src/renderer/components/ft-profile-selector/ft-profile-selector.js b/src/renderer/components/ft-profile-selector/ft-profile-selector.js index 3e8eeffeb..d9c519396 100644 --- a/src/renderer/components/ft-profile-selector/ft-profile-selector.js +++ b/src/renderer/components/ft-profile-selector/ft-profile-selector.js @@ -21,7 +21,7 @@ export default defineComponent({ }, computed: { locale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, profileList: function () { return this.$store.getters.getProfileList diff --git a/src/renderer/components/ft-select/ft-select.vue b/src/renderer/components/ft-select/ft-select.vue index 77f466625..57e9a9a72 100644 --- a/src/renderer/components/ft-select/ft-select.vue +++ b/src/renderer/components/ft-select/ft-select.vue @@ -15,7 +15,7 @@ v-for="(name, index) in selectNames" :key="index" :value="selectValues[index]" - :lang="isLocaleSelector && selectValues[index] !== 'system' ? selectValues[index].replace('_', '-') : null" + :lang="isLocaleSelector && selectValues[index] !== 'system' ? selectValues[index] : null" > {{ name }} diff --git a/src/renderer/components/ft-subscribe-button/ft-subscribe-button.js b/src/renderer/components/ft-subscribe-button/ft-subscribe-button.js index da395dcb7..b0a0906e1 100644 --- a/src/renderer/components/ft-subscribe-button/ft-subscribe-button.js +++ b/src/renderer/components/ft-subscribe-button/ft-subscribe-button.js @@ -51,7 +51,7 @@ export default defineComponent({ }, computed: { locale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, profileInitials: function () { return this.profileDisplayList.map((profile) => { diff --git a/src/renderer/components/proxy-settings/proxy-settings.js b/src/renderer/components/proxy-settings/proxy-settings.js index b985c39d6..901ca21d8 100644 --- a/src/renderer/components/proxy-settings/proxy-settings.js +++ b/src/renderer/components/proxy-settings/proxy-settings.js @@ -64,7 +64,7 @@ export default defineComponent({ return `${this.proxyProtocol}://${this.proxyHostname}:${this.proxyPort}` }, lang: function() { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, localeToUse: function() { // locales found here: https://ipwhois.io/documentation diff --git a/src/renderer/components/side-nav/side-nav.js b/src/renderer/components/side-nav/side-nav.js index dd050476b..45db9ef8e 100644 --- a/src/renderer/components/side-nav/side-nav.js +++ b/src/renderer/components/side-nav/side-nav.js @@ -30,7 +30,7 @@ export default defineComponent({ return this.$store.getters.getActiveProfile }, locale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, activeSubscriptions: function () { const subscriptions = deepCopy(this.activeProfile.subscriptions) diff --git a/src/renderer/components/subscriptions-videos/subscriptions-videos.js b/src/renderer/components/subscriptions-videos/subscriptions-videos.js index d3457e22f..c7ed19f28 100644 --- a/src/renderer/components/subscriptions-videos/subscriptions-videos.js +++ b/src/renderer/components/subscriptions-videos/subscriptions-videos.js @@ -45,7 +45,7 @@ export default defineComponent({ }, currentLocale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, lastVideoRefreshTimestamp: function () { diff --git a/src/renderer/components/watch-video-info/watch-video-info.js b/src/renderer/components/watch-video-info/watch-video-info.js index ed57aa9f2..ef5cf85c6 100644 --- a/src/renderer/components/watch-video-info/watch-video-info.js +++ b/src/renderer/components/watch-video-info/watch-video-info.js @@ -119,7 +119,7 @@ export default defineComponent({ }, currentLocale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, hideVideoLikesAndDislikes: function () { diff --git a/src/renderer/components/watch-video-playlist/watch-video-playlist.js b/src/renderer/components/watch-video-playlist/watch-video-playlist.js index ec0ccd27c..bfe449b6e 100644 --- a/src/renderer/components/watch-video-playlist/watch-video-playlist.js +++ b/src/renderer/components/watch-video-playlist/watch-video-playlist.js @@ -68,7 +68,7 @@ export default defineComponent({ return this.$store.getters.getBackendFallback }, currentLocale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, isUserPlaylist: function () { return this.playlistType === 'user' diff --git a/src/renderer/helpers/player/utils.js b/src/renderer/helpers/player/utils.js index 8085d87cb..939423d16 100644 --- a/src/renderer/helpers/player/utils.js +++ b/src/renderer/helpers/player/utils.js @@ -139,7 +139,7 @@ export function qualityLabelToDimension(qualityLabel) { * }[]} captions */ export function sortCaptions(captions) { - const currentLocale = i18n.locale.replace('_', '-') + const currentLocale = i18n.locale const userLocale = currentLocale.split('-') // ex. [en,US] const collator = new Intl.Collator([currentLocale, 'en']) diff --git a/src/renderer/helpers/utils.js b/src/renderer/helpers/utils.js index 08203d0b6..79c836930 100644 --- a/src/renderer/helpers/utils.js +++ b/src/renderer/helpers/utils.js @@ -12,10 +12,6 @@ export const CHANNEL_HANDLE_REGEX = /^@[\w.-]{3,30}$/ const PUBLISHED_TEXT_REGEX = /(\d+)\s?([a-z]+)/i -function currentLocale () { - return i18n.locale.replace('_', '-') -} - export function getIconForSortPreference(sortPreference) { switch (sortPreference) { case 'name_descending': @@ -701,7 +697,7 @@ export function toDistractionFreeTitle(title, minUpperCase = 3) { } export function formatNumber(number, options = undefined) { - return Intl.NumberFormat([i18n.locale.replace('_', '-'), 'en'], options).format(number) + return Intl.NumberFormat([i18n.locale, 'en'], options).format(number) } export function getTodayDateStrLocalTimezone() { @@ -767,7 +763,7 @@ export function getRelativeTimeFromDate(date, hideSeconds = false, useThirtyDayM // Using `Math.ceil` so that -1.x days ago displayed as 1 day ago // Notice that the value is turned to negative to be displayed as "ago" - return new Intl.RelativeTimeFormat([currentLocale(), 'en']).format(Math.ceil(-timeDiffFromNow), timeUnit) + return new Intl.RelativeTimeFormat([i18n.locale, 'en']).format(Math.ceil(-timeDiffFromNow), timeUnit) } /** diff --git a/src/renderer/i18n/index.js b/src/renderer/i18n/index.js index 3feed824a..555a3994b 100644 --- a/src/renderer/i18n/index.js +++ b/src/renderer/i18n/index.js @@ -11,8 +11,8 @@ const i18n = new VueI18n({ fallbackLocale: { // https://kazupon.github.io/vue-i18n/guide/fallback.html#explicit-fallback-with-decision-maps - // es_AR -> es -> en-US - es_AR: ['es'], + // es-AR -> es -> en-US + 'es-AR': ['es'], // es-MX -> es -> en-US 'es-MX': ['es'], // pt-BR -> pt -> en-US diff --git a/src/renderer/store/modules/settings.js b/src/renderer/store/modules/settings.js index 2f223954e..1c657507a 100644 --- a/src/renderer/store/modules/settings.js +++ b/src/renderer/store/modules/settings.js @@ -316,17 +316,15 @@ const stateWithSideEffects = { let targetLocale = value if (value === 'system') { - const systemLocaleName = (await getSystemLocale()).replace('-', '_') // ex: en_US - const systemLocaleSplit = systemLocaleName.split('_') // ex: en + const systemLocaleName = (await getSystemLocale()).replace('_', '-') // ex: en-US + const systemLocaleSplit = systemLocaleName.split('-') // ex: en const targetLocaleOptions = allLocales.filter((locale) => { // filter out other languages - const localeLang = locale.replace('-', '_').split('_')[0] + const localeLang = locale.split('-')[0] return localeLang.includes(systemLocaleSplit[0]) - }).sort((a, b) => { - const aLocaleName = a.replace('-', '_') - const bLocaleName = b.replace('-', '_') - const aLocale = aLocaleName.split('_') // ex: [en, US] - const bLocale = bLocaleName.split('_') + }).sort((aLocaleName, bLocaleName) => { + const aLocale = aLocaleName.split('-') // ex: [en, US] + const bLocale = bLocaleName.split('-') if (aLocaleName === systemLocaleName) { // country & language match, prefer a return -1 @@ -362,8 +360,8 @@ const stateWithSideEffects = { ) } - // "es" is used as a fallback for "es_AR" and "es-MX" - if (targetLocale === 'es_AR' || targetLocale === 'es-MX') { + // "es" is used as a fallback for "es-AR" and "es-MX" + if (targetLocale === 'es-AR' || targetLocale === 'es-MX') { loadPromises.push( loadLocale('es') ) diff --git a/src/renderer/views/Playlist/Playlist.js b/src/renderer/views/Playlist/Playlist.js index 91be3039b..8121a626f 100644 --- a/src/renderer/views/Playlist/Playlist.js +++ b/src/renderer/views/Playlist/Playlist.js @@ -97,7 +97,7 @@ export default defineComponent({ return this.isUserPlaylistRequested ? this.userPlaylistSortOrder : SORT_BY_VALUES.Custom }, currentLocale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, playlistId: function() { return this.$route.params.id diff --git a/src/renderer/views/Settings/Settings.js b/src/renderer/views/Settings/Settings.js index 6d1573880..722e37bba 100644 --- a/src/renderer/views/Settings/Settings.js +++ b/src/renderer/views/Settings/Settings.js @@ -119,7 +119,7 @@ export default defineComponent({ }, computed: { locale: function() { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, settingsPassword: function () { diff --git a/src/renderer/views/SubscribedChannels/SubscribedChannels.js b/src/renderer/views/SubscribedChannels/SubscribedChannels.js index eda06ec8e..b4410831d 100644 --- a/src/renderer/views/SubscribedChannels/SubscribedChannels.js +++ b/src/renderer/views/SubscribedChannels/SubscribedChannels.js @@ -56,7 +56,7 @@ export default defineComponent({ }, locale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, backendPreference: function () { diff --git a/src/renderer/views/UserPlaylists/UserPlaylists.js b/src/renderer/views/UserPlaylists/UserPlaylists.js index a29495f61..053d0b504 100644 --- a/src/renderer/views/UserPlaylists/UserPlaylists.js +++ b/src/renderer/views/UserPlaylists/UserPlaylists.js @@ -57,7 +57,7 @@ export default defineComponent({ }, computed: { locale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, allPlaylists: function () { diff --git a/src/renderer/views/Watch/Watch.js b/src/renderer/views/Watch/Watch.js index f5a29b77e..382db3f3a 100644 --- a/src/renderer/views/Watch/Watch.js +++ b/src/renderer/views/Watch/Watch.js @@ -201,7 +201,7 @@ export default defineComponent({ return !this.hideRecommendedVideos || (!this.hideLiveChat && this.isLive) || this.watchingPlaylist }, currentLocale: function () { - return this.$i18n.locale.replace('_', '-') + return this.$i18n.locale }, hideChapters: function () { return this.$store.getters.getHideChapters diff --git a/static/geolocations/en_GB.json b/static/geolocations/en-GB.json similarity index 100% rename from static/geolocations/en_GB.json rename to static/geolocations/en-GB.json diff --git a/static/geolocations/es_AR.json b/static/geolocations/es-AR.json similarity index 100% rename from static/geolocations/es_AR.json rename to static/geolocations/es-AR.json diff --git a/static/geolocations/nb_NO.json b/static/geolocations/nb-NO.json similarity index 100% rename from static/geolocations/nb_NO.json rename to static/geolocations/nb-NO.json diff --git a/static/locales/activeLocales.json b/static/locales/activeLocales.json index 58d8b378d..0a0357af8 100644 --- a/static/locales/activeLocales.json +++ b/static/locales/activeLocales.json @@ -1,6 +1,6 @@ [ "en-US", - "en_GB", + "en-GB", "ar", "bg", "ca", @@ -9,7 +9,7 @@ "de-DE", "el", "es", - "es_AR", + "es-AR", "es-MX", "et", "eu", @@ -26,7 +26,7 @@ "ja", "ko", "lt", - "nb_NO", + "nb-NO", "nl", "nn", "pl", diff --git a/static/locales/en_GB.yaml b/static/locales/en-GB.yaml similarity index 100% rename from static/locales/en_GB.yaml rename to static/locales/en-GB.yaml diff --git a/static/locales/es_AR.yaml b/static/locales/es-AR.yaml similarity index 100% rename from static/locales/es_AR.yaml rename to static/locales/es-AR.yaml diff --git a/static/locales/nb_NO.yaml b/static/locales/nb-NO.yaml similarity index 100% rename from static/locales/nb_NO.yaml rename to static/locales/nb-NO.yaml