Skip to content

Commit 017b727

Browse files
clydinmgechev
authored andcommitted
fix(@angular/cli): allow for private use language subtags
Fixes: #17163
1 parent f45236c commit 017b727

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

packages/angular/cli/lib/config/schema.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@
387387
"description": "Specifies the source locale of the application.",
388388
"default": "en-US",
389389
"$comment": "IETF BCP 47 language tag (simplified)",
390-
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
390+
"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})+)?$"
391391
},
392392
{
393393
"type": "object",
@@ -396,7 +396,7 @@
396396
"code": {
397397
"type": "string",
398398
"description": "Specifies the locale code of the source locale",
399-
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
399+
"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})+)?$"
400400
},
401401
"baseHref": {
402402
"type": "string",
@@ -411,7 +411,7 @@
411411
"type": "object",
412412
"additionalProperties": false,
413413
"patternProperties": {
414-
"^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$": {
414+
"^[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})+)?$": {
415415
"oneOf": [
416416
{
417417
"type": "string",
@@ -2066,7 +2066,7 @@
20662066
"minItems": 1,
20672067
"items": {
20682068
"type": "string",
2069-
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
2069+
"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})+)?$"
20702070
}
20712071
}
20722072
]

packages/angular_devkit/build_angular/src/browser/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
"minItems": 1,
212212
"items": {
213213
"type": "string",
214-
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
214+
"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})+)?$"
215215
}
216216
}
217217
]

packages/angular_devkit/build_angular/src/server/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
"minItems": 1,
176176
"items": {
177177
"type": "string",
178-
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
178+
"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})+)?$"
179179
}
180180
}
181181
]

packages/angular_devkit/build_angular/src/utils/i18n-options.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,13 @@ function findLocaleDataBasePath(projectRoot: string): string | null {
338338
}
339339

340340
function findLocaleDataPath(locale: string, basePath: string): string | null {
341-
const localeDataPath = path.join(basePath, locale + '.js');
341+
// Remove private use subtags
342+
const scrubbedLocale = locale.replace(/-x(-[a-zA-Z0-9]{1,8})+$/, '');
343+
344+
const localeDataPath = path.join(basePath, scrubbedLocale + '.js');
342345

343346
if (!fs.existsSync(localeDataPath)) {
344-
if (locale === 'en-US') {
347+
if (scrubbedLocale === 'en-US') {
345348
// fallback to known existing en-US locale data as of 9.0
346349
return findLocaleDataPath('en-US-POSIX', basePath);
347350
}

packages/angular_devkit/core/src/experimental/workspace/workspace-schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"type": "string",
137137
"description": "Specifies the source locale of the application.",
138138
"default": "en-US",
139-
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
139+
"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})+)?$"
140140
},
141141
{
142142
"type": "object",
@@ -145,7 +145,7 @@
145145
"code": {
146146
"type": "string",
147147
"description": "Specifies the locale code of the source locale",
148-
"pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$"
148+
"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})+)?$"
149149
},
150150
"baseHref": {
151151
"type": "string",
@@ -160,7 +160,7 @@
160160
"type": "object",
161161
"additionalProperties": false,
162162
"patternProperties": {
163-
"^[a-zA-Z]{2,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-[a-zA-Z]{5,8})?$": {
163+
"^[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})+)?$": {
164164
"oneOf": [
165165
{
166166
"type": "string",

tests/legacy-cli/e2e/tests/i18n/ivy-localize-locale-data.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,18 @@ export default async function() {
4343
throw new Error('locale data not found warning shown');
4444
}
4545

46+
// Update angular.json
47+
await updateJsonFile('angular.json', workspaceJson => {
48+
const appProject = workspaceJson.projects['test-project'];
49+
// tslint:disable-next-line: no-any
50+
const i18n: Record<string, any> = appProject.i18n;
51+
52+
i18n.sourceLocale = 'en-x-abc';
53+
appProject.architect['build'].options.localize = ['en-x-abc'];
54+
});
55+
56+
const { stderr: err3 } = await ng('build');
57+
if (err3.includes(`Locale data for 'en-x-abc' cannot be found. No locale data will be included for this locale.`)) {
58+
throw new Error('locale data not found warning shown');
59+
}
4660
}

0 commit comments

Comments
 (0)