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

Function parseStringsJSON

compiler/companion/src/strings/GenerateStringsFiles.ts:49–73  ·  view source on GitHub ↗
(
  moduleName: string,
  fileContent: string,
  l10nsvcDirectiveMode: LocalizationServiceDirectiveParsingMode,
)

Source from the content-addressed store, hash-verified

47}
48
49export function parseStringsJSON(
50 moduleName: string,
51 fileContent: string,
52 l10nsvcDirectiveMode: LocalizationServiceDirectiveParsingMode,
53) {
54 const parsed = JSON.parse(fileContent);
55 // Snap-specific: a "l10nsvc": "sourcefile" key/value pair is used as an annotation required by the Snap Localization Service:
56 // We ignore it when processing the strings.json file
57 const keyToIgnore = 'l10nsvc';
58 if (parsed.hasOwnProperty(keyToIgnore)) {
59 delete parsed[keyToIgnore];
60 } else {
61 switch (l10nsvcDirectiveMode) {
62 case LocalizationServiceDirectiveParsingMode.Ignore:
63 break;
64 case LocalizationServiceDirectiveParsingMode.Require:
65 throw new Error(
66 `Expected l10nsvc directive not found in strings.json for ${moduleName}.\n\n ⚠️ ⚠️ ⚠️\nPlease update ${moduleName}'s strings-en.json to include a "l10nsvc": "sourcefile" key/value pair.\n ⚠️ ⚠️ ⚠️\n`,
67 );
68 }
69 }
70
71 const ordered = sortStringsJSON(parsed);
72 return ordered;
73}
74
75function sortStringsJSON(stringsJSON: GenerateStringsJSONResult): GenerateStringsJSONResult {
76 const ordered = Object.keys(stringsJSON)

Callers 2

parseStringsJSONAtPathFunction · 0.85

Calls 2

sortStringsJSONFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected