Skip to content

feat(localize): support merging multiple translation files - #36792

Closed
petebacondarwin wants to merge 3 commits into
angular:masterfrom
petebacondarwin:i18n-merging-translation-files
Closed

petebacondarwin wants to merge 3 commits into
angular:masterfrom
petebacondarwin:i18n-merging-translation-files

Conversation

@petebacondarwin

@petebacondarwin petebacondarwin commented Apr 24, 2020 •

Copy link
Copy Markdown
Contributor

Previously only one translation file per locale could be loaded.
Now the user can specify multiple files per locale, and the translations
from each of these files will be merged together by message id.


Note that the CLI uses the lower level TranslationParser classes directly, so will not inherit this new behaviour automatically - cc @clydin.

@petebacondarwin petebacondarwin added feature Label used to distinguish feature request from other issues action: review The PR is still awaiting reviews from at least one requested reviewer area: i18n Issues related to localization and internationalization target: major This PR is targeted for the next major release labels Apr 24, 2020
@ngbot ngbot Bot modified the milestone: needsTriage Apr 24, 2020
@pullapprove
pullapprove Bot requested a review from mhevery April 24, 2020 14:06

@AndrewKushnir AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks @petebacondarwin 👍 Just left one question/proposal to consider.

@petebacondarwin
petebacondarwin force-pushed the i18n-merging-translation-files branch from 7b06907 to 38e2e0d Compare April 28, 2020 18:36

@AndrewKushnir AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the updates Pete! I've left a few comments, could you please have a look when you get a chance?

@AndrewKushnir
AndrewKushnir self-requested a review April 29, 2020 00:57
@petebacondarwin
petebacondarwin force-pushed the i18n-merging-translation-files branch from 38e2e0d to ebdaf62 Compare April 29, 2020 08:46
Previously the `missingTranslation` option had to be checked before calling
`warn` or `error` on the `diagnostics` object.

Now this boilerplate is hidden inside the `Diagnostics.add()` method, which
will open it up to being used for other conditional diagnostics.
This commit introduces `Diagnostics.merge(other)` which will take the messages from
`other` and append them to the messages of `this`.

The translation loader is updated to use this new method.
@petebacondarwin
petebacondarwin force-pushed the i18n-merging-translation-files branch from ebdaf62 to faca2a4 Compare April 30, 2020 19:44
Previously only one translation file per locale could be loaded.

Now the user can specify multiple files per locale, and the translations
from each of these files will be merged together by message id.
The merging is on a first-wins approach. So if to you have three files
to be merged:

```
['a.xlf', 'b.xmb', 'c.json']
```

Then any message from `a.xlf` will be used rather than a message from `b.xmb`
or `c.json` and so on. In practice this means that you should put the files
in order of most important first, with "fallback" translations later.
@petebacondarwin
petebacondarwin force-pushed the i18n-merging-translation-files branch from faca2a4 to c2d094a Compare April 30, 2020 19:49

@mhevery mhevery left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Integration tests LGTM

@AndrewKushnir AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks Pete (also special thanks for the docs!) 👍

@AndrewKushnir AndrewKushnir removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Apr 30, 2020
@petebacondarwin petebacondarwin added the action: merge The PR is ready for merge by the caretaker label May 1, 2020
@alxhub alxhub closed this in bf0c520 May 1, 2020
alxhub pushed a commit that referenced this pull request May 1, 2020
…#36792)

This commit introduces `Diagnostics.merge(other)` which will take the messages from
`other` and append them to the messages of `this`.

The translation loader is updated to use this new method.

PR Close #36792
alxhub pushed a commit that referenced this pull request May 1, 2020
Previously only one translation file per locale could be loaded.

Now the user can specify multiple files per locale, and the translations
from each of these files will be merged together by message id.
The merging is on a first-wins approach. So if to you have three files
to be merged:

```
['a.xlf', 'b.xmb', 'c.json']
```

Then any message from `a.xlf` will be used rather than a message from `b.xmb`
or `c.json` and so on. In practice this means that you should put the files
in order of most important first, with "fallback" translations later.

PR Close #36792
@petebacondarwin
petebacondarwin deleted the i18n-merging-translation-files branch May 4, 2020 18:30
@angular-automatic-lock-bot

Copy link
Copy Markdown

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 Jun 4, 2020
profanis pushed a commit to profanis/angular that referenced this pull request Sep 5, 2020
)

Previously the `missingTranslation` option had to be checked before calling
`warn` or `error` on the `diagnostics` object.

Now this boilerplate is hidden inside the `Diagnostics.add()` method, which
will open it up to being used for other conditional diagnostics.

PR Close angular#36792
profanis pushed a commit to profanis/angular that referenced this pull request Sep 5, 2020
…angular#36792)

This commit introduces `Diagnostics.merge(other)` which will take the messages from
`other` and append them to the messages of `this`.

The translation loader is updated to use this new method.

PR Close angular#36792
profanis pushed a commit to profanis/angular that referenced this pull request Sep 5, 2020
…6792)

Previously only one translation file per locale could be loaded.

Now the user can specify multiple files per locale, and the translations
from each of these files will be merged together by message id.
The merging is on a first-wins approach. So if to you have three files
to be merged:

```
['a.xlf', 'b.xmb', 'c.json']
```

Then any message from `a.xlf` will be used rather than a message from `b.xmb`
or `c.json` and so on. In practice this means that you should put the files
in order of most important first, with "fallback" translations later.

PR Close angular#36792
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 Issues related to localization and internationalization cla: yes feature Label used to distinguish feature request from other issues target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants