Commit Graph

56 Commits

Author SHA1 Message Date
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
Pete Bacon Darwin 9188751adc fix(ivy): i18n - do not render message ids unnecessarily (#32867)
In an attempt to be compatible with previous translation files
the Angular compiler was generating instructions that always
included the message id. This was because it was not possible
to accurately re-generate the id from the calls to `$localize()` alone.

In line with https://hackmd.io/EQF4_-atSXK4XWg8eAha2g this
commit changes the compiler so that it only renders ids if they are
"custom" ones provided by the template author.

NOTE:

When translating messages generated by the Angular compiler
from i18n tags in templates, the `$localize.translate()` function
will compute message ids, if no custom id is provided, using a
common digest function that only relies upon the information
available in the `$localize()` calls.

This computed message id will not be the same as the message
ids stored in legacy translation files. Such files will need to be
migrated to use the new common digest function.

This only affects developers who have been trialling `$localize`, have
been calling `loadTranslations()`, and are not exclusively using custom
ids in their templates.

PR Close #32867
2019-10-02 14:52:00 -07:00
Pete Bacon Darwin d24ade91b8 fix(ivy): i18n - support colons in $localize metadata (#32867)
Metadata blocks are delimited by colons. Previously the code naively just
looked for the next colon in the string as the end marker.

This commit supports escaping colons within the metadata content.
The Angular compiler has been updated to add escaping as required.

PR Close #32867
2019-10-02 14:52:00 -07:00
Pete Bacon Darwin 97d5700456 fix(ivy): i18n - better translation warnings (#32867)
The missing translation and invalid placeholder warnings now contain the
"meaning" if one was provided.

PR Close #32867
2019-10-02 14:52:00 -07:00
Pete Bacon Darwin 601f87c2ec fix(ivy): i18n - throw an error if a translation contains an invalid placeholder (#32867)
Previously if a translation contains a placeholder that
does not exist in the message being translated, that
placeholder is evaluated as `undefined`.

Translations should never contain such placeholder names
so now `translate` will throw a helpful error in instead.

PR Close #32867
2019-10-02 14:52:00 -07:00
Filipe Silva e41cbfb585 feat(ivy): support ng-add in localize package (#32791)
PR Close #32791
2019-09-27 13:15:02 -07:00
cexbrayat f1b1de9a3d fix(ivy): i18n - start generated placeholder name at `PH` (#32493)
Currently the expressions used in a template string are automatically named
`PH_1`, `PH_2`, etc. Whereas interpolations used in i18n templates generate
placeholders automatically named `INTERPOLATION`, `INTERPOLATION_1`, etc.

This commit aligns the behaviors by starting the generated placeholder
names for expressions at `PH`, then `PH_1`, etc.

It also documents this behavior in the documentation of `$localize` as
it was not mentioned before.

PR Close #32493
2019-09-17 15:13:30 -07:00