add app.setLocale() (#11469)
* infrastructure for setLocale via klang * add documentation for setLocale * add test for setLocale * fix spec * add spec and update docs * fix carriage feeds on windows * SetLocale() sets LC_ALL on Linux * in SetLocale() on Linux, use g_setenv() * fix tyop: '#ifdef OSX_POSIX' * make the linter happy * improvements from review
This commit is contained in:
parent
e3f1d90854
commit
ca34978e73
9 changed files with 92 additions and 16 deletions
|
@ -112,6 +112,25 @@ describe('app module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('app.setLocale()', () => {
|
||||
const testLocale = (locale, result, done) => {
|
||||
const appPath = path.join(__dirname, 'fixtures', 'api', 'locale-check')
|
||||
const electronPath = remote.getGlobal('process').execPath
|
||||
let output = ''
|
||||
let appProcess = ChildProcess.spawn(electronPath, [appPath, `--lang=${locale}`])
|
||||
|
||||
appProcess.stdout.on('data', (data) => { output += data })
|
||||
appProcess.stdout.on('end', () => {
|
||||
output = output.replace(/(\r\n|\n|\r)/gm, '')
|
||||
assert.equal(output, result)
|
||||
done()
|
||||
})
|
||||
}
|
||||
|
||||
it('should set the locale', (done) => testLocale('fr', 'fr', done))
|
||||
it('should not set an invalid locale', (done) => testLocale('asdfkl', 'en-US', done))
|
||||
})
|
||||
|
||||
describe('app.isInApplicationsFolder()', () => {
|
||||
before(function () {
|
||||
if (process.platform !== 'darwin') {
|
||||
|
|
10
spec/fixtures/api/locale-check/main.js
vendored
Normal file
10
spec/fixtures/api/locale-check/main.js
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
const {app} = require('electron')
|
||||
|
||||
app.on('ready', () => {
|
||||
process.stdout.write(app.getLocale())
|
||||
process.stdout.end()
|
||||
|
||||
setImmediate(() => {
|
||||
app.quit()
|
||||
})
|
||||
})
|
5
spec/fixtures/api/locale-check/package.json
vendored
Normal file
5
spec/fixtures/api/locale-check/package.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "locale-check",
|
||||
"main": "main.js"
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue