Enhance Breadcrumbs (#39)
* chore(localization): remove duplicated locale files * feat(localization): add localization for breadcrumbs * feat(localization): add beadcrumb enhancements * feat(debugging): add npm run debug command * chore(localization): add unit tests * chore(breadcrumbs): fix tests and typos * chore(localization): add docs for translationAvailable * chore(localization): refactor translationAvailable
This commit is contained in:
committed by
GitHub
parent
a48fd1b63d
commit
81577c82fd
@@ -1,5 +1,5 @@
|
||||
const url = require('url')
|
||||
const { translate } = require('../i18n/i18n')
|
||||
const { translate, translationAvaliable } = require('../i18n/i18n')
|
||||
|
||||
module.exports = (modifier) => {
|
||||
return (request, response, next) => {
|
||||
@@ -13,17 +13,26 @@ module.exports = (modifier) => {
|
||||
})
|
||||
// Map components of the path to breadcrumbs with resolvable URLs
|
||||
let mappedComponents = urlComponents.map((component, i, array) => {
|
||||
const currentLocale = response.locals.currentLocale
|
||||
const path = array.slice(0, i + 1).join('/')
|
||||
|
||||
let label = component.replace(/-/g, ' ')
|
||||
if (translationAvaliable(`${label}Label`, currentLocale.code)) {
|
||||
label = translate(`${label}Label`, currentLocale.code)
|
||||
}
|
||||
|
||||
return {
|
||||
label: component.replace(/-/g, ' '),
|
||||
label: label,
|
||||
url: url.resolve(baseUrl, path),
|
||||
path: path
|
||||
}
|
||||
})
|
||||
|
||||
breadcrumbs = breadcrumbs.concat(mappedComponents)
|
||||
if (modifier) {
|
||||
breadcrumbs = breadcrumbs.map(modifier)
|
||||
}
|
||||
|
||||
// Make it global
|
||||
request.app.locals.breadcrumb = breadcrumbs
|
||||
next()
|
||||
|
||||
Reference in New Issue
Block a user