0

need translate data from database using ng2-translate in angular without using JSON file or can we translate text using ng2-translate..

I tried by following code to translate text this.translate.get("SPANISH") .subscribe((data: string) => { this.value= data; });

Please guide me ..

1 Answers1

0

You should create a custom translation loader: https://www.npmjs.com/package/ng2-translate#write--use-your-own-loader

That also means all translations will be loaded at once. But if there is a lot of data to translate, it's better to use other approach to translate the data (for example - pass the desired language in the URL ?lang=en and return the data translated already).

MaxXx1313
  • 610
  • 5
  • 15
  • in which url need to translate ?can you give some example plz. – Susmitha Elangovan Nov 30 '21 at 09:26
  • It's not clear from the question which issue exactly we should solve. So far I have 2 assumptions: 1st - keep translation data in database instead of json file. 2nd - have user data translated into a multiple languages. Could you give more details please? – MaxXx1313 Nov 30 '21 at 09:43
  • i try to add my site with multiple langauage(spanish,english)..in my site i am having multiple pages,in that most of the grid values are loaded from the databases .how can i convert those things into other langauage.. – Susmitha Elangovan Nov 30 '21 at 09:47
  • Do you expect to translate the data automatically, like the GoogleTranslate service does? – MaxXx1313 Nov 30 '21 at 09:54
  • yes,looking to translate the data automatically when page loads – Susmitha Elangovan Nov 30 '21 at 09:57
  • FYI I also tried google translate api service in that i faced lots of issue like (button events are not working after translate) – Susmitha Elangovan Nov 30 '21 at 10:00
  • 'ng2-translate' is working with multi-language data which should be translated in advance. – MaxXx1313 Nov 30 '21 at 10:12
  • now i am using that,can you please guide me to proceed futhur,i almost complete all static pages by created json files,but for dynamic pages? – Susmitha Elangovan Nov 30 '21 at 10:16