mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-09 17:09:45 +08:00
15 lines
542 B
JavaScript
15 lines
542 B
JavaScript
// with this utility function we can write nested locales like an json object
|
|
export function flattenMessages(nestedMessages, prefix = '') {
|
|
return Object.keys(nestedMessages).reduce((messages, key) => {
|
|
let value = nestedMessages[key];
|
|
let prefixedKey = prefix ? `${prefix}.${key}` : key;
|
|
|
|
if (typeof value === 'string') {
|
|
messages[prefixedKey] = value;
|
|
} else {
|
|
Object.assign(messages, flattenMessages(value, prefixedKey));
|
|
}
|
|
|
|
return messages;
|
|
}, {});
|
|
}
|