Build a CLI tool that extracts translatable strings from XLSForm or XForm files and produces a JSON locale file, making it easy to translate humanitarian forms into local languages.
Usage: npx extract-translations --input form.xlsx --output locales/form.json
Output format:
{
formId: string,
version: string,
strings: {
[key: string]: {
default: string, // original English text
context: string, // e.g. 'label for field: patient_age'
translations: Record<string, string> // { 'sw': '...', 'fr': '...' }
}
}
}
Key generation: stable hash of {fieldPath}:{stringType} where stringType is label, hint, or constraint_message. Using a stable key means re-extracting after form edits preserves existing translations for unchanged strings.
Merge mode: if an existing locale file is provided via --merge existing.json, preserve translations for unchanged strings and flag changed strings with { _changed: true, _previous: '...' }.
Support both XLSForm (parse with xlsx library) and XForm XML input.
Write tests with a sample XLSForm fixture covering: basic label extraction, hint extraction, merge with unchanged strings, merge with changed strings.
No contributions yet.