UNPKG

@intl-t/core

Version:

A Fully-Typed Node-Based i18n Translation Library

12 lines (11 loc) 637 B
import { isClient } from "@intl-t/global"; export function getLocale(node, locale, preload = !isClient) { if (preload && typeof node === "function") return getLocale(node(locale), locale, preload); return node; } export async function getLocales(node, list, preload = typeof list === "boolean" ? list : void 0) { let locales = typeof node === "object" ? node : typeof list !== "object" ? {} : list.reduce((acc, locale) => ({ ...acc, [locale]: node }), {}); await Promise.all(Object.keys(locales).map(async (locale) => (locales[locale] = await getLocale(locales[locale], locale, preload)))); return locales; }