| 11 | }; |
| 12 | |
| 13 | const convertData = (data, locale, options) => { |
| 14 | if (!data) return ''; |
| 15 | if (Array.isArray(data)) |
| 16 | return data.map(d => convertData(d, locale, options)); |
| 17 | if (typeof data !== 'object') return applyReplacements(data, options); |
| 18 | const pluralMsg = |
| 19 | options.pluralVariable && getPluralMessage(data, locale, options); |
| 20 | if (pluralMsg) return pluralMsg; |
| 21 | |
| 22 | return Object.keys(data).reduce((res, key) => { |
| 23 | const { includeLocales: il, verbose } = options; |
| 24 | const isLcKey = (!il || il.includes(key)) && pluralCategories[key]; |
| 25 | if (isLcKey) { |
| 26 | options._lc[key] = true; |
| 27 | if (verbose) console.log(`messageformat-convert: Found locale ${key}`); |
| 28 | } |
| 29 | res[key] = convertData(data[key], isLcKey ? key : locale, options); |
| 30 | return res; |
| 31 | }, {}); |
| 32 | }; |
| 33 | |
| 34 | const convert = (data, options) => { |
| 35 | if (data.length === 1) data = data[0]; |