Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,30 @@ function getLocale(string) {
return (string && string.replace(/[.:].*/, ''));
}

function getLocales() {
return execa.stdout('locale', ['-a']);
}

function getLocalesSync() {
return execa.sync('locale', ['-a']).stdout;
}

function getSupportedLocale(locale, locales = '') {
return locales.includes(locale) ? locale : defaultLocale;
}

function getAppleLocale() {
return execa.stdout('defaults', ['read', '-globalDomain', 'AppleLocale']);
return Promise.all([
execa.stdout('defaults', ['read', '-globalDomain', 'AppleLocale']),
getLocales()
]).then(results => getSupportedLocale(results[0], results[1]));
}

function getAppleLocaleSync() {
return execa.sync('defaults', ['read', '-globalDomain', 'AppleLocale']).stdout;
return getSupportedLocale(
execa.sync('defaults', ['read', '-globalDomain', 'AppleLocale']).stdout,
getLocalesSync()
);
}

function getUnixLocale() {
Expand Down