@type {(filePath: string) => Promise }
(filePath)
| 14 | |
| 15 | /** @type {(filePath: string) => Promise<LocaleMessages>} */ |
| 16 | async function localeFileToJson(filePath) { |
| 17 | let file = await readFile(filePath); |
| 18 | file = file.replace(/^#.*?$/gm, ''); |
| 19 | |
| 20 | /** @type {LocaleMessages} */ |
| 21 | const messages = {}; |
| 22 | |
| 23 | const regex = /@([a-z0-9_]+)/ig; |
| 24 | let match; |
| 25 | while ((match = regex.exec(file))) { |
| 26 | const messageName = match[1]; |
| 27 | const messageStart = match.index + match[0].length; |
| 28 | let messageEnd = file.indexOf('@', messageStart); |
| 29 | if (messageEnd < 0) { |
| 30 | messageEnd = file.length; |
| 31 | } |
| 32 | messages[messageName] = { |
| 33 | message: file.substring(messageStart, messageEnd).trim(), |
| 34 | }; |
| 35 | } |
| 36 | |
| 37 | return messages; |
| 38 | } |
| 39 | |
| 40 | /** @type {(localesDir: string, code: string) => Promise<string>} */ |
| 41 | async function mergeLocale(localesDir, code) { |