Created
March 17, 2017 02:18
-
-
Save wangpin34/9a959b86326ee71f1ac233698ec962f4 to your computer and use it in GitHub Desktop.
retrieve locale and language info of windows os
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const spawn = require('child_process').spawn; | |
const locales = spawn('systeminfo.exe', []); | |
const localeReg = /([a-z]+-[a-z]+);/ig; | |
let result = ""; | |
locales.stdout.on('data', (data) => { | |
if(data && data.length > 0){ | |
result += data; | |
} | |
}); | |
locales.stderr.on('data', (data) => { | |
console.log(`stderr: ${data}`); | |
}); | |
locales.on('close', (code) => { | |
console.log(`child process exited with code ${code}`); | |
let parts = localeReg.exec(result); | |
if(parts){ | |
console.log('Region or Locale: ' + parts[0]); | |
} | |
parts = localeReg.exec(result); | |
if(parts){ | |
console.log('Input language: ' + parts[0]); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment