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

Drop use of the Intl API to improve browser support #18284

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,6 +5,7 @@ bazel-*
e2e_test.*
node_modules
bower_components
tools/gulp-tasks/cldr/cldr-data/

# Include when developing application packages.
pubspec.lock
Expand Down
6 changes: 6 additions & 0 deletions aio/content/examples/i18n/src/app/app.locale_data.ts
@@ -0,0 +1,6 @@
// #docregion import-locale
import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/i18n_data/locale_fr';

registerLocaleData(localeFr);
// #enddocregion import-locale
7 changes: 7 additions & 0 deletions aio/content/examples/i18n/src/app/app.locale_data_extra.ts
@@ -0,0 +1,7 @@
// #docregion import-locale-extra
import { registerLocaleData } from '@angular/common';
import localeEnGB from '@angular/common/i18n_data/locale_en-GB';
import localeEnGBExtra from '@angular/common/i18n_data/extra/locale_en-GB';

registerLocaleData(localeEnGB, localeEnGBExtra);
// #enddocregion import-locale-extra
2 changes: 1 addition & 1 deletion aio/content/examples/pipes/e2e-spec.ts
Expand Up @@ -28,7 +28,7 @@ describe('Pipes', function () {

it('should be able to toggle birthday formats', function () {
let birthDayEle = element(by.css('hero-birthday2 > p'));
expect(birthDayEle.getText()).toEqual(`The hero's birthday is 4/15/1988`);
expect(birthDayEle.getText()).toEqual(`The hero's birthday is 4/15/88`);
let buttonEle = element(by.cssContainingText('hero-birthday2 > button', 'Toggle Format'));
expect(buttonEle.isDisplayed()).toBe(true);
buttonEle.click().then(function() {
Expand Down
2 changes: 1 addition & 1 deletion aio/content/guide/browser-support.md
Expand Up @@ -347,7 +347,7 @@ Here are the features which may require additional polyfills:

<td>

[Date](api/common/DatePipe), [currency](api/common/CurrencyPipe), [decimal](api/common/DecimalPipe) and [percent](api/common/PercentPipe) pipes
If you use the following deprecated i18n pipes: [date](api/common/DeprecatedDatePipe), [currency](api/common/DeprecatedCurrencyPipe), [decimal](api/common/DeprecatedDecimalPipe) and [percent](api/common/DeprecatedPercentPipe)
</td>

<td>
Expand Down
22 changes: 22 additions & 0 deletions aio/content/guide/i18n.md
Expand Up @@ -40,6 +40,28 @@ You need to build and deploy a separate version of the application for each supp

{@a i18n-attribute}

## i18n pipes

Angular pipes can help you with internationalization: the `DatePipe`, `CurrencyPipe`, `DecimalPipe`
and `PercentPipe` use locale data to format your data based on your `LOCALE_ID`.

By default Angular only contains locale data for the language `en-US`, if you set the value of
`LOCALE_ID` to another locale, you will have to import new locale data for this language:

<code-example path="i18n/src/app/app.locale_data.ts" region="import-locale" title="src/app/app.locale_data.ts" linenums="false">
</code-example>

<div class="l-sub-section">

Note that the files in `@angular/common/i18n_data` contain most of the locale data that you will
need, but some advanced formatting options might only be available in the extra dataset that you can
import from `@angular/common/i18n_data/extra`:

<code-example path="i18n/src/app/app.locale_data_extra.ts" region="import-locale-extra" title="src/app/app.locale_data_extra.ts" linenums="false">
</code-example>

</div>

## Mark text with the _i18n_ attribute

The Angular `i18n` attribute is a marker for translatable content.
Expand Down
18 changes: 0 additions & 18 deletions aio/content/guide/pipes.md
Expand Up @@ -46,24 +46,6 @@ Inside the interpolation expression, you flow the component's `birthday` value t
function on the right. All pipes work this way.


<div class="l-sub-section">



The `Date` and `Currency` pipes need the *ECMAScript Internationalization API*.
Safari and other older browsers don't support it. You can add support with a polyfill.


<code-example language="html">
&lt;script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Intl.~locale.en"&gt;&lt;/script&gt;

</code-example>



</div>




## Built-in pipes
Expand Down
7 changes: 6 additions & 1 deletion build.sh
Expand Up @@ -86,7 +86,7 @@ done
#######################################
isIgnoredDirectory() {
name=$(basename ${1})
if [[ -f "${1}" || "${name}" == "src" || "${name}" == "test" || "${name}" == "integrationtest" ]]; then
if [[ -f "${1}" || "${name}" == "src" || "${name}" == "test" || "${name}" == "integrationtest" || "${name}" == "i18n_data" ]]; then
return 0
else
return 1
Expand Down Expand Up @@ -470,6 +470,11 @@ do
minify ${BUNDLES_DIR}

) 2>&1 | grep -v "as external dependency"

if [[ ${PACKAGE} == "common" ]]; then
echo "====== Copy i18n locale data"
rsync -a --exclude=*.d.ts --exclude=*.metadata.json ${OUT_DIR}/i18n_data/ ${NPM_DIR}/i18n_data
fi
else
echo "====== Copy ${PACKAGE} node tool"
rsync -a ${OUT_DIR}/ ${NPM_DIR}
Expand Down
2 changes: 2 additions & 0 deletions gulpfile.js
Expand Up @@ -42,3 +42,5 @@ gulp.task('serve', loadTask('serve', 'default'));
gulp.task('serve-examples', loadTask('serve', 'examples'));
gulp.task('changelog', loadTask('changelog'));
gulp.task('check-env', () => {/* this is a noop because the env test ran already above */});
gulp.task('cldr:extract', loadTask('cldr', 'extract'));
gulp.task('cldr:download', loadTask('cldr', 'download'));
3 changes: 2 additions & 1 deletion karma-js.conf.js
Expand Up @@ -47,7 +47,8 @@ module.exports = function(config) {
pattern: 'packages/platform-browser/test/browser/static_assets/**',
included: false,
watched: false,
}
},
{pattern: 'packages/common/i18n/**', included: false, watched: false, served: true},
],

exclude: [
Expand Down
92 changes: 84 additions & 8 deletions npm-shrinkwrap.clean.json
Expand Up @@ -1542,7 +1542,7 @@
}
},
"cldr": {
"version": "3.5.2",
"version": "4.5.0",
"dependencies": {
"uglify-js": {
"version": "1.3.3"
Expand All @@ -1552,6 +1552,59 @@
}
}
},
"cldr-data-downloader": {
"version": "0.3.2",
"dependencies": {
"adm-zip": {
"version": "0.4.4"
},
"async": {
"version": "2.5.0"
},
"bl": {
"version": "1.1.2"
},
"form-data": {
"version": "1.0.1"
},
"isarray": {
"version": "1.0.0"
},
"lodash": {
"version": "4.17.4"
},
"mime-db": {
"version": "1.27.0"
},
"mime-types": {
"version": "2.1.15"
},
"minimist": {
"version": "0.0.8"
},
"mkdirp": {
"version": "0.5.0"
},
"q": {
"version": "1.0.1"
},
"qs": {
"version": "6.2.3"
},
"readable-stream": {
"version": "2.0.6"
},
"request": {
"version": "2.74.0"
},
"tough-cookie": {
"version": "2.3.2"
}
}
},
"cldrjs": {
"version": "0.5.0"
},
"cli-boxes": {
"version": "1.0.0"
},
Expand Down Expand Up @@ -1660,6 +1713,9 @@
}
}
},
"config-chain": {
"version": "1.1.11"
},
"configstore": {
"version": "2.1.0",
"dependencies": {
Expand Down Expand Up @@ -3717,13 +3773,10 @@
"version": "0.3.0"
},
"memoizeasync": {
"version": "0.8.0",
"version": "1.0.0",
"dependencies": {
"lru-cache": {
"version": "2.5.0"
},
"passerror": {
"version": "0.0.2"
}
}
},
Expand Down Expand Up @@ -3876,6 +3929,14 @@
"normalize-path": {
"version": "2.0.1"
},
"npmconf": {
"version": "2.0.9",
"dependencies": {
"semver": {
"version": "4.3.6"
}
}
},
"npmlog": {
"version": "4.0.2"
},
Expand Down Expand Up @@ -4014,7 +4075,7 @@
"version": "2.0.0"
},
"passerror": {
"version": "0.0.1"
"version": "1.1.1"
},
"path-browserify": {
"version": "0.0.0"
Expand Down Expand Up @@ -4081,6 +4142,9 @@
"process-nextick-args": {
"version": "1.0.6"
},
"progress": {
"version": "1.1.8"
},
"promise": {
"version": "7.1.1"
},
Expand All @@ -4095,6 +4159,9 @@
}
}
},
"proto-list": {
"version": "1.2.4"
},
"protobufjs": {
"version": "5.0.0",
"dependencies": {
Expand Down Expand Up @@ -4342,6 +4409,9 @@
"request-capture-har": {
"version": "1.1.4"
},
"request-progress": {
"version": "0.3.1"
},
"requires-port": {
"version": "1.0.0"
},
Expand Down Expand Up @@ -4760,6 +4830,9 @@
"text-extensions": {
"version": "1.3.3"
},
"throttleit": {
"version": "0.0.2"
},
"through": {
"version": "2.3.8"
},
Expand Down Expand Up @@ -4932,6 +5005,9 @@
"uglify-to-browserify": {
"version": "1.0.2"
},
"uid-number": {
"version": "0.0.5"
},
"uid-safe": {
"version": "2.0.0"
},
Expand Down Expand Up @@ -5271,13 +5347,13 @@
"version": "8.2.2"
},
"xmldom": {
"version": "0.1.19"
"version": "0.1.27"
},
"xmlhttprequest-ssl": {
"version": "1.5.1"
},
"xpath": {
"version": "0.0.7"
"version": "0.0.24"
},
"xtend": {
"version": "4.0.1"
Expand Down