Closed ghost closed 5 years ago
If I've understood correctly, I think you'd want to update:
const { messages } = { ...getNamespace(root, modulePath) }
messages[modulePath.pop()] = { ...requireModule(fileName) }
function getNamespace(subtree, path) {
if (path.length === 1) return subtree
const namespace = path.shift()
subtree[namespace] = { messages: {}, ...subtree[namespace] }
return getNamespace(subtree[namespace], path)
}
to something like:
const messages = getNamespace(root, modulePath)
messages[modulePath.pop()] = { ...requireModule(fileName) }
function getNamespace(subtree, path) {
if (path.length === 1) return subtree
const namespace = path.shift()
return getNamespace(subtree[namespace], path)
}
Thank you for taking the time to answer me.
Almost! With your proposition subtree[namespace] inside getNamespace function is undefined. I added subtree[namespace] = { ...subtree[namespace] } to make it work. Thanks for your help.
const messages = getNamespace(root, modulePath)
messages[modulePath.pop()] = { ...requireModule(fileName) }
function getNamespace(subtree, path) {
if (path.length === 1) return subtree
const namespace = path.shift()
subtree[namespace] = { ...subtree[namespace] }
return getNamespace(subtree[namespace], path)
}
other solution
const requireModule = require.context('.', true, /\.json$/)
const langs = {}
requireModule.keys().forEach(fileName => {
const path = fileName.replace(/(\.\/|\.json)/g, '')
const moduleName = path.split('/')
if (!langs.hasOwnProperty(moduleName[0])) {
langs[moduleName[0]] = { [moduleName[1]]: {} }
}
langs[moduleName[0]][moduleName[1]] = requireModule(fileName)
})
export default langs
Hi,
I would like to thank you first. I learned a lot with your boilerplate and your conferences.
I try unsuccessfully to edit the file state/modules/index.js to automatically import languages for Vue118
I would like to have as object structure :
But now I have
Can I be helped to remove the "messages" object?
langs folder structure
langs/messages/index.js
langs/index.js
the desired result is to not need to manually import each new language and have this :