Skip to content

New i18n schema #15760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions etc/api/angular_devkit/core/src/_golden-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,7 @@ export declare class WorkspaceNotYetLoadedException extends BaseException {
export interface WorkspaceProject {
architect?: WorkspaceTool;
cli?: WorkspaceTool;
i18n?: WorkspaceProjectI18n;
prefix: string;
projectType: "application" | "library";
root: string;
Expand All @@ -1259,6 +1260,11 @@ export interface WorkspaceProject {
targets?: WorkspaceTool;
}

export interface WorkspaceProjectI18n {
locales: Record<string, string>;
sourceLocale?: string;
}

export interface WorkspaceSchema {
$schema?: string;
architect?: WorkspaceTool;
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/cli/commands/xi18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Extracts i18n messages from source code.",
"$longDescription": "",

"$aliases": [],
"$aliases": ["i18n-extract"],
"$scope": "in",
"$type": "architect",
"$impl": "./xi18n-impl#Xi18nCommand",
Expand Down
101 changes: 88 additions & 13 deletions packages/angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@
"type": "string",
"description": "Root of the project files."
},
"i18n": {
"$ref": "#/definitions/project/definitions/i18n"
},
"sourceRoot": {
"type": "string",
"description": "The root of the source files, assets and index.html file structure."
Expand Down Expand Up @@ -398,6 +401,28 @@
"^[a-z]{1,3}-.*": {}
},
"definitions": {
"i18n": {
"description": "Project i18n options",
"type": "object",
"properties": {
"sourceLocale": {
"type": "string",
"description": "Specifies the source language of the application.",
"default": "en-US"
},
"locales": {
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^[a-z]{2}(-[a-zA-Z]{2,})?$": {
"type": "string",
"description": "Localization file to use for i18n"
}
}
}
},
"additionalProperties": false
},
"target": {
"oneOf": [
{
Expand Down Expand Up @@ -756,21 +781,26 @@
"description": "Log progress to the console while building.",
"default": true
},
"localize": {
"$ref": "#/definitions/buildersOptions/localize"
},
"i18nMissingTranslation": {
"$ref": "#/definitions/buildersOptions/missingTranslation"
},
"i18nFile": {
"type": "string",
"description": "Localization file to use for i18n."
"description": "Localization file to use for i18n.",
"x-deprecated": "Deprecated since 9.0"
},
"i18nFormat": {
"type": "string",
"description": "Format of the localization file specified with --i18n-file."
"description": "Format of the localization file specified with --i18n-file.",
"x-deprecated": "Deprecated since 9.0"
},
"i18nLocale": {
"type": "string",
"description": "Locale to use for i18n."
},
"i18nMissingTranslation": {
"type": "string",
"description": "How to handle missing translations for i18n."
"description": "Locale to use for i18n.",
"x-deprecated": "Deprecated since 9.0"
},
"extractCss": {
"type": "boolean",
Expand Down Expand Up @@ -1281,10 +1311,24 @@
"type": "string",
"description": "Target to extract from."
},
"format": {
"type": "string",
"description": "Output format for the generated file.",
"default": "xlf",
"enum": [
"xmb",
"xlf",
"xlif",
"xliff",
"xlf2",
"xliff2"
]
},
"i18nFormat": {
"type": "string",
"description": "Output format for the generated file.",
"default": "xlf",
"x-deprecated": "Use 'format' option instead.",
"enum": [
"xmb",
"xlf",
Expand All @@ -1296,7 +1340,8 @@
},
"i18nLocale": {
"type": "string",
"description": "Specifies the source language of the application."
"description": "Specifies the source language of the application.",
"x-deprecated": "Use 'i18n' project level sub-option 'sourceLocale' instead."
},
"progress": {
"type": "boolean",
Expand Down Expand Up @@ -1761,21 +1806,26 @@
"description": "Log progress to the console while building.",
"default": true
},
"localize": {
"$ref": "#/definitions/buildersOptions/localize"
},
"i18nFile": {
"type": "string",
"description": "Localization file to use for i18n."
"description": "Localization file to use for i18n.",
"x-deprecated": "Deprecated since 9.0"
},
"i18nFormat": {
"type": "string",
"description": "Format of the localization file specified with --i18n-file."
"description": "Format of the localization file specified with --i18n-file.",
"x-deprecated": "Deprecated since 9.0"
},
"i18nLocale": {
"type": "string",
"description": "Locale to use for i18n."
"description": "Locale to use for i18n.",
"x-deprecated": "Deprecated since 9.0"
},
"i18nMissingTranslation": {
"type": "string",
"description": "How to handle missing translations for i18n."
"$ref": "#/definitions/buildersOptions/missingTranslation"
},
"outputHashing": {
"type": "string",
Expand Down Expand Up @@ -1965,6 +2015,31 @@
"additionalProperties": false
}
}
},
"buildersOptions": {
"missingTranslation": {
"type": "string",
"description": "How to handle missing translations for i18n.",
"enum": ["warning", "error", "ignore"],
"default": "warning"
},
"localize": {
"oneOf": [
{
"type": "boolean",
"description": "Translate all locales."
},
{
"type": "array",
"description": "List of locales ID's to translate.",
"minItems": 1,
"items": {
"type": "string",
"pattern": "^[a-z]{2}(-[a-zA-Z]{2,})?$"
}
}
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
AssetPatternClass,
Budget,
ExtraEntryPoint,
I18NMissingTranslation,
Localize,
OptimizationClass,
SourceMapClass,
} from '../../browser/schema';
Expand All @@ -27,26 +29,29 @@ export interface BuildOptions {
resourcesOutputPath?: string;
aot?: boolean;
sourceMap: SourceMapClass;
/** @deprecated use sourceMap instead */
/** @deprecated since version 8. use sourceMap instead. */
vendorSourceMap?: boolean;
/** @deprecated */
/** @deprecated since version 8 */
evalSourceMap?: boolean;
vendorChunk?: boolean;
commonChunk?: boolean;
baseHref?: string;
deployUrl?: string;
verbose?: boolean;
progress?: boolean;
/** @deprecated since version 9. Use 'locales' object in the project metadata instead.*/
i18nFile?: string;
/** @deprecated since version 9. No longer needed as the format will be determined automatically.*/
i18nFormat?: string;
/** @deprecated since version 9. Use 'localize' instead.*/
i18nLocale?: string;
i18nMissingTranslation?: string;
localize?: Localize;
i18nMissingTranslation?: I18NMissingTranslation;
extractCss?: boolean;
bundleDependencies?: 'none' | 'all';
watch?: boolean;
outputHashing?: string;
poll?: number;
app?: string;
deleteOutputPath?: boolean;
preserveSymlinks?: boolean;
extractLicenses?: boolean;
Expand All @@ -56,10 +61,12 @@ export interface BuildOptions {
subresourceIntegrity?: boolean;
serviceWorker?: boolean;
webWorkerTsConfig?: string;
/** @deprecated since version 8 **/
skipAppShell?: boolean;
statsJson: boolean;
forkTypeChecker: boolean;
profile?: boolean;
/** @deprecated since version 8 **/
es5BrowserSupport?: boolean;

main: string;
Expand Down
30 changes: 26 additions & 4 deletions packages/angular_devkit/build_angular/src/browser/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,41 @@
},
"i18nFile": {
"type": "string",
"description": "Localization file to use for i18n."
"description": "Localization file to use for i18n.",
"x-deprecated": "Use 'locales' object in the project metadata instead."
},
"i18nFormat": {
"type": "string",
"description": "Format of the localization file specified with --i18n-file."
"description": "Format of the localization file specified with --i18n-file.",
"x-deprecated": "No longer needed as the format will be determined automatically."
},
"i18nLocale": {
"type": "string",
"description": "Locale to use for i18n."
"description": "Locale to use for i18n.",
"x-deprecated": "Use 'localize' instead."
},
"i18nMissingTranslation": {
"type": "string",
"description": "How to handle missing translations for i18n."
"description": "How to handle missing translations for i18n.",
"enum": ["warning", "error", "ignore"],
"default": "warning"
},
"localize": {
"oneOf": [
{
"type": "boolean",
"description": "Translate all locales."
},
{
"type": "array",
"description": "List of locales ID's to translate.",
"minItems": 1,
"items": {
"type": "string",
"pattern": "^[a-z]{2}(-[a-zA-Z]{2,})?$"
}
}
]
},
"extractCss": {
"type": "boolean",
Expand Down
22 changes: 18 additions & 4 deletions packages/angular_devkit/build_angular/src/extract-i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import {
} from '../angular-cli-files/models/webpack-configs';
import { statsErrorsToString, statsWarningsToString } from '../angular-cli-files/utilities/stats';
import { Schema as BrowserBuilderOptions } from '../browser/schema';
import { createI18nOptions } from '../utils/i18n-options';
import { assertCompatibleAngularVersion } from '../utils/version';
import { generateBrowserWebpackConfigFromContext } from '../utils/webpack-browser-config';
import { Schema as ExtractI18nBuilderOptions } from './schema';
import { Format, Schema as ExtractI18nBuilderOptions } from './schema';

function getI18nOutfile(format: string | undefined) {
switch (format) {
Expand Down Expand Up @@ -58,13 +59,26 @@ async function execute(options: ExtractI18nBuilderOptions, context: BuilderConte
await context.getBuilderNameForTarget(browserTarget),
);

if (options.i18nFormat !== Format.Xlf) {
options.format = options.i18nFormat;
}

// We need to determine the outFile name so that AngularCompiler can retrieve it.
let outFile = options.outFile || getI18nOutfile(options.i18nFormat);
let outFile = options.outFile || getI18nOutfile(options.format);
if (options.outputPath) {
// AngularCompilerPlugin doesn't support genDir so we have to adjust outFile instead.
outFile = path.join(options.outputPath, outFile);
}

const projectName = context.target && context.target.project;
if (!projectName) {
throw new Error('The builder requires a target.');
}
// target is verified in the above call
// tslint:disable-next-line: no-non-null-assertion
const metadata = await context.getProjectMetadata(context.target!);
const i18n = createI18nOptions(metadata);

const { config } = await generateBrowserWebpackConfigFromContext(
{
...browserOptions,
Expand All @@ -73,8 +87,8 @@ async function execute(options: ExtractI18nBuilderOptions, context: BuilderConte
styles: false,
},
buildOptimizer: false,
i18nLocale: options.i18nLocale,
i18nFormat: options.i18nFormat,
i18nLocale: options.i18nLocale || i18n.sourceLocale,
i18nFormat: options.format,
i18nFile: outFile,
aot: true,
progress: options.progress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@
"type": "string",
"description": "Target to extract from."
},
"format": {
"type": "string",
"description": "Output format for the generated file.",
"default": "xlf",
"enum": [
"xmb",
"xlf",
"xlif",
"xliff",
"xlf2",
"xliff2"
]
},
"i18nFormat": {
"type": "string",
"description": "Output format for the generated file.",
"default": "xlf",
"x-deprecated": "Use 'format' option instead.",
"enum": [
"xmb",
"xlf",
Expand All @@ -23,7 +37,8 @@
},
"i18nLocale": {
"type": "string",
"description": "Specifies the source language of the application."
"description": "Specifies the source language of the application.",
"x-deprecated": "Use 'i18n' project level sub-option 'sourceLocale' instead."
},
"progress": {
"type": "boolean",
Expand Down
Loading