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

Use BCP 47 compatible languages codes for all locales #5723

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
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
15 changes: 4 additions & 11 deletions _scripts/getRegions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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',
Expand All @@ -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',
Expand Down
11 changes: 3 additions & 8 deletions _scripts/getShakaLocales.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
])
}
}
Expand All @@ -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'
],
[
Expand Down
10 changes: 9 additions & 1 deletion src/datastores/handlers/base.js
Original file line number Diff line number Diff line change
@@ -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' } })
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default defineComponent({
},

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

systemTheme: function () {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/channel-about/channel-about.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default defineComponent({
},

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

formattedJoined: function () {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/ft-list-video/ft-list-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export default defineComponent({
},

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

externalPlayer: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default defineComponent({
]
},
locale: function () {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},
},
watch: {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/ft-profile-edit/ft-profile-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/ft-select/ft-select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/proxy-settings/proxy-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/side-nav/side-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default defineComponent({
},

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

lastVideoRefreshTimestamp: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default defineComponent({
},

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

hideVideoLikesAndDislikes: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/helpers/player/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
8 changes: 2 additions & 6 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions src/renderer/store/modules/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
)
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/views/Playlist/Playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/views/Settings/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default defineComponent({
},
computed: {
locale: function() {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},

settingsPassword: function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default defineComponent({
},

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

backendPreference: function () {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/views/UserPlaylists/UserPlaylists.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default defineComponent({
},
computed: {
locale: function () {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},

allPlaylists: function () {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/views/Watch/Watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions static/locales/activeLocales.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
"en-US",
"en_GB",
"en-GB",
"ar",
"bg",
"ca",
Expand All @@ -9,7 +9,7 @@
"de-DE",
"el",
"es",
"es_AR",
"es-AR",
"es-MX",
"et",
"eu",
Expand All @@ -26,7 +26,7 @@
"ja",
"ko",
"lt",
"nb_NO",
"nb-NO",
"nl",
"nn",
"pl",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.