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

fix(ivy): i18n - support setting locales for each translation file #33381

Conversation

petebacondarwin
Copy link
Member

Previously the target locale of a translation file had to be extracted
from the contents of the translation file.

Now an array of locales can be provided via the translationFileLocales
option that overrides any target locale extracted from the file.
This allows us to support translation files that do not have a target
locale specified in their contents.

// FW-1644
Fixes #33323

@petebacondarwin petebacondarwin added action: review The PR is still awaiting reviews from at least one requested reviewer area: i18n target: major This PR is targeted for the next major release comp: ivy labels Oct 24, 2019
@petebacondarwin petebacondarwin requested a review from a team as a code owner October 24, 2019 18:58
@ngbot ngbot bot modified the milestone: needsTriage Oct 24, 2019
@petebacondarwin petebacondarwin 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 fixed by Ivy labels Oct 24, 2019
Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

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

the rest lgtm

@petebacondarwin
Copy link
Member Author

After @clydin's feedback I completely redesigned this PR - so all the files have changed since the last reviews (cc @IgorMinar).

@clydin please note that the return type from TranslationParser.parse() has changed. I think you are using this directly in the CLI integration?? So this will be a breaking change for this integration.

PTAL!!

Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

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

A few more suggestions.

if (parsedLocale !== undefined && providedLocale !== undefined &&
parsedLocale !== providedLocale) {
this.diagnostics.warn(
`The provided locale "${providedLocale}" and the target locale "${parsedLocale}" do not match for translation file "${filePath}".`);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that this is easy to understand. How about "specified locale XX doesn't match locale YY found in the translation file"

const loader = new TranslationLoader([parser], diagnostics);
expect(() => loader.loadBundles(['/src/locale/messages.en.xlf'], []))
.toThrowError(
'No target locale provided nor found in the translation file "/src/locale/messages.en.xlf"');
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add "please provide --target-locale argument"?

Copy link
Member Author

Choose a reason for hiding this comment

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

The only problem with this is that it might be called via the Angular CLI which does not have this option...

Copy link
Member Author

Choose a reason for hiding this comment

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

How about: "consider explicitly providing a target-locale for this file"?

*/
export interface ParsedTranslationBundle {
parsedLocale: string|undefined;
parsedTranslations: Record<ɵMessageId, ɵParsedTranslation>;
Copy link
Member

Choose a reason for hiding this comment

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

If these names are kept unchanged, no code changes would be needed on the CLI side.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is where it is used in the CLI (for context): https://github.com/angular/angular-cli/blob/395c97912800af435021432e708cbdfab28783fe/packages/angular_devkit/build_angular/src/utils/load-translations.ts

Only the translations property appears to be important...

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll switch them back...

@petebacondarwin petebacondarwin force-pushed the i18n-missing-target-language branch 4 times, most recently from d742d1c to 529d94c Compare October 25, 2019 21:10
@petebacondarwin petebacondarwin added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 25, 2019
@petebacondarwin
Copy link
Member Author

As I am a code-owner of this, and having approval from @IgorMinar, I think that this can be merged, right?

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

LGTM, just left a couple comments. Thanks Pete.


diagnostics.messages.forEach(m => console.warn(`${m.type}: ${m.message}`));
process.exit(diagnostics.hasErrors ? 1 : 0);
}

export interface TranslateFilesOptions {
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding docs 👍

Previously the target locale of a translation file had to be extracted
from the contents of the translation file. Therefore it was an error if
the translation file did not provide a target locale.

Now an array of locales can be provided via the `translationFileLocales`
option that overrides any target locale extracted from the file.
This allows us to support translation files that do not have a target
locale specified in their contents.

// FW-1644
Fixes angular#33323
The `localize-translate` command line tool can now accept an array of
target locales to support the case where translation files do not
contain them. Specify this array via the `--target-locales` option.

NOTE to early adopters: in order to support this, the original `-t`
option for the binary has changed from being a glob pattern to an array
of paths, which will have matching indices to any provided target-locales.
AndrewKushnir pushed a commit that referenced this pull request Oct 28, 2019
…#33381)

The `localize-translate` command line tool can now accept an array of
target locales to support the case where translation files do not
contain them. Specify this array via the `--target-locales` option.

NOTE to early adopters: in order to support this, the original `-t`
option for the binary has changed from being a glob pattern to an array
of paths, which will have matching indices to any provided target-locales.

PR Close #33381
mohaxspb pushed a commit to mohaxspb/angular that referenced this pull request Nov 7, 2019
…ngular#33381)

Previously the target locale of a translation file had to be extracted
from the contents of the translation file. Therefore it was an error if
the translation file did not provide a target locale.

Now an array of locales can be provided via the `translationFileLocales`
option that overrides any target locale extracted from the file.
This allows us to support translation files that do not have a target
locale specified in their contents.

// FW-1644
Fixes angular#33323

PR Close angular#33381
mohaxspb pushed a commit to mohaxspb/angular that referenced this pull request Nov 7, 2019
…angular#33381)

The `localize-translate` command line tool can now accept an array of
target locales to support the case where translation files do not
contain them. Specify this array via the `--target-locales` option.

NOTE to early adopters: in order to support this, the original `-t`
option for the binary has changed from being a glob pattern to an array
of paths, which will have matching indices to any provided target-locales.

PR Close angular#33381
mohaxspb pushed a commit to mohaxspb/angular that referenced this pull request Nov 7, 2019
…ngular#33381)

Previously the target locale of a translation file had to be extracted
from the contents of the translation file. Therefore it was an error if
the translation file did not provide a target locale.

Now an array of locales can be provided via the `translationFileLocales`
option that overrides any target locale extracted from the file.
This allows us to support translation files that do not have a target
locale specified in their contents.

// FW-1644
Fixes angular#33323

PR Close angular#33381
mohaxspb pushed a commit to mohaxspb/angular that referenced this pull request Nov 7, 2019
…angular#33381)

The `localize-translate` command line tool can now accept an array of
target locales to support the case where translation files do not
contain them. Specify this array via the `--target-locales` option.

NOTE to early adopters: in order to support this, the original `-t`
option for the binary has changed from being a glob pattern to an array
of paths, which will have matching indices to any provided target-locales.

PR Close angular#33381
@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 Nov 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: i18n cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

target-language was not needed in VE but seems to be required on Ivy i18n
5 participants