Tuesday, October 10, 2017

Angualr JS translate not working properly inside Visualforce page

I need to translate my html into different languages based on user preference. For that I am using Angular JS translate method. The example when I write inside notepad and saved as “.html” is working fine. But when I pasted the same code inside my Salesforce Visualforce page, its behaviour changes.ie. When I click on button”IT” to translate the content to “Italics” the contents are translating to Italics but within seconds the contents are again going back to their Prefered language “EN”. I have given below my screenshot of output.

enter image description here

I have given below my code, can anyone say what’s wrong in this.

 <!DOCTYPE html>
 <html ng-app="app">
 <head>
 </head>
 <body>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
 <script src="https://cdn.rawgit.com/angular-translate/bower-angular-translate/2.5.2/angular-translate.js"></script>
 <script>
 // Code goes here
 var app = angular.module('app', ['pascalprecht.translate']);

 app.config(['$translateProvider',
 function($translateProvider) {

 $translateProvider.translations('it', {
  'Purchase order': "Ordine di acquisto ",
  'Number:': "Numero:",
  'Customer data': "Dati Cliente",
  'Surname / Company':"Cognome/Società",
  'Name':"Nome",
  'Piazza way':"Via/Piazza",
  'City':"Città",
  'VAT tax code':"Codice Fiscale/Partita IVA",
  'Phone':"Telefono",
  'E-Mail':"E-Mail",
  'CAP':"CAP"


});
$translateProvider.preferredLanguage("en");
 }
]);

app.controller('AppController', function ($translate) {
// this.browser = navigator.userAgent;
 this.useLang = function (lang) {
$translate.use(lang);
}
});
</script>


 <div ng-controller="AppController as app">
 <h3 translate>     Purchase order </h3>
 <p translate>Number:</p>
 <h3 translate>Customer data</h3>
 <p><span translate>Surname / Company</span>_________</p>
 <p> <span translate>Name</span>__________</p>
 <p><span translate>Piazza way</span>____________</p>
 <p><span translate>CAP</span>_______<span translate>City</span>______</p>
 <p><span translate>VAT tax code</span>__________</p>
 <p><span translate>Phone</span>____________</p>
 <p><span translate>E-Mail</span>_________</p>

 <button ng-click="app.useLang('it')">IT</button>
 <button ng-click="app.useLang('en')">EN</button>

 </div>
 </body>
 </html>

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/10/10/angualr-js-translate-not-working-properly-inside-visualforce-page/
via @lzomedia #developer #freelance #web #lzomedia.com

No comments:

Post a Comment