-
Notifications
You must be signed in to change notification settings - Fork 902
Description
Feature Proposal
We propose adding functionality to separate the survey layout JSON from localized strings, allowing them to be stored in separate files and fetched/loaded at runtime. This would improve modularity, especially for applications handling multiple languages dynamically.
Proposed Changes
-
Extend
ISaveToJSONOptionsInterface
Add the following options to control how localizable strings are handled during serialization:storeLocaleStrings?: boolean | "stringsOnly"; locales?: Array<string>;
Behavior based on
storeLocalizableStrings:false: Serialize without any localizable strings, including the default locale.true: The default behavior, you may not set it. Serialize only the specified locales fromlocales(e.g.,["default", "fr", "it"]) or if it is empty then all strings for all locales (default serializer behavior)."stringsOnly": Serialize only object types, unique properties, and localized strings (excludes other properties). Useful for isolating strings in a separate JSON file."stringsOnly"withlocales: Limits the strings to the specified locales (e.g., only Italian with["it"]).
Examples usage:
//exclude all locales except default, "fr" and "it"
const json = survey.toJSON({ locales: ["default", "fr", "it"] }); //serialize strings only and ingore all locales except "fr" and "it"
const json = survey.toJSON({ storeLocalizableStrings: "stringsOnly", locales: ["fr", "it"] }); //do not serialize any strings, including the text for default locale
const json = survey.toJSON({ storeLocalizableStrings: false ); -
New Method:
survey.mergeLocalizationJSON(json: any, locales?: Array<string>): void
This method merges localized strings from a provided JSON into the existing survey. It enables loading translations from separate files on demand, supporting dynamic locale switching.Example:
// Assume 'translations.json' contains strings for 'fr' and 'it' fetch('translations.json') .then(response => response.json()) .then(translations => { survey.mergeLocalizationJSON(translations, ["fr"]); // Load only French strings });
-
New Method:
survey.getLocalizationJSON(locales?: Array<string>): any
This function calls toJSON function with storeLocalizableStrings: "stringsOnly" parameter. It makes API simpler.
Benefits
- Reduces main survey JSON size by offloading translations.
- Facilitates easier management of multilingual surveys.
- Enables runtime loading for better performance in web apps.