MCPcopy Create free account
hub / github.com/Snapchat/Valdi / exportStringsFiles

Function exportStringsFiles

compiler/companion/src/strings/exportStringsFiles.ts:20–66  ·  view source on GitHub ↗
(
  moduleName: string,
  inputStringsDir: string,
  iosOutputPath?: string,
  androidOutputPath?: string,
)

Source from the content-addressed store, hash-verified

18} from './GenerateStringsFiles';
19
20export 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
68async function exportStringsFile(
69 moduleName: string,

Callers 1

addBaseEndpointsMethod · 0.90

Calls 9

fileExistsFunction · 0.90
inputJSONPathFunction · 0.85
androidStringsXMLPathFunction · 0.85
exportStringsFileFunction · 0.85
keysMethod · 0.65
getMethod · 0.65
allMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected