( moduleName: string, inputStringsDir: string, iosOutputPath?: string, androidOutputPath?: string, )
| 18 | } from './GenerateStringsFiles'; |
| 19 | |
| 20 | export async function exportStringsFiles( |
| 21 | moduleName: string, |
| 22 | inputStringsDir: string, |
| 23 | iosOutputPath?: string, |
| 24 | androidOutputPath?: string, |
| 25 | ) { |
| 26 | const exists = await fileExists(inputStringsDir); |
| 27 | if (!exists) { |
| 28 | throw new Error(`Expected strings directory at ${inputStringsDir}, but it doesn't exist`); |
| 29 | } |
| 30 | |
| 31 | if (!iosOutputPath && !androidOutputPath) { |
| 32 | throw new Error('Asked to export strings, but no output paths provided'); |
| 33 | } |
| 34 | |
| 35 | const promises = []; |
| 36 | |
| 37 | let localeMap = fullLocaleMap; |
| 38 | for (const inputLocale of localeMap.keys()) { |
| 39 | const outputLocales = localeMap.get(inputLocale); |
| 40 | if (!outputLocales) { |
| 41 | throw new Error(`No known output locales for input locale ${inputLocale}`); |
| 42 | } |
| 43 | |
| 44 | const baseStringsJSONPath = inputJSONPath(inputStringsDir, 'en'); |
| 45 | |
| 46 | const inputStringsJSONPath = inputJSONPath(inputStringsDir, inputLocale); |
| 47 | const outputIOSLocalizableStringsPath = |
| 48 | iosOutputPath && iosLocalizableStringsPath(iosOutputPath, outputLocales.ios, moduleName); |
| 49 | const outputAndroidStringsXMLPath = |
| 50 | androidOutputPath && androidStringsXMLPath(androidOutputPath, outputLocales.android, moduleName); |
| 51 | |
| 52 | const promise = exportStringsFile( |
| 53 | moduleName, |
| 54 | inputLocale, |
| 55 | baseStringsJSONPath, |
| 56 | inputStringsJSONPath, |
| 57 | outputIOSLocalizableStringsPath, |
| 58 | outputAndroidStringsXMLPath, |
| 59 | ).catch((reason) => { |
| 60 | throw new Error(`Failed to export strings file for module '${moduleName}': ${reason}`); |
| 61 | }); |
| 62 | promises.push(promise); |
| 63 | } |
| 64 | |
| 65 | await Promise.all(promises); |
| 66 | } |
| 67 | |
| 68 | async function exportStringsFile( |
| 69 | moduleName: string, |
no test coverage detected