mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Only look for file exists and read file on supported locale directories that we build (#42505)
Fixes #42263
This commit is contained in:
1 parent
6ed344f2c8
commit
b8faaea90c
2 files changed
+33
-2
No files matched your search
@@ -318,6 +318,9 @@ namespace ts {
|
||||
return getCombinedFlags(node, n => n.flags);
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export const supportedLocaleDirectories = ["cs", "de", "es", "fr", "it", "ja", "ko", "pl", "pt-br", "ru", "tr", "zh-cn", "zh-tw"];
|
||||
|
||||
/**
|
||||
* Checks to see if the locale is in the appropriate format,
|
||||
* and if it is, attempts to set the appropriate language.
|
||||
@@ -326,7 +329,8 @@ namespace ts {
|
||||
locale: string,
|
||||
sys: { getExecutingFilePath(): string, resolvePath(path: string): string, fileExists(fileName: string): boolean, readFile(fileName: string): string | undefined },
|
||||
errors?: Push<Diagnostic>) {
|
||||
const matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase());
|
||||
const lowerCaseLocale = locale.toLowerCase();
|
||||
const matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(lowerCaseLocale);
|
||||
|
||||
if (!matchResult) {
|
||||
if (errors) {
|
||||
@@ -340,7 +344,7 @@ namespace ts {
|
||||
|
||||
// First try the entire locale, then fall back to just language if that's all we have.
|
||||
// Either ways do not fail, and fallback to the English diagnostic strings.
|
||||
if (!trySetLanguageAndTerritory(language, territory, errors)) {
|
||||
if (contains(supportedLocaleDirectories, lowerCaseLocale) && !trySetLanguageAndTerritory(language, territory, errors)) {
|
||||
trySetLanguageAndTerritory(language, /*territory*/ undefined, errors);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user