1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-23 23:47:57 +01:00
Whalebird-desktop-client-ma.../renderer/utils/flattenMessage.ts
AkiraFukushima 0375e02d93
Setup i18n
2023-11-04 15:32:37 +09:00

15 lines
467 B
TypeScript

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
}, {})
}