summaryrefslogtreecommitdiff
path: root/shared/storefronts/src
diff options
context:
space:
mode:
authorrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
committerrxliuli <rxliuli@gmail.com>2025-11-04 05:03:50 +0800
commitbce557cc2dc767628bed6aac87301a1be7c5431b (patch)
treeb51a051228d01fe3306cd7626d4a96768aadb944 /shared/storefronts/src
init commit
Diffstat (limited to 'shared/storefronts/src')
-rw-r--r--shared/storefronts/src/index.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/shared/storefronts/src/index.js b/shared/storefronts/src/index.js
new file mode 100644
index 0000000..74f4843
--- /dev/null
+++ b/shared/storefronts/src/index.js
@@ -0,0 +1,19 @@
+// helper functions available for use at runtime
+/**
+ * @param {Region[]} regions - array of region objects that include region name and locales
+ * @returns {StorefrontNameTranslations} - storefront ID (ie: us) mapped to that storefront name translated in all supported languages
+ */
+export function getFormattedStorefrontNameTranslations(regions) {
+ return Object.fromEntries(
+ regions.flatMap(({ locales }) => {
+ const storefronts = {};
+ for (const locale of locales) {
+ if (!(locale.id in storefronts)) {
+ storefronts[locale.id] = { default: locale.name };
+ }
+ storefronts[locale.id][locale.language] = locale.name;
+ }
+ return Object.entries(storefronts);
+ }),
+ );
+}