Use BCP 47 compatible languages codes for all locales (#5723)

This commit is contained in:
absidue 2024-09-23 22:07:40 +02:00 committed by GitHub
parent b1861ff727
commit 84ee64cb7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 53 additions and 63 deletions

View File

@ -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',

View File

@ -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'
],
[

View File

@ -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' } })
}

View File

@ -122,7 +122,7 @@ export default defineComponent({
},
locale: function() {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},
systemTheme: function () {

View File

@ -55,7 +55,7 @@ export default defineComponent({
},
currentLocale: function () {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},
formattedJoined: function () {

View File

@ -364,7 +364,7 @@ export default defineComponent({
},
currentLocale: function () {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},
externalPlayer: function () {

View File

@ -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()

View File

@ -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

View File

@ -66,7 +66,7 @@ export default defineComponent({
]
},
locale: function () {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},
},
watch: {

View File

@ -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)

View File

@ -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: {

View File

@ -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

View File

@ -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>

View File

@ -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) => {

View File

@ -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

View File

@ -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)

View File

@ -45,7 +45,7 @@ export default defineComponent({
},
currentLocale: function () {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},
lastVideoRefreshTimestamp: function () {

View File

@ -119,7 +119,7 @@ export default defineComponent({
},
currentLocale: function () {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},
hideVideoLikesAndDislikes: function () {

View File

@ -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'

View File

@ -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'])

View File

@ -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)
}
/**

View File

@ -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

View File

@ -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')
)

View File

@ -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

View File

@ -119,7 +119,7 @@ export default defineComponent({
},
computed: {
locale: function() {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},
settingsPassword: function () {

View File

@ -56,7 +56,7 @@ export default defineComponent({
},
locale: function () {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},
backendPreference: function () {

View File

@ -57,7 +57,7 @@ export default defineComponent({
},
computed: {
locale: function () {
return this.$i18n.locale.replace('_', '-')
return this.$i18n.locale
},
allPlaylists: function () {

View File

@ -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

View File

@ -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",