@google/clasp
Version:
Develop Apps Script Projects locally
37 lines (36 loc) • 1.21 kB
JavaScript
import { createIntl, createIntlCache } from '@formatjs/intl';
import Debug from 'debug';
const debug = Debug('clasp:intl');
function isDefined(item) {
return item !== null && item !== undefined;
}
function getLocale() {
const envLocales = [process.env.LC_ALL, process.env.LC_CTYPE, process.env.LANG].filter(isDefined);
for (const envLocale of envLocales) {
try {
// Attempt to normalize the locale string (e.g., "en_US" to "en-US")
const normalizedLocale = new Intl.Locale(envLocale).toString();
return normalizedLocale;
}
catch (_error) {
// Ignore invalid locale strings and try the next one
debug('Invalid locale string: %s', envLocale);
}
}
return 'en';
}
function loadMessages(_locale) {
// TODO - L10N not implemented yet.
return {};
}
const cache = createIntlCache();
const locale = getLocale();
const localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
debug('Using locale: %s', locale);
export const intl = createIntl({
// Locale of the application
locale,
timeZone: localTimeZone,
defaultLocale: 'en',
messages: loadMessages(locale),
}, cache);