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

Function exportStringsFile

compiler/companion/src/strings/exportStringsFiles.ts:68–129  ·  view source on GitHub ↗
(
  moduleName: string,
  inputLocale: string,
  baseStringsJSONPath: string,
  inputStringsJSONPath: string,
  outputIOSLocalizableStringsPath: string | undefined,
  outputAndroidStringsXMLPath: string | undefined,
)

Source from the content-addressed store, hash-verified

66}
67
68async function exportStringsFile(
69 moduleName: string,
70 inputLocale: string,
71 baseStringsJSONPath: string,
72 inputStringsJSONPath: string,
73 outputIOSLocalizableStringsPath: string | undefined,
74 outputAndroidStringsXMLPath: string | undefined,
75) {
76 const isExportingBaseLocale = inputLocale === 'en';
77
78 // Translation happens in the repo with the valdi_modules sources.
79
80 const exists = await fileExists(inputStringsJSONPath);
81 if (!exists) {
82 if (isExportingBaseLocale) {
83 throw new Error(`Expected base localization file at ${inputStringsJSONPath}, but it doesn't exist`);
84 } else {
85 // Translation file for that locale doesn't exist
86 return;
87 }
88 }
89
90 const baseEnglishStringsJSON = await parseStringsJSONAtPath(
91 moduleName,
92 baseStringsJSONPath,
93 LocalizationServiceDirectiveParsingMode.Ignore,
94 );
95 let l10nsvcDirectiveParsingMode = LocalizationServiceDirectiveParsingMode.Ignore;
96 if (isExportingBaseLocale) {
97 l10nsvcDirectiveParsingMode = LocalizationServiceDirectiveParsingMode.Require;
98 }
99 const inputStringsJSON = await parseStringsJSONAtPath(moduleName, inputStringsJSONPath, l10nsvcDirectiveParsingMode);
100 if (outputAndroidStringsXMLPath) {
101 await unlink(outputAndroidStringsXMLPath).catch((e) => undefined); // ignore errors
102 const androidOutput = await generateAndroidStringsXMLFromStringsJSON(
103 moduleName,
104 baseEnglishStringsJSON,
105 inputStringsJSON,
106 inputLocale,
107 );
108 if (androidOutput) {
109 const dirname = path.dirname(outputAndroidStringsXMLPath);
110 await mkdir(dirname, { recursive: true });
111 await writeFile(outputAndroidStringsXMLPath, androidOutput);
112 }
113 }
114
115 if (outputIOSLocalizableStringsPath) {
116 await unlink(outputIOSLocalizableStringsPath).catch((e) => undefined); // ignore errors
117 const iosOutput = generateIOSLocalizableStringsFromStringsJSON(
118 moduleName,
119 baseEnglishStringsJSON,
120 inputStringsJSON,
121 inputLocale,
122 );
123 if (iosOutput) {
124 const dirname = path.dirname(outputIOSLocalizableStringsPath);
125 await mkdir(dirname, { recursive: true });

Callers 1

exportStringsFilesFunction · 0.85

Tested by

no test coverage detected