Skip to content

Commit

Permalink
Handle multiple language
Browse files Browse the repository at this point in the history
  • Loading branch information
lcduong committed Sep 23, 2024
1 parent a746244 commit b55c4bb
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 10 deletions.
106 changes: 101 additions & 5 deletions webapp/src/views/schedule/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,26 @@ export default {
let founds = null
if (selectedIds.length) {
if (results && results.length) {
founds = self.schedule.talks.filter(t => selectedIds.includes(t[refKey]) && results && results.includes(t.id))?.map(i => i.id) || []
founds = self.schedule.talks.filter(t => {
if (refKey === 'session_type') {
if (typeof t.session_type === 'string') {
return selectedIds.includes(t.session_type) && results.includes(t.id)
} else {
return Object.keys(t.session_type).some(key => selectedIds.includes(t.session_type[key])) && results.includes(t.id)
}
}
return selectedIds.includes(t[refKey]) && results && results.includes(t.id)})?.map(i => i.id) || []

Check failure on line 165 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Requires a space before '}'

Check failure on line 165 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block
} else {
founds = self.schedule.talks.filter(t => { return selectedIds.includes(t[refKey]) })?.map(i => i.id) || []
founds = self.schedule.talks.filter(t => {
if (refKey === 'session_type') {
if (typeof t.session_type === 'string') {
return selectedIds.includes(t.session_type)
} else {
return Object.keys(t.session_type).some(key => selectedIds.includes(t.session_type[key]))
}
}
return selectedIds.includes(t[refKey])
})?.map(i => i.id) || []
}
results = founds
}
Expand Down Expand Up @@ -204,9 +221,45 @@ export default {
},
filter() {
const filter = this.defaultFilter
filter.tracks.data = this.schedule.tracks.map(t => { t.value = t.id; t.label = t.name; return t })
filter.rooms.data = this.schedule.rooms.map(t => { t.value = t.id; t.label = t.name; return t })
filter.types.data = this.schedule.session_type.map(t => { t.value = t.session_type; t.label = t.session_type; return t })
const setSessionType = new Set()
const enLanguage = 'en'
this.schedule.session_type.forEach(t => {
if (typeof t.session_type === 'string') {
setSessionType.add(t.session_type)
} else {
const sessionTypeKeyArray = Object.keys(t.session_type)
let isEnglish = false
for (let i = 0; i < sessionTypeKeyArray.length; i++) {
if (sessionTypeKeyArray[i] === this.getLanguage()) {
setSessionType.add(t.session_type[sessionTypeKeyArray[i]])
break
}

Check failure on line 238 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else if (sessionTypeKeyArray[i] === enLanguage) {
isEnglish = true
if (i === sessionTypeKeyArray.length - 1) {
setSessionType.add(t.session_type[enLanguage])
}
}

Check failure on line 244 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else {
if (i === sessionTypeKeyArray.length - 1) {
if (isEnglish) {
setSessionType.add(t.session_type[enLanguage])
}

Check failure on line 249 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else {
setSessionType.add(t.session_type[sessionTypeKeyArray[i]])
}
}
}
}
}
})
filter.types.data = Array.from(setSessionType).map(t => { return { value: t, label: t } })
filter.tracks.data = this.filterLanguage(this.schedule.tracks)
filter.rooms.data = this.filterLanguage(this.schedule.rooms)
return filter
}
},
Expand Down Expand Up @@ -296,6 +349,49 @@ export default {
},
resetOnlyFavs() {
this.onlyFavs = false
},
getLanguage() {
return localStorage.getItem('userLanguage') || 'en'
},
filterLanguage(data) {
const setMap = new Map()
const enLanguage = 'en'
data.forEach(
t => {
if (typeof t.name === 'string') {
setMap.set(t.id, t.name)
} else {
const keyArray = Object.keys(t.name)
let isEnglish = false
for (let i = 0; i < keyArray.length; i++) {
if (keyArray[i] === this.getLanguage()) {
setMap.set(t.id, t.name[keyArray[i]])
break
}

Check failure on line 372 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else if (keyArray[i] === enLanguage) {
isEnglish = true
if (i === keyArray.length - 1) {
setMap.set(t.id, t.name[enLanguage])
}
}

Check failure on line 378 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else {
if (i === keyArray.length - 1) {
if (isEnglish) {
setMap.set(t.id, t.name[enLanguage])
}

Check failure on line 383 in webapp/src/views/schedule/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace does not appear on the same line as the subsequent block
else {
setMap.set(t.id, t.name[keyArray[i]])
}
}
}
}
}
}
)
return Array.from(setMap).map(t => { return { value: t[0], label: t[1] } })
}
}
}
Expand Down
106 changes: 101 additions & 5 deletions webapp/src/views/schedule/sessions/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,26 @@ export default {
let founds = null
if (selectedIds.length) {
if (results && results.length) {
founds = self.schedule.talks.filter(t => selectedIds.includes(t[refKey]) && results && results.includes(t.id))?.map(i => i.id) || []
founds = self.schedule.talks.filter(t => {
if (refKey === 'session_type') {
if (typeof t.session_type === 'string') {
return selectedIds.includes(t.session_type) && results.includes(t.id)
} else {
return Object.keys(t.session_type).some(key => selectedIds.includes(t.session_type[key])) && results.includes(t.id)
}
}
return selectedIds.includes(t[refKey]) && results && results.includes(t.id)})?.map(i => i.id) || []

Check failure on line 153 in webapp/src/views/schedule/sessions/index.vue

View workflow job for this annotation

GitHub Actions / build

Requires a space before '}'

Check failure on line 153 in webapp/src/views/schedule/sessions/index.vue

View workflow job for this annotation

GitHub Actions / build

Closing curly brace should be on the same line as opening curly brace or on the line after the previous block
} else {
founds = self.schedule.talks.filter(t => { return selectedIds.includes(t[refKey]) })?.map(i => i.id) || []
founds = self.schedule.talks.filter(t => {
if (refKey === 'session_type') {
if (typeof t.session_type === 'string') {
return selectedIds.includes(t.session_type)
} else {
return Object.keys(t.session_type).some(key => selectedIds.includes(t.session_type[key]))
}
}
return selectedIds.includes(t[refKey])
})?.map(i => i.id) || []
}
results = founds
}
Expand Down Expand Up @@ -192,9 +209,45 @@ export default {
},
filter() {
const filter = this.defaultFilter
filter.tracks.data = this.schedule.tracks.map(t => { t.value = t.id; t.label = t.name; return t })
filter.rooms.data = this.schedule.rooms.map(t => { t.value = t.id; t.label = t.name; return t })
filter.types.data = this.schedule.session_type.map(t => { t.value = t.session_type; t.label = t.session_type; return t })
const setSessionType = new Set()
const enLanguage = 'en'
this.schedule.session_type.forEach(t => {
if (typeof t.session_type === 'string') {
setSessionType.add(t.session_type)
} else {
const sessionTypeKeyArray = Object.keys(t.session_type)
let isEnglish = false
for (let i = 0; i < sessionTypeKeyArray.length; i++) {
if(sessionTypeKeyArray[i] === this.getLanguage()) {
setSessionType.add(t.session_type[sessionTypeKeyArray[i]])
break
}
else if (sessionTypeKeyArray[i] === enLanguage) {
isEnglish = true
if(i === sessionTypeKeyArray.length - 1) {
setSessionType.add(t.session_type[enLanguage])
}
}
else {
if (i === sessionTypeKeyArray.length - 1) {
if(isEnglish){
setSessionType.add(t.session_type[enLanguage])
}
else {
setSessionType.add(t.session_type[sessionTypeKeyArray[i]])
}
}
}
}
}
})
filter.types.data = Array.from(setSessionType).map(t => { return { value: t, label: t } })
filter.rooms.data = this.filterLanguage(this.schedule.rooms)
filter.tracks.data = this.filterLanguage(this.schedule.tracks)
return filter
}
},
Expand Down Expand Up @@ -284,6 +337,49 @@ export default {
},
resetOnlyFavs() {
this.onlyFavs = false
},
getLanguage() {
return localStorage.getItem('userLanguage') || 'en'
},
filterLanguage(data) {
const setMap = new Map()
const enLanguage = 'en'
data.forEach(
t => {
if (typeof t.name === 'string') {
setMap.set(t.id, t.name)
} else {
const keyArray = Object.keys(t.name)
let isEnglish = false
for (let i = 0; i < keyArray.length; i++) {
if (keyArray[i] === this.getLanguage()) {
setMap.set(t.id, t.name[keyArray[i]])
break
}
else if (keyArray[i] === enLanguage) {
isEnglish = true
if (i === keyArray.length - 1) {
setMap.set(t.id, t.name[enLanguage])
}
}
else {
if (i === keyArray.length - 1) {
if (isEnglish) {
setMap.set(t.id, t.name[enLanguage])
}
else {
setMap.set(t.id, t.name[keyArray[i]])
}
}
}
}
}
}
)
return Array.from(setMap).map(t => { return { value: t[0], label: t[1] } })
}
}
}
Expand Down

0 comments on commit b55c4bb

Please sign in to comment.