mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 02:54:21 +08:00
fix(@angular/cli): allow for private use language subtags
Fixes: #17163
This commit is contained in:
parent
237bade5d5
commit
f0bada1925
@ -393,7 +393,7 @@
|
||||
"description": "Specifies the source locale of the application.",
|
||||
"default": "en-US",
|
||||
"$comment": "IETF BCP 47 language tag (simplified)",
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@ -402,7 +402,7 @@
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "Specifies the locale code of the source locale",
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$"
|
||||
},
|
||||
"baseHref": {
|
||||
"type": "string",
|
||||
@ -417,7 +417,7 @@
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"patternProperties": {
|
||||
"^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$": {
|
||||
"^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string",
|
||||
@ -2081,7 +2081,7 @@
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -211,7 +211,7 @@
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -175,7 +175,7 @@
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
@ -338,10 +338,13 @@ function findLocaleDataBasePath(projectRoot: string): string | null {
|
||||
}
|
||||
|
||||
function findLocaleDataPath(locale: string, basePath: string): string | null {
|
||||
const localeDataPath = path.join(basePath, locale + '.js');
|
||||
// Remove private use subtags
|
||||
const scrubbedLocale = locale.replace(/-x(-[a-zA-Z0-9]{1,8})+$/, '');
|
||||
|
||||
const localeDataPath = path.join(basePath, scrubbedLocale + '.js');
|
||||
|
||||
if (!fs.existsSync(localeDataPath)) {
|
||||
if (locale === 'en-US') {
|
||||
if (scrubbedLocale === 'en-US') {
|
||||
// fallback to known existing en-US locale data as of 9.0
|
||||
return findLocaleDataPath('en-US-POSIX', basePath);
|
||||
}
|
||||
|
@ -136,7 +136,7 @@
|
||||
"type": "string",
|
||||
"description": "Specifies the source locale of the application.",
|
||||
"default": "en-US",
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
@ -145,7 +145,7 @@
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "Specifies the locale code of the source locale",
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
|
||||
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$"
|
||||
},
|
||||
"baseHref": {
|
||||
"type": "string",
|
||||
@ -160,7 +160,7 @@
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"patternProperties": {
|
||||
"^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$": {
|
||||
"^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?(-x(-[a-zA-Z0-9]{1,8})+)?$": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string",
|
||||
|
@ -43,4 +43,18 @@ export default async function() {
|
||||
throw new Error('locale data not found warning shown');
|
||||
}
|
||||
|
||||
// Update angular.json
|
||||
await updateJsonFile('angular.json', workspaceJson => {
|
||||
const appProject = workspaceJson.projects['test-project'];
|
||||
// tslint:disable-next-line: no-any
|
||||
const i18n: Record<string, any> = appProject.i18n;
|
||||
|
||||
i18n.sourceLocale = 'en-x-abc';
|
||||
appProject.architect['build'].options.localize = ['en-x-abc'];
|
||||
});
|
||||
|
||||
const { stderr: err3 } = await ng('build');
|
||||
if (err3.includes(`Locale data for 'en-x-abc' cannot be found. No locale data will be included for this locale.`)) {
|
||||
throw new Error('locale data not found warning shown');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user