Skip to content

Commit

Permalink
fix(@angular/cli): allow for private use language subtags
Browse files Browse the repository at this point in the history
Fixes:  #17163
  • Loading branch information
clydin authored and mgechev committed Mar 17, 2020
1 parent f45236c commit 017b727
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
8 changes: 4 additions & 4 deletions packages/angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,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",
Expand All @@ -396,7 +396,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",
Expand All @@ -411,7 +411,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",
Expand Down Expand Up @@ -2066,7 +2066,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})+)?$"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})+)?$"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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})+)?$"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-locale-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

0 comments on commit 017b727

Please sign in to comment.