Commit Graph

62 Commits

Author SHA1 Message Date
Pete Bacon Darwin fc4c3c3eb5 fix(localize): merge translation from all XLIFF `<file>` elements (#35936)
XLIFF translation files can contain multiple `<file>` elements,
each of which contains translations. In ViewEngine all these
translations are merged into a single translation bundle.

Previously in Ivy only the translations from the last `<file>`
element were being loaded. Now all the translations from each
`<file>` are merged into a single translation bundle.

Fixes #35839

PR Close #35936
2020-03-09 13:06:05 -04:00
Pete Bacon Darwin 0e2a577b42 fix(localize): improve matching and parsing of XTB translation files (#35793)
This commit improves the `canParse()` method to check that the file is
valid XML and has the expected root node. Previously it was relying upon
a regular expression to do this.

PR Close #35793
2020-03-09 12:11:58 -04:00
Pete Bacon Darwin 08071e5634 fix(localize): improve matching and parsing of XLIFF 2.0 translation files (#35793)
Previously, the `Xliff2TranslationParser` only matched files that had a narrow
choice of extensions (e.g. `xlf`) and also relied upon a regular expression
match of an optional XML namespace directive.

This commit relaxes the requirement on both of these and, instead, relies
upon parsing the file into XML and identifying an element of the form
`<xliff version="2.0">` which is the minimal requirement for such files.

PR Close #35793
2020-03-09 12:11:58 -04:00
Pete Bacon Darwin 350ac11554 fix(localize): improve matching and parsing of XLIFF 1.2 translation files (#35793)
Previously, the `Xliff1TranslationParser` only matched files that had a narrow
choice of extensions (e.g. `xlf`) and also relied upon a regular expression
match of an optional XML namespace directive.

This commit relaxes the requirement on both of these and, instead, relies
upon parsing the file into XML and identifying an element of the form
`<xliff version="1.2">` which is the minimal requirement for such files.

PR Close #35793
2020-03-09 12:11:58 -04:00
Pete Bacon Darwin cd32085a75 refactor(localize): allow hints from `canParse()` to `parse()` (#35793)
This enables complex work to be done in `TranslationParser.canParse()`
without duplicating the work in `TranslationParser.parse()`.

PR Close #35793
2020-03-09 12:11:58 -04:00
Pete Bacon Darwin d88b237f1e refactor(localize): add support for TranslationParser diagnostics (#35793)
This modifies the internal (but shared with CLI) API for loading/parsing
translation files. Now the parsers will return a new `Diagnostics` object
along with any translations and locale extracted from the file.

It is up to the caller to decide what to do about this, if there are errors
it is suggested that an error is thrown, which is what the `TranslationLoader`
class does.

PR Close #35793
2020-03-09 12:11:58 -04:00
Pete Bacon Darwin 53f059ee8f fix(localize): improve placeholder mismatch error message (#35593)
The original error message was confusing since often it is the
translation that is at fault not the message.

PR Close #35593
2020-02-24 09:11:21 -08:00
Pete Bacon Darwin df75451a0c fix(localize): support minified ES5 `$localize` calls (#35562)
Some minification tooling modifies `$localize` calls
to contain a comma sequence of items, where the
cooked and raw values are assigned to variables.

This change improves our ability to recognize these
structures.

Fixes #35376

PR Close #35562
2020-02-20 10:55:53 -08:00
Pete Bacon Darwin fb852f7252 build(localize): sync up babel dependencies (#35008)
In #34974 the top level dependency on `@babel/core` was bumped to
7.8.3. This commit ensures that the package.json that gets included
in the `@angular/localize` distributable is at the same version.

PR Close #35008
2020-01-29 09:24:08 -08:00
Pete Bacon Darwin 7069a83727 fix(localize): re-enable filename in code-frame error messages (#34994)
These were removed in 4c3a543f7f
due to a breaking change in an update to `babel-core`. See
dcf7d89b8e

This commit adds back in the filename to these messages.

Resolves https://github.com/angular/angular/pull/34974/files#r371034476

PR Close #34994
2020-01-27 12:25:40 -08:00
Igor Minar 4c3a543f7f test(localize): fix broken localize/translate tests (#34974)
the test failures most likely result from the babel updates in the previous commit.

it does look like we lost the file path from the error message, which is something that we

should follow up no in a separate change.

PR Close #34974
2020-01-26 14:53:47 -08:00
Igor Minar 7360e1ea2c build: add missing @babel/core bazel dep to fix //packages/localize/src/tools/test:test_lib (#34974)
Previously we relied on this package being hoisted and available, which is error prone and it would
be just a matter of time before the build would break due rehoisting of deps upon future npm package.json
changes.

PR Close #34974
2020-01-26 14:53:47 -08:00
Igor Minar a58034b316 build: add missing @babel/generator bazel dep to fix //packages/localize/src/tools/test:test (#34974)
It's not clear how this ever worked (npm hoisting is a suspect though), but this dep is required because
one of the tests imports @babel/generator in the ts sources.

The lack of this dep is breaking builds on the master branch.

More discussion about this issue on Slack: https://angular-team.slack.com/archives/C07DT5M6V/p1579934766007500

PR Close #34974
2020-01-26 14:53:46 -08:00
Paul Gschwendtner 970b22f98e test: setup circular dependency tests for all entry points (#34774)
Sets up circular dependency tests for all entry-points in the
project (except for the ones part of a deprecated package).

PR Close #34774
2020-01-23 11:36:40 -08:00
Greg Magolan a28c02bf89 build: derive ts_library dep from jasmine_node_test boostrap label if it ends in `_es5` (#34736)
PR Close #34736
2020-01-15 14:58:07 -05:00
Greg Magolan aee67f08d9 test: handle bootstrap templated_args in jasmine_node_test defaults.bzl (#34736)
PR Close #34736
2020-01-15 14:58:07 -05:00
Greg Magolan dcff76e8b9 refactor: handle breaking changes in rules_nodejs 1.0.0 (#34736)
The major one that affects the angular repo is the removal of the bootstrap attribute in nodejs_binary, nodejs_test and jasmine_node_test in favor of using templated_args --node_options=--require=/path/to/script. The side-effect of this is that the bootstrap script does not get the require.resolve patches with explicitly loading the targets _loader.js file.

PR Close #34736
2020-01-15 14:58:07 -05:00
Greg Magolan 93c2df23bf build: upgrade to rules_nodejs 1.0.0 (first stable release) (#34736)
Brings in the fix for stamping which was preventing many targets from getting cached.

PR Close #34736
2020-01-15 14:58:07 -05:00
atscott e88d652f2a Revert "build: upgrade to rules_nodejs 1.0.0 (first stable release) (#34589)" (#34730)
This reverts commit cb6ffa1211.

PR Close #34730
2020-01-10 14:12:15 -08:00
atscott 538d0446b5 Revert "refactor: handle breaking changes in rules_nodejs 1.0.0 (#34589)" (#34730)
This reverts commit 9bb349e1c8.

PR Close #34730
2020-01-10 14:12:15 -08:00
atscott 5e60215470 Revert "test: handle bootstrap templated_args in jasmine_node_test defaults.bzl (#34589)" (#34730)
This reverts commit da4782e67f.

PR Close #34730
2020-01-10 14:12:15 -08:00
atscott 24679d8676 Revert "build: derive ts_library dep from jasmine_node_test boostrap label if it ends in `_es5` (#34589)" (#34730)
This reverts commit 79a0d007b4.

PR Close #34730
2020-01-10 14:12:14 -08:00
Greg Magolan 79a0d007b4 build: derive ts_library dep from jasmine_node_test boostrap label if it ends in `_es5` (#34589)
PR Close #34589
2020-01-10 08:32:00 -08:00
Greg Magolan da4782e67f test: handle bootstrap templated_args in jasmine_node_test defaults.bzl (#34589)
PR Close #34589
2020-01-10 08:31:59 -08:00
Greg Magolan 9bb349e1c8 refactor: handle breaking changes in rules_nodejs 1.0.0 (#34589)
The major one that affects the angular repo is the removal of the bootstrap attribute in nodejs_binary, nodejs_test and jasmine_node_test in favor of using templated_args --node_options=--require=/path/to/script. The side-effect of this is that the bootstrap script does not get the require.resolve patches with explicitly loading the targets _loader.js file.

PR Close #34589
2020-01-10 08:31:59 -08:00
Greg Magolan cb6ffa1211 build: upgrade to rules_nodejs 1.0.0 (first stable release) (#34589)
Brings in the fix for stamping which was preventing many targets from getting cached.

PR Close #34589
2020-01-10 08:31:58 -08:00
Pete Bacon Darwin 6ce940315b fix(ivy): i18n - remove `translate` function when clearing translations (#34346)
The `loadTranslations()` function will attach the `translate()` function
to `$localize.translate` to cause runtime translation to occur.

We should cleanup after ourselves by unattaching this function when
we call `clearTranslations()`.

Fixes #32781

PR Close #34346
2019-12-11 13:19:22 -08:00
Pete Bacon Darwin 8e96b450e2 refactor(ivy): i18n - store legacy message ids separately to custom ids (#34135)
This change will enable the Angular compiler to provide these legacy
message ids by default, which will solve problems with ngcc not knowing
whether to generate legacy ids or not.

PR Close #34135
2019-12-03 10:15:53 -08:00
Pete Bacon Darwin 80d326bd49 refactor(ivy): i18n - remove hack around TS tagged literals (#34135)
When first written there was no way to specify the raw text when
programmatically creating a template tagged literal AST node.

This is now fixed in TS and so the hack is no longer needed.

PR Close #34135
2019-12-03 10:15:52 -08:00
Pete Bacon Darwin d529b55651 fix(ivy): i18n - correctly parse XLIFF placeholders (#34155)
The ViewEngine translation extractor does not convert `-` to `_` for
placeholders that represent custom elements. For example `<app-component>`
gets converted to placeholders like `START_TAG_APP-COMPONENT`.

In `$localize` placeholders are expected to be snake-case, not kebab-case.
So we must normalize them when parsing a translation file that might have
been created via the View Engine translation extractor.

The `$localize` extraction code will normalize these placeholders when
creating translation files in the first place.

Fixes #34151

PR Close #34155
2019-12-02 11:24:48 -08:00
Igor Minar ea37e82e69 build: consolidate @angular-devkit/build-angular to the root package.json (#34002)
This allows us to update the version of the package in a single place for all tests.

Notable exemption of this is aio which currently doesn't depend on anything installed in the root.

PR Close #34002
2019-12-02 10:49:12 -08:00
Joey Perrott 1d563a7acd build: set up all packages to publish via wombot proxy (#33747)
PR Close #33747
2019-11-13 11:34:33 -08:00
Pete Bacon Darwin 936700ad9f fix(compiler): i18n - ignore `alt-trans` tags in XLIFF 1.2 (#33450)
The parser was accidentally reading the `target` tag
below the `alt-trans` target and overriding the correct
`target` tag.

(This already worked in `$localize` but a test has been
added to confirm.)

Fixes #33161

PR Close #33450
2019-10-29 11:49:32 -07:00
Pete Bacon Darwin 2c623fde16 feat(ivy): i18n - support inlining of XTB formatted translation files (#33444)
This commit implements the `XtbTranslationParser`, which can read XTB
formatted files.

PR Close #33444
2019-10-28 16:20:33 -07:00
Pete Bacon Darwin c2f13a1e3a refactor(ivy): i18n - share `MessageSerializer` across `TranslationParsers` (#33444)
Each of the XML based `TranslationParsers` was providing its own
`MessageSerializer`, but they are all very similar. So these have been
consolidated into a single more generic `MessageSerializer.

As a result of this, the extra layers of folders in the project seemed
unnecessary, so they have been flattened.

PR Close #33444
2019-10-28 16:20:33 -07:00
Pete Bacon Darwin 41979d6a27 fix(ivy): i18n - update `localize-translate` to accept target-locales (#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
2019-10-28 10:09:15 -07:00
Pete Bacon Darwin 62b2840822 fix(ivy): i18n - support setting locales for each translation file (#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 #33323

PR Close #33381
2019-10-28 10:09:15 -07:00
Pete Bacon Darwin fb84ea74fe feat(ivy): i18n - inline current locale at compile-time (#33314)
During compile-time translation inlining, the `$localize.locale`
expression will now be replaced with a string literal containing the
current locale of the translations.

PR Close #33314
2019-10-24 10:16:26 -07:00
Pete Bacon Darwin f17072c7af refactor(ivy): i18n - create and use `isLocalize()` helper (#33314)
PR Close #33314
2019-10-24 10:16:26 -07:00
Pete Bacon Darwin fde8363e0d feat(ivy): allow the locale to be set via a global property (#33314)
In the post-$localize world the current locale value is defined by setting
`$localize.locale` which is then read at runtime by Angular in the provider
for the `LOCALE_ID` token and also passed to the ivy machinery via`setLocaleId()`.

The $localize compile-time inlining tooling can replace occurrences of
`$localize.locale` with a string literal, similar to how translations
are inlined.

// FW-1639

See https://github.com/angular/angular-cli/issues/15896

PR Close #33314
2019-10-24 10:16:25 -07:00
Alex Eagle 422eb14dc0 build: remove vendored Babel typings (#33226)
These were getting included in the @angular/localize package.
Instead, patch the upstream files to work with TS typeRoots option

See bazelbuild/rules_nodejs#1033

PR Close #33226
2019-10-17 18:45:52 -04:00
Matias Niemelä e9ee6859e3 revert: build: remove vendored Babel typings (#33176) (#33215)
This reverts commit 4c63e6ba04.

PR Close #33215
2019-10-17 00:24:25 -04:00
Alex Eagle 4c63e6ba04 build: remove vendored Babel typings (#33176)
These were getting included in the @angular/localize package.
Instead, patch the upstream files to work with TS typeRoots option

See bazelbuild/rules_nodejs#1033

PR Close #33176
2019-10-16 12:54:28 -04:00
Pete Bacon Darwin f433d6604b feat(ivy): i18n - support source locale inlining (#33101)
Add a new flag to `localize-translate` that allows the
source locale to be specified. When this locale is
provided an extra copy of the files is made for this
locale where the is no translation but all the calls to
`$localize` are stripped out.

Resolves FW-1623

PR Close #33101
2019-10-14 20:32:57 +00:00
Pete Bacon Darwin 83425fa119 fix(ivy): i18n - support lazy-load template string helpers (#33097)
There are numerous approaches to downlevelling backticked
template strings to ES5.
This commit handles yet another one that Babel applies.

PR Close #33097
2019-10-14 16:33:39 +00:00
Pete Bacon Darwin 1845faa66b fix(ivy): i18n - strip meta blocks from untranslated messages (#33097)
If a message has no translation then we should still strip the
meta blocks from the message parts before adding back to the
AST.

PR Close #33097
2019-10-14 16:33:38 +00:00
Pete Bacon Darwin d617373a76 refactor(ivy): i18n - change `unwrapMessagePartsFromLocalizeCall` to accept a `NodePath` (#33097)
In Babel `NodePath` objects have more useful information available than
simple AST nodes. But they are more difficult to create, especially for testing.

This commit prepares the way for parsing more complex code downlevelling
scenarios.

PR Close #33097
2019-10-14 16:33:38 +00:00
Pete Bacon Darwin 90855f331f refactor(ivy): i18n - rename `I18nError` to `TranslationParserError` (#32881)
This closer reflects what caused the error.

PR Close #32881
2019-10-09 13:19:38 -07:00
Pete Bacon Darwin 2cdb3a079d feat(ivy): i18n - implement compile-time inlining (#32881)
This commit implements a tool that will inline translations and generate
a translated copy of a set of application files from a set of translation
files.

PR Close #32881
2019-10-09 13:19:38 -07:00
cexbrayat d18289fa9c fix(ivy): missing schematics field in localize package (#33025)
The schematics added in #32791 is currently failing as the package.json does not reference it.

```
> ng add @angular/localize@9.0.0-next.9
+ @angular/localize@9.0.0-next.9
added 1 package from 1 contributor in 6.745s
Installed packages for tooling via npm.
The package that you are trying to add does not support schematics. You can try using a different version of the package or contact the package author to add ng-add support.
```

PR Close #33025
2019-10-07 10:21:29 -07:00