Skip to content
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

Closed

Conversation

ocombe
Copy link
Contributor

@ocombe ocombe commented Apr 27, 2017

What kind of change does this PR introduce?

[x] Feature

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")

[x] No

@ocombe ocombe added area: i18n action: review The PR is still awaiting reviews from at least one requested reviewer feature Issue that requests a new feature labels Apr 27, 2017
@ocombe ocombe requested a review from vicb April 27, 2017 07:50
targetI18nFormat?: string;

// locale for imported translation files
// you should only use this if you have one tsconfig file per locale
Copy link
Contributor

@vicb vicb Apr 27, 2017

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

@@ -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,
Copy link
Contributor

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)

Copy link
Contributor Author

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) !,
Copy link
Contributor

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;
Copy link
Contributor

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 ?

Copy link
Contributor

@vicb vicb left a 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

@vicb vicb added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 27, 2017
@ocombe ocombe force-pushed the feature-i18n-params-tsconfig-16232 branch from 7c6100a to 9d7d54e Compare April 28, 2017 12:03
const optMissingTranslation = cliOptions.missingTranslation || options.missingTranslation;
const transFile = cliOptions.i18nFile || options.i18nFile;
let translations: string = '';
if (transFile) {
if (!cliOptions.locale) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be locale ?

Copy link
Contributor Author

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

@ocombe ocombe force-pushed the feature-i18n-params-tsconfig-16232 branch from 9d7d54e to 6befe68 Compare April 28, 2017 12:14
i18nFormat: cliOptions.i18nFormat,
locale: cliOptions.locale, missingTranslation,
translations,
i18nFormat: cliOptions.i18nFormat || options.i18nTranslationFormat,
Copy link
Contributor

@vicb vicb Apr 28, 2017

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,
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

@vicb vicb left a 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

@ocombe ocombe force-pushed the feature-i18n-params-tsconfig-16232 branch from 6befe68 to 8a24b8c Compare April 28, 2017 16:52
@@ -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;
Copy link
Contributor

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> {
Copy link
Contributor

@vicb vicb May 1, 2017

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

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) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change ?

Copy link
Contributor Author

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);
Copy link
Contributor

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

@ocombe ocombe force-pushed the feature-i18n-params-tsconfig-16232 branch from 8a24b8c to cbf49f1 Compare May 2, 2017 11:46
@ocombe ocombe mentioned this pull request May 2, 2017
20 tasks
@vicb vicb removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label May 10, 2017
@vicb
Copy link
Contributor

vicb commented May 10, 2017

LGTM, needed before merge:

  • @ocombe to update the tests according to discussions,
  • travis should be green (the failure does not seem to relate to the changes).

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
@ocombe ocombe force-pushed the feature-i18n-params-tsconfig-16232 branch from cbf49f1 to 71a7a3b Compare May 12, 2017 13:47
@ocombe ocombe added the action: merge The PR is ready for merge by the caretaker label May 12, 2017
@vicb
Copy link
Contributor

vicb commented May 15, 2017

Blocked because missing approval.

@alexeagle could you please review. Thanks.

Copy link
Contributor

@alexeagle alexeagle left a 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;
Copy link
Contributor

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?

Copy link
Contributor Author

@ocombe ocombe May 16, 2017

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 ?

Copy link
Contributor

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[];

Copy link
Contributor

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;
Copy link
Contributor

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")

Copy link
Contributor Author

@ocombe ocombe May 16, 2017

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.

@chuckjaz chuckjaz removed the action: merge The PR is ready for merge by the caretaker label May 19, 2017
@mhevery mhevery force-pushed the feature-i18n-params-tsconfig-16232 branch from ae67092 to 71a7a3b Compare July 26, 2017 19:56
@googlebot
Copy link

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 cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@vikerman
Copy link
Contributor

Does this have google3 impact?

@vicb
Copy link
Contributor

vicb commented Aug 11, 2017

closing as implemented in the new 5.x compiler flow - see #18494

@vicb vicb closed this Aug 11, 2017
@ocombe ocombe deleted the feature-i18n-params-tsconfig-16232 branch November 10, 2017 08:48
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: i18n cla: no feature Issue that requests a new feature state: blocked
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants