Merge pull request #731 from yuya-oc/fix-spellchecker

Fix correct spellchecker locale is not selected for non en-US locales
This commit is contained in:
Yuya Ochiai
2018-03-16 00:12:31 +09:00
committed by GitHub
4 changed files with 31 additions and 8 deletions

View File

@@ -15,7 +15,6 @@ const defaultPreferences = {
},
showUnreadBadge: true,
useSpellChecker: true,
spellCheckerLocale: 'en-US',
};
module.exports = defaultPreferences;

View File

@@ -12,11 +12,8 @@ function merge(base, target) {
const defaultPreferences = require('./config/defaultPreferences');
const upgradePreferences = require('./config/upgradePreferences');
function loadDefault(spellCheckerLocale) {
const config = JSON.parse(JSON.stringify(defaultPreferences));
return Object.assign({}, config, {
spellCheckerLocale: spellCheckerLocale || defaultPreferences.spellCheckerLocale || 'en-US',
});
function loadDefault() {
return JSON.parse(JSON.stringify(defaultPreferences));
}
function hasBuildConfigDefaultTeams(config) {

View File

@@ -79,8 +79,7 @@ try {
settings.writeFileSync(configFile, config);
}
} catch (e) {
const spellCheckerLocale = SpellChecker.getSpellCheckerLocale(app.getLocale());
config = settings.loadDefault(null, spellCheckerLocale);
config = settings.loadDefault();
console.log('Failed to read or upgrade config.json', e);
if (!config.teams.length && config.defaultTeam) {
config.teams.push(config.defaultTeam);
@@ -386,6 +385,12 @@ app.on('ready', () => {
return;
}
if (!config.spellCheckerLocale) {
config.spellCheckerLocale = SpellChecker.getSpellCheckerLocale(app.getLocale());
const configFile = app.getPath('userData') + '/config.json';
settings.writeFileSync(configFile, config);
}
const appStateJson = path.join(app.getPath('userData'), 'app-state.json');
appState = new AppStateManager(appStateJson);
if (wasUpdated(appState.lastAppVersion)) {

View File

@@ -3,6 +3,28 @@ const path = require('path');
const SpellChecker = require('../../src/main/SpellChecker');
describe('main/Spellchecker.js', function() {
describe('getSpellCheckerLocale()', () => {
it('should return recognized locale', () => {
SpellChecker.getSpellCheckerLocale('en').should.equal('en-US');
SpellChecker.getSpellCheckerLocale('en-US').should.equal('en-US');
SpellChecker.getSpellCheckerLocale('fr').should.equal('fr-FR');
SpellChecker.getSpellCheckerLocale('fr-FR').should.equal('fr-FR');
SpellChecker.getSpellCheckerLocale('de').should.equal('de-DE');
SpellChecker.getSpellCheckerLocale('de-DE').should.equal('de-DE');
SpellChecker.getSpellCheckerLocale('es').should.equal('es-ES');
SpellChecker.getSpellCheckerLocale('es-ES').should.equal('es-ES');
SpellChecker.getSpellCheckerLocale('nl').should.equal('nl-NL');
SpellChecker.getSpellCheckerLocale('nl-NL').should.equal('nl-NL');
SpellChecker.getSpellCheckerLocale('ja').should.equal('en-US');
SpellChecker.getSpellCheckerLocale('ja-JP').should.equal('en-US');
});
});
describe('en-US', function() {
let spellchecker = null;