mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-18 07:01:58 +08:00
16 lines
542 B
JavaScript
16 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;
|
||
|
}, {});
|
||
|
}
|