Flattens a nested translation object into a single-level key-value map.
(tree, prefix = '')
| 13 | |
| 14 | /** Flattens a nested translation object into a single-level key-value map. */ |
| 15 | function flatten(tree, prefix = '') { |
| 16 | const entries = {}; |
| 17 | for (const [key, value] of Object.entries(tree)) { |
| 18 | const fullKey = prefix ? `${prefix}.${key}` : key; |
| 19 | if (typeof value === 'string') { |
| 20 | entries[fullKey] = value; |
| 21 | } else if (value && typeof value === 'object' && !Array.isArray(value)) { |
| 22 | Object.assign(entries, flatten(value, fullKey)); |
| 23 | } |
| 24 | } |
| 25 | return entries; |
| 26 | } |
| 27 | |
| 28 | /** Hashes a string using SHA1. */ |
| 29 | function hash(str) { |