Merge pull request #81 from GilgusMaximus/master

Localization of 'Published x y ago' strings
This commit is contained in:
Preston 2020-08-18 17:12:09 -04:00 committed by GitHub
commit 4392f96b42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 119 additions and 5 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ dist
coverage
__coverage__
csak-timelog.json
.idea/

View File

@ -1,5 +1,6 @@
import Vue from 'vue'
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
import { mapActions } from 'vuex'
export default Vue.extend({
name: 'FtListVideo',
@ -213,7 +214,20 @@ export default Vue.extend({
this.viewCount = this.data.viewCount
if (typeof (this.data.publishedText) !== 'undefined') {
this.uploadedTime = this.data.publishedText
// produces a string according to the template in the locales string
this.toLocalePublicationString({
publishText: this.data.publishedText,
templateString: this.$t('Video.Publicationtemplate'),
timeStrings: this.$t('Video.Published'),
liveStreamString: this.$t('Video.Watching'),
upcomingString: this.$t('Video.Published.Upcoming'),
isLive: this.data.live,
isUpcoming: this.data.isUpcoming
}).then((data) => {
this.uploadedTime = data
}).catch((error) => {
console.error(error)
})
}
if (typeof (this.data.viewCount) !== 'undefined' && this.data.viewCount !== null) {
@ -252,6 +266,19 @@ export default Vue.extend({
}
if (typeof (this.data.uploaded_at) !== 'undefined') {
this.toLocalePublicationString({
publishText: this.data.uploaded_at,
templateString: this.$t('Video.Publicationtemplate'),
timeStrings: this.$t('Video.Published'),
liveStreamString: this.$t('Video.Watching'),
upcomingString: this.$t('Video.Published.Upcoming'),
isLive: this.data.live,
isUpcoming: false
}).then((data) => {
this.uploadedTime = data
}).catch((error) => {
console.error(error)
})
this.uploadedTime = this.data.uploaded_at
}
@ -265,6 +292,9 @@ export default Vue.extend({
}
this.isLive = this.data.live
}
},
...mapActions([
'toLocalePublicationString'
])
}
})

View File

@ -166,6 +166,70 @@ const actions = {
return vttString
},
toLocalePublicationString ({ dispatch }, payload) {
if (payload.isLive) {
return '0' + payload.liveStreamString
} else if (payload.isUpcoming || payload.publishText === null) {
// the check for null is currently just an inferring of knowledge, because there is no other possibility left
return payload.upcomingString
}
const strings = payload.publishText.split(' ')
const singular = (strings[0] === '1')
let publicationString = payload.templateString.replace('$', strings[0])
switch (strings[1].substring(0, 2)) {
case 'se':
if (singular) {
publicationString = publicationString.replace('%', payload.timeStrings.Second)
} else {
publicationString = publicationString.replace('%', payload.timeStrings.Seconds)
}
break
case 'mi':
if (singular) {
publicationString = publicationString.replace('%', payload.timeStrings.Minute)
} else {
publicationString = publicationString.replace('%', payload.timeStrings.Minutes)
}
break
case 'ho':
if (singular) {
publicationString = publicationString.replace('%', payload.timeStrings.Hour)
} else {
publicationString = publicationString.replace('%', payload.timeStrings.Hours)
}
break
case 'da':
if (singular) {
publicationString = publicationString.replace('%', payload.timeStrings.Day)
} else {
publicationString = publicationString.replace('%', payload.timeStrings.Days)
}
break
case 'we':
if (singular) {
publicationString = publicationString.replace('%', payload.timeStrings.Week)
} else {
publicationString = publicationString.replace('%', payload.timeStrings.Weeks)
}
break
case 'mo':
if (singular) {
publicationString = publicationString.replace('%', payload.timeStrings.Month)
} else {
publicationString = publicationString.replace('%', payload.timeStrings.Months)
}
break
case 'ye':
if (singular) {
publicationString = publicationString.replace('%', payload.timeStrings.Year)
} else {
publicationString = publicationString.replace('%', payload.timeStrings.Years)
}
break
}
return publicationString
},
showToast (_, payload) {
FtToastEvents.$emit('toast.open', payload.message, payload.action, payload.time)
}

View File

@ -305,18 +305,23 @@ Video:
Oct: Okt
Nov: Nov
Dec: Dez
Second: Sekunde
Seconds: Sekunden
Hour: Stunde
Hours: Stunden
Day: Tag
Days: Tage
Days: Tagen
Week: Woche
Weeks: Wochen
Month: Monat
Months: Monate
Months: Monaten
Year: Jahr
Years: Jahre
Years: Jahren
Ago: Vor
Upcoming: Premiere bald
Published on: Veröffentlicht am
Publicationtemplate: vor $ % veröffentlicht
#& Videos
Videos:
#& Sort By

View File

@ -297,6 +297,8 @@ Video:
Oct: Oct
Nov: Nov
Dec: Dec
Second: Second
Seconds: Seconds
Hour: Hour
Hours: Hours
Day: Day
@ -308,7 +310,10 @@ Video:
Year: Year
Years: Years
Ago: Ago
Upcoming: Premieres soon
Published on: Published on
# $ is replaced with the number and % with the unit (days, hours, minutes...)
Publicationtemplate: $ % ago
#& Videos
Videos:
#& Sort By

View File

@ -302,6 +302,10 @@ Video:
Oct: Out
Nov: Nov
Dec: Dez
# !
Second: Second
# !
Seconds: Seconds
Hour: Hora
Hours: Horas
Day: Dia
@ -313,7 +317,12 @@ Video:
Year: Ano
Years: Anos
Ago:
# !
Upcoming: Premieres soon
Published on: Publicado em
# !
# $ is replaced with the number and % with the unit (days, hours, minutes...)
Publicationtemplate: $ % ago
#& Videos
Videos:
#& Sort By