Whalebird-desktop-client-ma.../renderer/utils/flattenMessage.ts

15 lines
467 B
TypeScript
Raw Permalink Normal View History

2023-11-04 07:32:37 +01:00
export function flattenMessages(nestedMessages: { [key: string]: any }, prefix = ''): { [key: string]: string } {
return Object.keys(nestedMessages).reduce((messages, key) => {
const value = nestedMessages[key]
const prefixedKey = prefix ? `${prefix}.${key}` : key
if (typeof value === 'string') {
messages[prefixedKey] = value
} else {
Object.assign(messages, flattenMessages(value, prefixedKey))
}
return messages
}, {})
}