Skip to content

Commit

Permalink
Use named parameters instead of $ and % in localised strings (FreeTub…
Browse files Browse the repository at this point in the history
…eApp#2685)

* Use named parameters instead of $ and % in localised strings

* Fix URL warning again

* Update placeholders in most locales

* Let the translators fix the problematic RTL strings

* Fix the missing quotes in some of the YAML files
  • Loading branch information
absidue committed Oct 13, 2022
1 parent 81426ed commit c0f98ee
Show file tree
Hide file tree
Showing 86 changed files with 1,279 additions and 1,457 deletions.
6 changes: 2 additions & 4 deletions src/renderer/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ export default Vue.extend({
this.updateChangelog = marked.parse(json[0].body)
this.changeLogTitle = json[0].name

const message = this.$t('Version $ is now available! Click for more details')
this.updateBannerMessage = message.replace('$', versionNumber)
this.updateBannerMessage = this.$t('Version {versionNumber} is now available! Click for more details', { versionNumber })

const appVersion = packageDetails.version.split('.')
const latestVersion = versionNumber.split('.')
Expand Down Expand Up @@ -242,8 +241,7 @@ export default Vue.extend({
const latestPubDate = new Date(latestBlog.pubDate)

if (lastAppWasRunning === null || latestPubDate > lastAppWasRunning) {
const message = this.$t('A new blog is now available, $. Click to view more')
this.blogBannerMessage = message.replace('$', latestBlog.title)
this.blogBannerMessage = this.$t('A new blog is now available, {blogTitle}. Click to view more', { blogTitle: latestBlog.title })
this.latestBlogUrl = latestBlog.link
this.showBlogBanner = true
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/data-settings/data-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ export default Vue.extend({
const objectKeys = Object.keys(playlistObject)

if ((objectKeys.length < requiredKeys.length) || playlistObject.videos.length === 0) {
const message = this.$t('Settings.Data Settings.Playlist insufficient data').replace('$', playlistData.playlistName)
const message = this.$t('Settings.Data Settings.Playlist insufficient data', { playlist: playlistData.playlistName })
this.showToast({
message: message
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export default Vue.extend({

const cmdArgs = this.$store.getters.getExternalPlayerCmdArguments[this.externalPlayer]
if (cmdArgs && typeof cmdArgs.defaultCustomArguments === 'string' && cmdArgs.defaultCustomArguments !== '') {
const defaultArgs = this.$t('Tooltips.External Player Settings.DefaultCustomArgumentsTemplate')
.replace('$', cmdArgs.defaultCustomArguments)
const defaultArgs = this.$t('Tooltips.External Player Settings.DefaultCustomArgumentsTemplate',
{ defaultCustomArguments: cmdArgs.defaultCustomArguments })
return `${tooltip} ${defaultArgs}`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default Vue.extend({

restrictedMessage: function () {
const contentType = this.$t('Age Restricted.Type.' + this.contentTypeString)
return this.$t('Age Restricted.This $contentType is age restricted').replace('$contentType', contentType)
return this.$t('Age Restricted.This {videoOrPlaylist} is age restricted', { videoOrPlaylist: contentType })
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export default Vue.extend({
methods: {
handleExternalPlayer: function () {
this.openInExternalPlayer({
strings: this.$t('Video.External Player'),
watchProgress: 0,
playbackRate: this.defaultPlayback,
videoId: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div class="info">
<ft-icon-button
v-if="externalPlayer !== ''"
:title="$t('Video.External Player.OpenInTemplate').replace('$', externalPlayer)"
:title="$t('Video.External Player.OpenInTemplate', { externalPlayer })"
:icon="['fas', 'external-link-alt']"
class="externalPlayerButton"
theme="base-no-default"
Expand Down
5 changes: 0 additions & 5 deletions src/renderer/components/ft-list-video/ft-list-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ export default Vue.extend({
this.$emit('pause-player')

this.openInExternalPlayer({
strings: this.$t('Video.External Player'),
watchProgress: this.watchProgress,
playbackRate: this.defaultPlayback,
videoId: this.id,
Expand Down Expand Up @@ -394,10 +393,6 @@ export default Vue.extend({
// produces a string according to the template in the locales string
this.toLocalePublicationString({
publishText: this.publishedText,
templateString: this.$t('Video.Publicationtemplate'),
timeStrings: this.$t('Video.Published'),
liveStreamString: this.$t('Video.Watching'),
upcomingString: this.$t('Video.Published.Upcoming'),
isLive: this.isLive,
isUpcoming: this.isUpcoming,
isRSS: this.data.isRSS
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/ft-list-video/ft-list-video.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</div>
<ft-icon-button
v-if="externalPlayer !== ''"
:title="$t('Video.External Player.OpenInTemplate').replace('$', externalPlayer)"
:title="$t('Video.External Player.OpenInTemplate', { externalPlayer })"
:icon="['fas', 'external-link-alt']"
class="externalPlayerIcon"
theme="base"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export default Vue.extend({
return this.$store.getters.getProfileList
},
selectedText: function () {
const localeText = this.$t('Profile.$ selected')
return localeText.replace('$', this.selectedLength)
return this.$t('Profile.{number} selected', { number: this.selectedLength })
},
deletePromptMessage: function () {
if (this.isMainProfile) {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/ft-profile-edit/ft-profile-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default Vue.extend({

setDefaultProfile: function () {
this.updateDefaultProfile(this.profileId)
const message = this.$t('Profile.Your default profile has been set to $').replace('$', this.profileName)
const message = this.$t('Profile.Your default profile has been set to {profile}', { profile: this.profileName })
this.showToast({
message: message
})
Expand All @@ -143,7 +143,7 @@ export default Vue.extend({

this.removeProfile(this.profileId)

const message = this.$t('Profile.Removed $ from your profiles').replace('$', this.profileName)
const message = this.$t('Profile.Removed {profile} from your profiles', { profile: this.profileName })
this.showToast({ message })

if (this.defaultProfile === this.profileId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export default Vue.extend({
return this.profileList.flatMap((profile) => profile.name !== this.profile.name ? [profile.name] : [])
},
selectedText: function () {
const localeText = this.$t('Profile.$ selected')
return localeText.replace('$', this.selectedLength)
return this.$t('Profile.{number} selected', { number: this.selectedLength })
}
},
watch: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default Vue.extend({
if (targetProfile) {
this.updateActiveProfile(targetProfile._id)

const message = this.$t('Profile.$ is now the active profile').replace('$', profile.name)
const message = this.$t('Profile.{profile} is now the active profile', { profile: profile.name })
this.showToast({ message })
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/ft-video-player/ft-video-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ export default Vue.extend({
} catch (err) {
console.error(`Parse failed: ${err.message}`)
this.showToast({
message: this.$t('Screenshot Error').replace('$', err.message)
message: this.$t('Screenshot Error', { error: err.message })
})
canvas.remove()
return
Expand Down Expand Up @@ -1412,7 +1412,7 @@ export default Vue.extend({
} catch (err) {
console.error(err)
this.showToast({
message: this.$t('Screenshot Error').replace('$', err)
message: this.$t('Screenshot Error', { error: err })
})
canvas.remove()
return
Expand All @@ -1429,11 +1429,11 @@ export default Vue.extend({
if (err) {
console.error(err)
this.showToast({
message: this.$t('Screenshot Error').replace('$', err)
message: this.$t('Screenshot Error', { error: err })
})
} else {
this.showToast({
message: this.$t('Screenshot Success').replace('$', filePath)
message: this.$t('Screenshot Success', { filePath })
})
}
})
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/general-settings/general-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ export default Vue.extend({
const instance = this.currentInvidiousInstance
this.updateDefaultInvidiousInstance(instance)

const message = this.$t('Default Invidious instance has been set to $')
this.showToast({
message: message.replace('$', instance)
message: this.$t('Default Invidious instance has been set to {instance}', { instance })
})
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
v-if="defaultInvidiousInstance !== ''"
class="center"
>
{{ $t('Settings.General Settings.The currently set default instance is $').replace('$', defaultInvidiousInstance) }}
{{ $t('Settings.General Settings.The currently set default instance is {instance}', { instance: defaultInvidiousInstance }) }}
</p>
<template v-else>
<p class="center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ export default Vue.extend({
comment.dataType = 'local'
this.toLocalePublicationString({
publishText: (comment.time + ' ago'),
templateString: this.$t('Video.Publicationtemplate'),
timeStrings: this.$t('Video.Published'),
liveStreamString: this.$t('Video.Watching'),
upcomingString: this.$t('Video.Published.Upcoming'),
isLive: false,
isUpcoming: false,
isRSS: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
{{ comment.numReplies }}
<span v-if="comment.numReplies === 1">{{ $t("Comments.Reply").toLowerCase() }}</span>
<span v-else>{{ $t("Comments.Replies").toLowerCase() }}</span>
<span v-if="comment.hasOwnerReplied && !comment.showReplies"> {{ $t("Comments.From $channelName").replace("$channelName", channelName) }}</span>
<span v-if="comment.hasOwnerReplied && !comment.showReplies"> {{ $t("Comments.From {channelName}", { channelName }) }}</span>
<span v-if="comment.numReplies > 1 && comment.hasOwnerReplied && !comment.showReplies">{{ $t("Comments.And others") }}</span>
</span>
</p>
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/components/watch-video-info/watch-video-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ export default Vue.extend({
this.$emit('pause-player')

this.openInExternalPlayer({
strings: this.$t('Video.External Player'),
watchProgress: this.getTimestamp(),
playbackRate: this.defaultPlayback,
videoId: this.id,
Expand Down Expand Up @@ -387,9 +386,8 @@ export default Vue.extend({
})

if (duplicateSubscriptions > 0) {
const message = this.$t('Channel.Removed subscription from $ other channel(s)')
this.showToast({
message: message.replace('$', duplicateSubscriptions)
message: this.$t('Channel.Removed subscription from {count} other channel(s)', { count: duplicateSubscriptions })
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
/>
<ft-icon-button
v-if="externalPlayer !== ''"
:title="$t('Video.External Player.OpenInTemplate').replace('$', externalPlayer)"
:title="$t('Video.External Player.OpenInTemplate', { externalPlayer })"
:icon="['fas', 'external-link-alt']"
class="option"
theme="secondary"
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 @@ -18,7 +18,7 @@ if (isDev) {
const doc = load(fs.readFileSync(`static/locales/${locale}.yaml`))
messages[locale] = doc
} catch (e) {
console.error(e)
console.error(locale, e)
}
})
}
Expand Down Expand Up @@ -50,7 +50,7 @@ class CustomVueI18n extends VueI18n {
const data = JSON.parse(brotliDecompressSync(compressed).toString())
this.setLocaleMessage(locale, data)
} catch (err) {
console.error(err)
console.error(locale, err)
}
} else {
const url = new URL(window.location.href)
Expand Down
Loading

0 comments on commit c0f98ee

Please sign in to comment.