mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 00:01:19 +08:00
Allow BCP-47 language codes in spell checker (#2410)
This commit is contained in:
parent
5878e4c514
commit
22cdd11864
@ -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": {
|
||||||
|
@ -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.
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user