Skip to content

Validate AppleLocale against supported locales #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 26, 2018
Merged
Changes from 2 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.indexOf(locale) === -1 ? defaultLocale : locale;
}

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

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

function getUnixLocale() {
Expand Down