Shilpa
Published in : 2022-03-03
I am using latest ANGULAR 13 version and want to translate all the text written on my landing page to be translated in different languages chosen by readers.
I want support of French, German, and English (UK).
Here is my code sample,
Library: free translate from NPM
npm i free-translate
const { translate } = require('free-translate');(async () => { const translatedText = await translate('Hello World', { from: 'en', to: 'ja' }); console.log(translatedText); // こんにちは世界})();
But this is not much accurate, All translators are not 100% accurate because of grammar and masculine/feminine translations, but if I can achieve at least 95%, I am good with it!
I have around 780-800 lines on the page. How do I convert the lines automatically or manually and show on base of user's language selection?
Join our community and get the chance to solve your code issues & share your opinion with us
Sign up Now
Rakshit Date : 2022-03-05
Best answers
34
Best answers
34
I believe ngx-translate library will make your work easy. Online translators are not 100% accurate. I recommend one thing, If you want to convert your text to Spanish, contact someone who speaks spanish, german, french (any of them) or find a freelancer translator to convert your text. They knows feminine vs masculine version of items.
Add npm package to your project using below command.
Update your app.module.ts imports with below lines,
Add below code to your app.component.ts
Add below code to Your app.component.html
Add a new file Inside your assets/i18n/en.json
Update your html markup as given below:
Your output:
To learn and explore this library more, you can visit here.
Reference: website | github | npm
Shilpa Date : 2022-03-06
Best answers
10
Best answers
10
Such a amazing explanation , I will try it for sure. Thank you.