export type NonRecordType = boolean|number|bigint|string|symbol|any[]; export type I18N = (T & NonRecordType) | Record; export type LocaleInfo = { locale?: string defaultLocale?: string }; export function translate( data: I18N, {locale, defaultLocale=''}: LocaleInfo, ): T; export function translate( data: I18N|null, {locale, defaultLocale=''}: LocaleInfo, ): null; export function translate( data: I18N|undefined, {locale, defaultLocale=''}: LocaleInfo, ): undefined; export function translate( data: I18N|U, {locale, defaultLocale=''}: LocaleInfo, ): T|U { if (data == null) return data; if (typeof data !== 'object') return data; if (data instanceof Array) return data; return (locale == null ? undefined : data[locale]) ?? data[defaultLocale] ?? Object.values(data)[0]; }