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
feat(compiler-cli): add i18n parameters to tsconfig #16365
Conversation
targetI18nFormat?: string; | ||
|
||
// locale for imported translation files | ||
// you should only use this if you have one tsconfig file per locale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can remove this line "you should ..."
same below
packages/compiler-cli/src/codegen.ts
Outdated
@@ -73,8 +73,8 @@ export class CodeGenerator { | |||
} | |||
const {compiler: aotCompiler} = compiler.createAotCompiler(ngCompilerHost, { | |||
translations: transContent, | |||
i18nFormat: cliOptions.i18nFormat, | |||
locale: cliOptions.locale, | |||
i18nFormat: cliOptions.i18nFormat || options.targetI18nFormat, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|| sourceFormat
at the end (useful when they are the same)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For xmb/xtb source & target format are different, this could lead to bugs. The only case where this would work would be for xlf and it's already the default format.
@@ -23,7 +23,9 @@ function extract( | |||
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions, | |||
program: ts.Program, host: ts.CompilerHost): Promise<void> { | |||
return Extractor.create(ngOptions, program, host, cliOptions.locale) | |||
.extract(cliOptions.i18nFormat !, cliOptions.outFile); | |||
.extract( | |||
(cliOptions.i18nFormat || ngOptions.sourceI18nFormat) !, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take the opportunity of this PR to clean the (...)!
hack.
@@ -81,6 +81,26 @@ interface Options extends ts.CompilerOptions { | |||
|
|||
// Whether to enable support for <template> and the template attribute (true by default) | |||
enableLegacyTemplate?: boolean; | |||
|
|||
// format for extracted messages file (xlf, xmb) | |||
sourceI18nFormat?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a general comment on this PR, "source" is confusing because it relates to the file being written which is counter-intuitive - same for "target".
Can you think about better names ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See inline comments + need tests
7c6100a
to
9d7d54e
Compare
packages/compiler-cli/src/codegen.ts
Outdated
const optMissingTranslation = cliOptions.missingTranslation || options.missingTranslation; | ||
const transFile = cliOptions.i18nFile || options.i18nFile; | ||
let translations: string = ''; | ||
if (transFile) { | ||
if (!cliOptions.locale) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be locale
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to be sure if you really paid attention to the code.
Jokes aside, good catch, fixed
9d7d54e
to
6befe68
Compare
packages/compiler-cli/src/codegen.ts
Outdated
i18nFormat: cliOptions.i18nFormat, | ||
locale: cliOptions.locale, missingTranslation, | ||
translations, | ||
i18nFormat: cliOptions.i18nFormat || options.i18nTranslationFormat, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to the top with other parameters ?
explain why we do || options.i18nTranslationFormat
(ie most files contain both messages and translations)
@@ -23,7 +23,9 @@ function extract( | |||
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions, | |||
program: ts.Program, host: ts.CompilerHost): Promise<void> { | |||
return Extractor.create(ngOptions, program, host, cliOptions.locale) | |||
.extract(cliOptions.i18nFormat !, cliOptions.outFile); | |||
.extract( | |||
cliOptions.i18nFormat || ngOptions.i18nFormat || null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing here, move init to the top, missing i18nTranslationFormat
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format could not be null -> || ''
at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forget my first comment, you have updated the API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use "i18nTranslationFormat" for the extraction (this is ng-xi18n, not ngc)
.extract(cliOptions.i18nFormat !, cliOptions.outFile); | ||
.extract( | ||
cliOptions.i18nFormat || ngOptions.i18nFormat || null, | ||
cliOptions.outFile || ngOptions.outFile || null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move init at the top
// path & name of your translations file | ||
i18nFile?: string; | ||
|
||
// strategy to use for missing translations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specify the possible values in the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- see inline comments,
- add tests
6befe68
to
8a24b8c
Compare
@@ -22,8 +22,9 @@ import {Extractor} from './extractor'; | |||
function extract( | |||
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.I18nExtractionCliOptions, | |||
program: ts.Program, host: ts.CompilerHost): Promise<void> { | |||
return Extractor.create(ngOptions, program, host, cliOptions.locale) | |||
.extract(cliOptions.i18nFormat !, cliOptions.outFile); | |||
const format = cliOptions.i18nFormat || ngOptions.i18nFormat || null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set the default to xliff
@@ -27,7 +27,7 @@ export class Extractor { | |||
public host: ts.CompilerHost, private ngCompilerHost: CompilerHost, | |||
private program: ts.Program) {} | |||
|
|||
extract(formatName: string, outFile: string|null): Promise<void> { | |||
extract(formatName: string|null, outFile: string|null): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert |null
also for the other methods if possible
packages/compiler-cli/src/main.ts
Outdated
args: any, consoleError: (s: string) => void = console.error): Promise<number> { | ||
args: any, consoleError: (s: string) => void = console.error, | ||
codegen: | ||
(n: tsc.AngularCompilerOptions, c: tsc.NgcCliOptions, p: ts.Program, h: ts.CompilerHost) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the only way that I found to add the unit test. I can remove it, but I'll have to remove the test as well
@@ -150,6 +150,6 @@ export class NgTools_InternalApi_NG_2 { | |||
const extractor = Extractor.create( | |||
options.angularCompilerOptions, options.program, options.host, locale, hostContext); | |||
|
|||
return extractor.extract(options.i18nFormat !, options.outFile || null); | |||
return extractor.extract(options.i18nFormat || null, options.outFile || null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, add xliff
by default
8a24b8c
to
cbf49f1
Compare
LGTM, needed before merge:
|
You can now add parameters to your tsconfig that will be used when you don't provide cli parameters. It works with ng-xi18n and ngc. Since they both use some parameters with a similar name, those options in tsconfig can have a slightly different name compared to the cli parameters. Closes angular#16232 Fixes angular#16235
cbf49f1
to
71a7a3b
Compare
Blocked because missing approval. @alexeagle could you please review. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @vikerman
locale?: string; | ||
|
||
// path & name for the extracted messages file | ||
outFile?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably confusing.
"compilerOptions": {
"outDir": "foo",
"out": "bar"
},
"angularCompilerOptions": {
"outFile": "baz"
}
I think either these options need to have i18n in the name, or be nested:
"angularCompilerOptions": {
"i18n_msgs": {
"extract": {
"outFile": "msgs.xtb"
},
"merge": {
"i18nFile": "msgs.xtb"
}
}
}
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used the names of the current cli options (when possible). We can nest them though, what do you think @vicb ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not possible to nest the options:
type CompilerOptionsValue = string | number | boolean | (string | number)[] | string[] | MapLike<string[]> | PluginImport[];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't MapLike<string[]>
the way to nest options? TypeScript does nest them, eg. compilerOptions.paths
i18nFormat?: string; | ||
|
||
// locale of your application for extracted messages file | ||
locale?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was expecting multiple locales to appear here. Users shouldn't have N tsconfig files (and note that the tsconfig "extends" behavior doesn't cover unknown config properties like "angularCompilerOptions")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the locale used for extracted messages, which is the main locale of your application. There is only one here since you only do one extraction.
You are referring to translationLocale?: string;
which is the locale used when you compile the application. I had a comment there that @vicb told me remove which was something like "only use this if you have one tsconfig file / locale".
I agree that it would be better if we could compile all locales in one command, but that is not possible yet. There's a bit refactor coming for the compiler and it will probably change at that point, but for now we can only compile for one locale.
ae67092
to
71a7a3b
Compare
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
Does this have google3 impact? |
closing as implemented in the new 5.x compiler flow - see #18494 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
What kind of change does this PR introduce?
What is the current behavior? (You can also link to an open issue here)
Right now you cannot add existing i18n parameters to tsconfig, see issue #16232
What is the new behavior?
You can now add parameters to your tsconfig that will be used when you don't provide cli parameters. It works with ng-xi18n and ngc. Since they both have some parameters with a similar name, those options in tsconfig have a slightly different name compared to the cli parameters (with the prefix source for ng-xi18n and the prefix target for ngc).
Does this PR introduce a breaking change? (check one with "x")