( moduleName: string, fileContent: string, l10nsvcDirectiveMode: LocalizationServiceDirectiveParsingMode, )
| 47 | } |
| 48 | |
| 49 | export 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 | |
| 75 | function sortStringsJSON(stringsJSON: GenerateStringsJSONResult): GenerateStringsJSONResult { |
| 76 | const ordered = Object.keys(stringsJSON) |
no test coverage detected