0
Hello, I have a Ode application that uses express and handlebars, I would like to make it available in 3 different languages (Portuguese, Spanish and English).
I managed to do this by creating a different file for each language, but it ended up getting very messy, and I’m not sure if this is the right way.
const renderLang = ['en', 'pt', 'es']
const renderTitle = ['What is my IP?', 'Qual é o meu IP?', '¿Cual es mi IP?']
router.get('/lookup', function(req, res) {
let getSubDomain = req.headers.host.split(`.`)
let renderSelectLang = verifyLang(getSubDomain[0])
res.render(renderSelectLang[0] + '/lookup', {lang: renderSelectLang[0], title: renderSelectLang[1]})
})
function verifyLang(subDomain) {
let renderSelectLang = [renderLang[0], renderTitle[0]]
if(subDomain == 'pt') {
renderSelectLang = [renderLang[1], renderTitle[1]]
} else if(subDomain == 'es') {
renderSelectLang = [renderLang[2], renderTitle[2]]
}
return renderSelectLang
}
And I’m also using sub-domains, one for each language 'pt' and 'es' and the default route is in English.
I need some more efficient way to define languages but I don’t know how to do it.
I thought of creating an external file such as a JSON and storing the messages but I don’t know if this is correct and also don’t know how it can be done.