Allow BCP-47 language codes in spell checker (#2410)

This commit is contained in:
Felix Häusler 2020-11-30 09:17:02 +01:00 committed by GitHub
parent 5878e4c514
commit 22cdd11864
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -338,7 +338,7 @@
}, },
"spellcheckerLanguage": { "spellcheckerLanguage": {
"description": "Spelling--The spell checker language", "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" "default": "en-US"
}, },
"imageInsertAction": { "imageInsertAction": {

View File

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

View File

@ -3,10 +3,10 @@ import langMap from 'iso-639-1'
/** /**
* Return the native language name by language code. * 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 => { export const getLanguageName = languageCode => {
if (!languageCode || (languageCode.length !== 2 && languageCode.length !== 5)) { if (!languageCode || languageCode.length < 2) {
return null return null
} }