fix(@angular/cli): allow for private use language subtags

Fixes:  #17163
This commit is contained in:
Charles Lyding 2020-03-11 14:15:33 -04:00 committed by Minko Gechev
parent 237bade5d5
commit f0bada1925
6 changed files with 28 additions and 11 deletions

View File

@ -393,7 +393,7 @@
"description": "Specifies the source locale of the application.", "description": "Specifies the source locale of the application.",
"default": "en-US", "default": "en-US",
"$comment": "IETF BCP 47 language tag (simplified)", "$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", "type": "object",
@ -402,7 +402,7 @@
"code": { "code": {
"type": "string", "type": "string",
"description": "Specifies the locale code of the source locale", "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": { "baseHref": {
"type": "string", "type": "string",
@ -417,7 +417,7 @@
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"patternProperties": { "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": [ "oneOf": [
{ {
"type": "string", "type": "string",
@ -2081,7 +2081,7 @@
"minItems": 1, "minItems": 1,
"items": { "items": {
"type": "string", "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})+)?$"
} }
} }
] ]

View File

@ -211,7 +211,7 @@
"minItems": 1, "minItems": 1,
"items": { "items": {
"type": "string", "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})+)?$"
} }
} }
] ]

View File

@ -175,7 +175,7 @@
"minItems": 1, "minItems": 1,
"items": { "items": {
"type": "string", "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})+)?$"
} }
} }
] ]

View File

@ -338,10 +338,13 @@ function findLocaleDataBasePath(projectRoot: string): string | null {
} }
function findLocaleDataPath(locale: string, basePath: 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 (!fs.existsSync(localeDataPath)) {
if (locale === 'en-US') { if (scrubbedLocale === 'en-US') {
// fallback to known existing en-US locale data as of 9.0 // fallback to known existing en-US locale data as of 9.0
return findLocaleDataPath('en-US-POSIX', basePath); return findLocaleDataPath('en-US-POSIX', basePath);
} }

View File

@ -136,7 +136,7 @@
"type": "string", "type": "string",
"description": "Specifies the source locale of the application.", "description": "Specifies the source locale of the application.",
"default": "en-US", "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", "type": "object",
@ -145,7 +145,7 @@
"code": { "code": {
"type": "string", "type": "string",
"description": "Specifies the locale code of the source locale", "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": { "baseHref": {
"type": "string", "type": "string",
@ -160,7 +160,7 @@
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"patternProperties": { "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": [ "oneOf": [
{ {
"type": "string", "type": "string",

View File

@ -43,4 +43,18 @@ export default async function() {
throw new Error('locale data not found warning shown'); 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');
}
} }