Skip to content

docs: add example for providing custom MatPaginatorIntl #22771

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"@angular/bazel": "^12.0.0",
"@angular/compiler-cli": "^12.0.0",
"@angular/dev-infra-private": "https://github.com/angular/dev-infra-private-builds.git#2e0271af93b020a811323fbc274afcf588dbc91e",
"@angular/localize": "^12.0.0",
"@angular/platform-browser-dynamic": "^12.0.0",
"@angular/platform-server": "^12.0.0",
"@angular/router": "^12.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ VERSION_PLACEHOLDER_REPLACEMENTS = {
# List of default Angular library UMD bundles which are not processed by ngcc.
ANGULAR_NO_NGCC_BUNDLES = [
("@angular/compiler", ["compiler.umd.js"]),
("@angular/localize", ["localize.umd.js", "localize-init.umd.js"]),
]

# List of Angular library UMD bundles which will are processed by ngcc.
Expand Down
1 change: 1 addition & 0 deletions scripts/check-rollup-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const filesToCheckGlob = [
'!src/+(e2e-app|universal-app|dev-app)/**/*.ts',
'!src/**/schematics/**/*.ts',
'!src/**/tests/**/*.ts',
'!src/components-examples/private/localize-types.d.ts',
];

const failures = new Map<string, string[]>();
Expand Down
1 change: 1 addition & 0 deletions src/components-examples/material/paginator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ng_module(
deps = [
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/components-examples/private:localize_types",
"//src/material/input",
"//src/material/paginator",
"//src/material/paginator/testing",
Expand Down
7 changes: 7 additions & 0 deletions src/components-examples/material/paginator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ import {
} from './paginator-configurable/paginator-configurable-example';
import {PaginatorOverviewExample} from './paginator-overview/paginator-overview-example';
import {PaginatorHarnessExample} from './paginator-harness/paginator-harness-example';
import {
PaginatorIntlExample,
PaginatorIntlExampleModule,
} from './paginator-intl/paginator-intl-example';

export {
PaginatorConfigurableExample,
PaginatorHarnessExample,
PaginatorIntlExample,
PaginatorOverviewExample,
};

const EXAMPLES = [
PaginatorConfigurableExample,
PaginatorHarnessExample,
// PaginatorIntlExample is imported through it's own example module.
PaginatorOverviewExample,
];

Expand All @@ -26,6 +32,7 @@ const EXAMPLES = [
CommonModule,
MatInputModule,
MatPaginatorModule,
PaginatorIntlExampleModule,
FormsModule,
],
declarations: EXAMPLES,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<mat-paginator [length]="0" [pageSizeOptions]="[10, 50, 100]">
</mat-paginator>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {Component, Injectable, NgModule} from '@angular/core';
import {MatPaginatorIntl, MatPaginatorModule} from '@angular/material/paginator';
import {Subject} from 'rxjs';

@Injectable()
export class MyCustomPaginatorIntl implements MatPaginatorIntl {
changes = new Subject<void>();

// For internationalization, the `$localize` function from
// the `@angular/localize` package can be used.
firstPageLabel = $localize`First page`;
itemsPerPageLabel = $localize`Items per page:`;
lastPageLabel = $localize`Last page`;

// You can set labels to an arbitrary string too, or dynamically compute
// it through other third-party internationalization libraries.
nextPageLabel = 'Next page';
previousPageLabel = 'Previous page';

getRangeLabel(page: number, pageSize: number, length: number): string {
if (length === 0) {
return $localize`Page 1 of 1`;
}
const amountPages = Math.ceil(length / pageSize);
return $localize`Page ${page + 1} of ${amountPages}`;
}
}

/**
* @title Paginator internationalization
*/
@Component({
selector: 'paginator-intl-example',
templateUrl: 'paginator-intl-example.html',
})
export class PaginatorIntlExample {}

@NgModule({
imports: [MatPaginatorModule],
declarations: [PaginatorIntlExample],
providers: [
{provide: MatPaginatorIntl, useClass: MyCustomPaginatorIntl}
]
})
export class PaginatorIntlExampleModule {}
5 changes: 5 additions & 0 deletions src/components-examples/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ ts_library(
"@npm//@angular/core",
],
)

ts_library(
name = "localize_types",
srcs = ["localize-types.d.ts"],
)
5 changes: 5 additions & 0 deletions src/components-examples/private/localize-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {LocalizeFn} from '@angular/localize/src/localize';

declare global {
const $localize: LocalizeFn;
}
1 change: 1 addition & 0 deletions src/dev-app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ ng_module(
"//src/dev-app/virtual-scroll",
"//src/dev-app/youtube-player",
"//src/material/core",
"@npm//@angular/localize",
"@npm//@angular/router",
],
)
Expand Down
5 changes: 2 additions & 3 deletions src/dev-app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

