How can I change the language url in runtime using angular 7?
How can I change the language url in runtime using angular 7?

Hi all,
I am currently building a data table using angular 7, and I want to have a dropdown menu to switch different languages for the internationalization support. To my understanding, the dtoption has a language.url option which can specify which language to use. I have no problem to set the default language during the table initialization. However, I don't know how how to make it work after I change the url option to a different language file when the event of of switching the lang is triggered. Any help or working examples will be appreciated. Thanks.
Answers
Hi @Marcusshaocong ,
That's an initialisation option, so you would need to destroy the table (
destroy()
) and recreate it (you can usedestroy
here) with the new URL,Cheers,
Colin
Hi Colin,
Thanks for the quick reply. What I wanted to do is to change the dtOptions' language.url to point to a different language file when the langChange event is trigger.
I have tried use the
destroy()
and then thedraw()
to re-render the table, however it does not take effect. Do you know how to do it correctly? I think my point is change the dtOptions' language setting after the table has been initialized, looks like thedestroy()
anddraw()
did not do the trick.Hi @Marcusshaocong ,
Yep, once you've called
destroy()
, you'll need to reinitialise the table with new setting. I see you're callingdtInstance.init()
but that code isn't there.We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi @colin,
Can you roughly tell me what is the potential interface or api to reinitialise the table with new setting in this case?
I am using angular 7 and a lot of third party modules, I am not sure if I can fully replicate the same test case here, it might take me a lot of time to do that. Very much appreciated for your help. Thanks.
Hi @Marcusshaocong ,
It would be the same as the original initialisation - just with the URL path. You could even just add
destroy
as I mentioned above, so you wouldn't need to calldestroy
, something like this.Cheers,
Colin