index.js
1 // helper functions available for use at runtime 2 /** 3 * @param {Region[]} regions - array of region objects that include region name and locales 4 * @returns {StorefrontNameTranslations} - storefront ID (ie: us) mapped to that storefront name translated in all supported languages 5 */ 6 export function getFormattedStorefrontNameTranslations(regions) { 7 return Object.fromEntries( 8 regions.flatMap(({ locales }) => { 9 const storefronts = {}; 10 for (const locale of locales) { 11 if (!(locale.id in storefronts)) { 12 storefronts[locale.id] = { default: locale.name }; 13 } 14 storefronts[locale.id][locale.language] = locale.name; 15 } 16 return Object.entries(storefronts); 17 }), 18 ); 19 }