javascriptangularjstranslationangular-translate

Translating text within controller with AngularJs


Im using angular translate and need to translate some words in the controller. Im using json files for translation in the html.

// LABELS
var monthNames = [
    "Janvier", "Février", "Mars",
    "Avril", "Mai", "Juin", "Juillet",
    "Août", "Septembre", "Octobre",
    "Novembre", "Décembre"
];
//some code here
title: {
    display: true,
    text: 'Commandes'
}

Solution

  • Inject $filter service in your controller and then you are free to use itwith any service ( in this example with the translate service )

    const translation = $filter('translate')('HELLO_WORLD'); // HELLO_WORLD is the definition from the translation json file