-
Notifications
You must be signed in to change notification settings - Fork 6.8k
MdPaginatorIntl Internationalization example #5573
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
Comments
Please keep GitHub issues for bug reports / feature requests. Better avenues for troubleshooting / questions are stack overflow, gitter, mailing list, etc. |
Although this is not explicitly mentioned in the docs, you can infer the purpose of When the docs say you must provide your own instance, it means extending the |
Try in oninit this: |
Okay I solved this by using each of your solutions ;)
|
|
@Laurensvdw, actually @CaerusKaru is right but in your defence I can say you just couldn't implement it properly since |
Okay that explains why I couldn't get it working with the documentation @CaerusKaru mentioned earlier about DI, as the |
Ah, now that is a bug. I sent #5726 to fix. |
I'm still unclear as to the process for this. what I understand; and please correct me wherever I'm wrong
what else? thank you in advanced |
@Lior-G see https://plnkr.co/edit/Zy0kOh78CBelkBH8VEug?p=preview. I don't know if that's the best way to do it, but it works |
@willshowell |
@Lior-G The Plunkr uses the latest build from the master branch (generally a couple of commits behind the latest commit). MdPaginatorIntl is exposed as of #5716. You can have your project rely on the latest build by following Step 1 in the Getting Started guide, just run: |
Hi, MdPaginatorIntl is exported as ex on (@angular/material/typings/index.d.ts) you can import this class like this:
And after:
//MyClassIntl
|
The cool example that @diarcastro provide unfortunately is not working on beta.10 seems that /typings/index.d.ts in beta.10 has't |
The documentation to do this is really poor. Anybody with an example for creating your own class with internationalization using for example ngx-translate? Something DYNAMIC ??? |
+1 to an example how to make this DYNAMIC!!! We use ngx-translate and cannot make this single line of the table dynamic... |
@mhosman @rsaulo This is how I did it in Create separate file e.g. custom-mat-paginator-int.ts:
Load and include it in providers in app.module.ts
|
@rivoheinsalu , yes, i ended with the same solution, thanks for the reply! |
Hey @rivoheinsalu, thanks for sharing. The only problem about this is that it keeps saying for example 1 of 2. How can I change the "of"? |
@mhosman I have edited my example, see getRangeLabel. I have not tried it with 'of', insted changed it to '/'. You could try to set private properti and assing value in translation part: And then try to use it in getRangeLabel(). Unfortunately I cannot currently test it. |
Great @rivoheinsalu !! Thank you very much for your help! |
Sorry I have just one last problem... I have another component with preferences. In that component I change the language. Then, I just go back to the component with the paginator and the language is not being changed (just in the paginator, in the rest of the site is working ok). The onLangChange is not working or maybe because I change the language in other component, the onLangChange is not being fired... so... the only way is to create a custom observable?? |
@mhosman did you include following to providers in global (app.module.ts) as I told not in component?
For me it works well when changing language in one component and then navigating to component with table. Second Try debugging or console logging in CustomMatPaginatorIntl and see if second |
Yes @rivoheinsalu all setup it's okay. Paginator is working okay and current language it's okay. The only problem is with onLangChange. It's not being fired (I also put a console.log inside and nothing). Important: all the rest of the site is changing the language okay, the only problem is with the onLangChange inside this CustomMatPaginatorIntl. |
In my table I only added the following in the ngOnInit(): ngOnInit() { |
@dani3lrp how an I translate "1 of 10" ? |
@rivoheinsalu I got No provider for TranslateService! with your solution |
@duard Have you properly setup ngx-translate module importing TranslateModule.forRoot()? |
Extending on @rivoheinsalu his answer (with 'OF' translation & unsubscribing from translate)
Everything else is exactly the same as specified in Rivo's answer |
Here is my test file for the code above. If you like to have code coverage 💯 :
|
@AnimaWolf in my case ngOnDestroy never get called, have you tested your implementation of OnDestroy? |
Are they joking with this??? Refactor. Provide simple inputs. Please. |
WoW- I just found one of the ugliest sides of angular material... |
The subscription to `
` |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
The new paginator has a small text in the documentation about Internationalization. I was wondering if anyone has an example of doing this. The document states that you can do this by "providing your own instance of MdPaginatorIntl". I have no idea how to do this... Thanks!
The text was updated successfully, but these errors were encountered: