Skip to content
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

Allow BCP-47 language codes in spell checker #2410

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/preferences/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
},
"spellcheckerLanguage": {
"description": "Spelling--The spell checker language",
"pattern": "^[a-z]{2}(?:[-][A-Z]{2})?$",
"pattern": "^[a-z]{2,3}(?:[-](?:[0-9]|[a-zA-Z]){2,}){0,2}$",
"default": "en-US"
},
"imageInsertAction": {
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/spellchecker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ export class SpellChecker {
}

if (!this.isHunspell) {
// NB: OS X will return lists that are half just a language, half
// language + locale, like ['en', 'pt_BR', 'ko']
// NOTE: OS X will return lists that are half just a language, half
// language + locale, like ['en', 'pt_BR', 'ko'] and Windows also returns
// BCP-47 ones.
return this.provider.currentSpellchecker.getAvailableDictionaries()
.map(x => {
if (x.length === 2) return fallbackLocales[x]
Expand All @@ -307,6 +308,7 @@ export class SpellChecker {
return null
}
})
.filter(x => { return !!x })
}

// Load hunspell dictionaries from disk.
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/spellchecker/languageMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import langMap from 'iso-639-1'
/**
* Return the native language name by language code.
*
* @param {string} langCode The ISO two or four-letter language code (e.g. en, en-US).
* @param {string} langCode The ISO two or four-letter language code (e.g. en, en-US) or BCP-47 code.
*/
export const getLanguageName = languageCode => {
if (!languageCode || (languageCode.length !== 2 && languageCode.length !== 5)) {
if (!languageCode || languageCode.length < 2) {
return null
}

Expand Down