I'm using angular-datatables(based on jquery-datatables), reading language from Json files. It's not hard to switch datatables language through something like $scope.dtOptions.language.url = '../locales/dt/'+ lng +'.json';
but once the page refreshes, it will go back to default language. Is there any way to save language.url in cookie, and then tell datatables to read language option from cookie?
Asked
Active
Viewed 266 times
0

vincentf
- 1,419
- 2
- 20
- 36
1 Answers
0
You could better use localStorage for that. I has 2 benefits - 1) size not limited to 4kb, but starts from 5mb; 2) not being sent over the wire to server and back every request. More on comparison here Local Storage vs Cookies The browser api is straightforward:
localStorage.setItem('datatablesLang', 'en');
localStorage.getItem('datatablesLang'); // =='en'
More details on the browser API here: https://developer.mozilla.org/en-US/docs/Web/API/Storage/LocalStorage
Besides that there's a good angular module: angular-local-storage that can do even more.
-
Thanks for your suggestion – vincentf Feb 29 '16 at 00:53