Just starting out with angular and feeling a bit lost...
I want to be able to load different JSON files for data based on the language selected (e.g. json/Agenda-nl.json).
Currently, I have separate controller and HTML files for each language. Is there a way to dynamically load them, possibly using the angular-translate module?
Thanks in advance for any assistance!
var App = angular.module('App', ['pascalprecht.translate']);
App.config(function($translateProvider) {
$translateProvider.translations('fr', {
TYPE: 'Type',
BUTTON_TEXT_FR: 'Français',
BUTTON_TEXT_NL: 'Nederlands'
})
.translations('nl', {
TYPE: 'Type',
BUTTON_TEXT_FR: 'Français',
BUTTON_TEXT_NL: 'Nederlands'
});
$translateProvider.preferredLanguage('fr');
});
App.controller('TranslateController', function($translate, $scope) {
$scope.changeLanguage = function (langKey) {
$translate.use(langKey);
};
});
App.controller('AgendaListCtrl', ['$scope', '$http',
function ($scope, $http) {
$http.get('json/Agenda-nl.json').success(function(data) {
$scope.courses = data;
});
$http.get('json/language.json').success(function(language) {
$scope.language = language;
});
$http.get('load.php').success(function(loaded) {
$scope.load = loaded;
});
$scope.selectModel = '1';
$scope.hover = function(course) {
// Shows/hides the enroll button on hover
return course.showOverlay = ! course.showOverlay;
};
// create a blank object to hold our form information
// $scope will allow this to pass between controller and view
$scope.formData = {};
// process the form
$scope.processForm = function() {
console.log("Submitting Form");
$scope.formData
$http({
url : 'insert.php',
method : 'POST',
data : $.param($scope.formData),
headers : { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
})
.success(function(data) {
console.log(data);
if (!data.success) {
$scope.errormessage = data.errors.message;
console.log(data.errors.message);
} else {
$scope.message = data.message;
console.log(data.message);
}
});
};
}
]);