/**
* This is the main entry-point for the AOT compilation. File will be used to test AOT support.
*/
// Load `$localize` for examples using it.
import '@angular/localize/init';

import {platformBrowser} from '@angular/platform-browser';
import {MainModuleNgFactory} from './main-module.ngfactory';
Expand Down
5 changes: 3 additions & 2 deletions tools/system-config-tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ function setupFrameworkPackages() {
// When running with Ivy, we need to load the ngcc processed UMD bundles.
// These are stored in the `__ivy_ngcc_` folder that has been generated
// since we run ngcc with `--create-ivy-entry-points`. Filter out the compiler
// package because it won't be processed by ngcc.
if (isRunningWithIvy && entryPointName !== '@angular/compiler') {
// and localize package because it won't be processed by ngcc.
if (isRunningWithIvy && entryPointName !== '@angular/compiler' &&
!entryPointName.startsWith('@angular/localize')) {
bundlePath = '__ivy_ngcc__/' + bundlePath;
}
packagesConfig[entryPointName] = {
Expand Down
108 changes: 108 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@
dependencies:
tslib "^2.1.0"

"@angular/localize@^12.0.0":
version "12.0.1"
resolved "https://registry.yarnpkg.com/@angular/localize/-/localize-12.0.1.tgz#6477066b6e4830c9dffa931064794108961d4364"
integrity sha512-+nLvfbX2tQUMCDILlUOhb1o3B7DzcJgrEy3QEG3dGkT7A7RjA5zShXN+CXuaeEMlTSGURVx3IEzuudpGcgLz9Q==
dependencies:
"@babel/core" "7.8.3"
glob "7.1.7"
yargs "^16.2.0"

"@angular/platform-browser-dynamic@^12.0.0":
version "12.0.0"
resolved "https://registry.yarnpkg.com/@angular/platform-browser-dynamic/-/platform-browser-dynamic-12.0.0.tgz#295036e7b487b6dbe3b13db763a371675d391ee6"
Expand Down Expand Up @@ -236,6 +245,27 @@
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.13.12.tgz#a8a5ccac19c200f9dd49624cac6e19d7be1236a1"
integrity sha512-3eJJ841uKxeV8dcN/2yGEUy+RfgQspPEgQat85umsE1rotuquQ2AbIub4S6j7c50a2d+4myc+zSlnXeIHrOnhQ==

"@babel/[email protected]":
version "7.8.3"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.8.3.tgz#30b0ebb4dd1585de6923a0b4d179e0b9f5d82941"
integrity sha512-4XFkf8AwyrEG7Ziu3L2L0Cv+WyY47Tcsp70JFmpftbAA1K7YL/sgE9jh9HyNj08Y/U50ItUchpN0w6HxAoX1rA==
dependencies:
"@babel/code-frame" "^7.8.3"
"@babel/generator" "^7.8.3"
"@babel/helpers" "^7.8.3"
"@babel/parser" "^7.8.3"
"@babel/template" "^7.8.3"
"@babel/traverse" "^7.8.3"
"@babel/types" "^7.8.3"
convert-source-map "^1.7.0"
debug "^4.1.0"
gensync "^1.0.0-beta.1"
json5 "^2.1.0"
lodash "^4.17.13"
resolve "^1.3.2"
semver "^5.4.1"
source-map "^0.5.0"

"@babel/core@>=7.9.0":
version "7.9.0"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.9.0.tgz#ac977b538b77e132ff706f3b8a4dbad09c03c56e"
Expand Down Expand Up @@ -329,6 +359,15 @@
jsesc "^2.5.1"
source-map "^0.5.0"

"@babel/generator@^7.14.2", "@babel/generator@^7.8.3":
version "7.14.3"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.14.3.tgz#0c2652d91f7bddab7cccc6ba8157e4f40dcedb91"
integrity sha512-bn0S6flG/j0xtQdz3hsjJ624h3W0r3llttBMfyHX3YrZ/KtLYr15bjA0FXkgW7FpvrDuTuElXeVjiKlYRpnOFA==
dependencies:
"@babel/types" "^7.14.2"
jsesc "^2.5.1"
source-map "^0.5.0"

"@babel/generator@^7.9.0", "@babel/generator@^7.9.5":
version "7.9.5"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.9.5.tgz#27f0917741acc41e6eaaced6d68f96c3fa9afaf9"
Expand Down Expand Up @@ -367,6 +406,15 @@
"@babel/template" "^7.12.13"
"@babel/types" "^7.12.13"

"@babel/helper-function-name@^7.14.2":
version "7.14.2"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.14.2.tgz#397688b590760b6ef7725b5f0860c82427ebaac2"
integrity sha512-NYZlkZRydxw+YT56IlhIcS8PAhb+FEUiOzuhFTfqDyPmzAhRge6ua0dQYT/Uh0t/EDHq05/i+e5M2d4XvjgarQ==
dependencies:
"@babel/helper-get-function-arity" "^7.12.13"
"@babel/template" "^7.12.13"
"@babel/types" "^7.14.2"

"@babel/helper-function-name@^7.9.5":
version "7.9.5"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.9.5.tgz#2b53820d35275120e1874a82e5aabe1376920a5c"
Expand Down Expand Up @@ -591,6 +639,11 @@
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.12.11.tgz#c9a1f021917dcb5ccf0d4e453e399022981fc9ed"
integrity sha512-np/lG3uARFybkoHokJUmf1QfEvRVCPbmQeUQpKow5cQ3xWrV9i3rUHodKDJPQfTVX61qKi+UdYk8kik84n7XOw==

"@babel/helper-validator-identifier@^7.14.0":
version "7.14.0"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.0.tgz#d26cad8a47c65286b15df1547319a5d0bcf27288"
integrity sha512-V3ts7zMSu5lfiwWDVWzRDGIN+lnCEUdaXgtVHJgLb1rGaA6jMrtB9EmE7L18foXJIE8Un/A/h6NJfGQp/e1J4A==

"@babel/helper-validator-identifier@^7.9.0", "@babel/helper-validator-identifier@^7.9.5":
version "7.9.5"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.5.tgz#90977a8e6fbf6b431a7dc31752eee233bf052d80"
Expand Down Expand Up @@ -619,6 +672,15 @@
"@babel/traverse" "^7.13.0"
"@babel/types" "^7.13.0"

"@babel/helpers@^7.8.3":
version "7.14.0"
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.14.0.tgz#ea9b6be9478a13d6f961dbb5f36bf75e2f3b8f62"
integrity sha512-+ufuXprtQ1D1iZTO/K9+EBRn+qPWMJjZSw/S0KlFrxCw4tkrzv9grgpDHkY9MeQTjTY8i2sp7Jep8DfU6tN9Mg==
dependencies:
"@babel/template" "^7.12.13"
"@babel/traverse" "^7.14.0"
"@babel/types" "^7.14.0"

"@babel/helpers@^7.9.0":
version "7.9.2"
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.9.2.tgz#b42a81a811f1e7313b88cba8adc66b3d9ae6c09f"
Expand Down Expand Up @@ -684,6 +746,11 @@
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.13.12.tgz#ba320059420774394d3b0c0233ba40e4250b81d1"
integrity sha512-4T7Pb244rxH24yR116LAuJ+adxXXnHhZaLJjegJVKSdoNCe4x1eDBaud5YIcQFcqzsaD5BHvJw5BQ0AZapdCRw==

"@babel/parser@^7.14.2", "@babel/parser@^7.8.3":
version "7.14.3"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.14.3.tgz#9b530eecb071fd0c93519df25c5ff9f14759f298"
integrity sha512-7MpZDIfI7sUC5zWo2+foJ50CSI5lcqDehZ0lVgIhSi4bFEk94fLAKlF3Q0nzSQQ+ca0lm+O6G9ztKVBeu8PMRQ==

"@babel/parser@^7.8.6", "@babel/parser@^7.9.0":
version "7.9.4"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.9.4.tgz#68a35e6b0319bbc014465be43828300113f2f2e8"
Expand Down Expand Up @@ -751,6 +818,20 @@
globals "^11.1.0"
lodash "^4.17.19"

"@babel/traverse@^7.14.0", "@babel/traverse@^7.8.3":
version "7.14.2"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.14.2.tgz#9201a8d912723a831c2679c7ebbf2fe1416d765b"
integrity sha512-TsdRgvBFHMyHOOzcP9S6QU0QQtjxlRpEYOy3mcCO5RgmC305ki42aSAmfZEMSSYBla2oZ9BMqYlncBaKmD/7iA==
dependencies:
"@babel/code-frame" "^7.12.13"
"@babel/generator" "^7.14.2"
"@babel/helper-function-name" "^7.14.2"
"@babel/helper-split-export-declaration" "^7.12.13"
"@babel/parser" "^7.14.2"
"@babel/types" "^7.14.2"
debug "^4.1.0"
globals "^11.1.0"

"@babel/traverse@^7.8.6", "@babel/traverse@^7.9.0":
version "7.9.5"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.9.5.tgz#6e7c56b44e2ac7011a948c21e283ddd9d9db97a2"
Expand Down Expand Up @@ -808,6 +889,14 @@
lodash "^4.17.19"
to-fast-properties "^2.0.0"

"@babel/types@^7.14.0", "@babel/types@^7.14.2":
version "7.14.2"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.14.2.tgz#4208ae003107ef8a057ea8333e56eb64d2f6a2c3"
integrity sha512-SdjAG/3DikRHpUOjxZgnkbR11xUlyDMUFJdvnIgZEE16mqmY0BINMmc4//JMJglEmn6i7sq6p+mGrFWyZ98EEw==
dependencies:
"@babel/helper-validator-identifier" "^7.14.0"
to-fast-properties "^2.0.0"

"@babel/types@^7.8.3", "@babel/types@^7.8.6", "@babel/types@^7.9.0", "@babel/types@^7.9.5":
version "7.9.5"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.9.5.tgz#89231f82915a8a566a703b3b20133f73da6b9444"
Expand Down Expand Up @@ -7243,6 +7332,18 @@ [email protected], glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6, glob@^7.1.1, glo
once "^1.3.0"
path-is-absolute "^1.0.0"

[email protected]:
version "7.1.7"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90"
integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.4"
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^5.0.15:
version "5.0.15"
resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1"
Expand Down Expand Up @@ -8690,6 +8791,13 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1:
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=

json5@^2.1.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.0.tgz#2dfefe720c6ba525d9ebd909950f0515316c89a3"
integrity sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==
dependencies:
minimist "^1.2.5"

json5@^2.1.2:
version "2.1.3"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.1.3.tgz#c9b0f7fa9233bfe5807fe66fcf3a5617ed597d43"
Expand Down