feat: add i18n meta tags (title, description) in all 7 languages with dynamic updates on locale change
This commit is contained in:
18
js/i18n.js
18
js/i18n.js
@@ -183,6 +183,24 @@ class I18n {
|
||||
const key = el.getAttribute('data-i18n-aria')
|
||||
el.setAttribute('aria-label', this.t(key))
|
||||
})
|
||||
|
||||
const metaTitle = this.t('meta.title')
|
||||
if (metaTitle !== 'meta.title') {
|
||||
document.title = metaTitle
|
||||
const ogTitle = document.querySelector('meta[property="og:title"]')
|
||||
if (ogTitle) ogTitle.setAttribute('content', metaTitle)
|
||||
const twTitle = document.querySelector('meta[name="twitter:title"]')
|
||||
if (twTitle) twTitle.setAttribute('content', metaTitle)
|
||||
}
|
||||
const metaDesc = this.t('meta.description')
|
||||
if (metaDesc !== 'meta.description') {
|
||||
const desc = document.querySelector('meta[name="description"]')
|
||||
if (desc) desc.setAttribute('content', metaDesc)
|
||||
const ogDesc = document.querySelector('meta[property="og:description"]')
|
||||
if (ogDesc) ogDesc.setAttribute('content', metaDesc)
|
||||
const twDesc = document.querySelector('meta[name="twitter:description"]')
|
||||
if (twDesc) twDesc.setAttribute('content', metaDesc)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user