Skip to content

Commit 4dfa19b

Browse files
coreyfarrellBenjamin E. Coe
authored andcommitted
feat(i18n): swap out os-locale dependency for simple inline implementation (#1356)
1 parent 812048c commit 4dfa19b

File tree

4 files changed

+3
-16
lines changed

4 files changed

+3
-16
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"cliui": "^5.0.0",
2323
"find-up": "^3.0.0",
2424
"get-caller-file": "^2.0.1",
25-
"os-locale": "^3.1.0",
2625
"require-directory": "^2.1.1",
2726
"require-main-filename": "^2.0.0",
2827
"set-blocking": "^2.0.0",

test/validation.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ describe('validation tests', () => {
291291

292292
function loadLocale (locale) {
293293
delete require.cache[require.resolve('../')]
294-
delete require.cache[require.resolve('os-locale')]
295294
yargs = require('../')
296295
process.env.LC_ALL = locale
297296
}

test/yargs.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,6 @@ describe('yargs dsl tests', () => {
638638

639639
function loadLocale (locale) {
640640
delete require.cache[require.resolve('../')]
641-
delete require.cache[require.resolve('os-locale')]
642641
yargs = require('../')
643642
process.env.LC_ALL = locale
644643
}
@@ -687,17 +686,6 @@ describe('yargs dsl tests', () => {
687686
r.logs.join(' ').should.match(/Exibe ajuda/)
688687
})
689688

690-
it('handles os-locale throwing an exception', () => {
691-
// make os-locale throw.
692-
require('os-locale')
693-
require.cache[require.resolve('os-locale')].exports.sync = () => { throw Error('an error!') }
694-
695-
delete require.cache[require.resolve('../')]
696-
yargs = require('../')
697-
698-
yargs.locale().should.equal('en')
699-
})
700-
701689
it('uses locale string for help option default desc on .locale().help()', () => {
702690
const r = checkOutput(() => {
703691
yargs(['-h'])

yargs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,9 @@ function Yargs (processArgs, cwd, parentRequire) {
11811181
if (!detectLocale) return
11821182

11831183
try {
1184-
const osLocale = require('os-locale')
1185-
self.locale(osLocale.sync({ spawn: false }))
1184+
const { env } = process
1185+
const locale = env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE || 'en_US'
1186+
self.locale(locale.replace(/[.:].*/, ''))
11861187
} catch (err) {
11871188
// if we explode looking up locale just noop
11881189
// we'll keep using the default language 'en'.

0 commit comments

Comments
 (0)