Last active
August 29, 2015 14:10
-
-
Save canujohann/65f2dfcfa70b0ff2c4b0 to your computer and use it in GitHub Desktop.
load-languages-files-angular.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var module = angular.module("myapp", []).config(["$locationProvider", function($locationProvider) { | |
$locationProvider.html5Mode(true); | |
}]); | |
module.controller("mycontroller", function($scope, $http,$location) { | |
// Authorized languages | |
var languages = ['en','ja','fr']; | |
var default_lang = 'ja'; | |
// Get translations according to the 'lang' parameter | |
// Default language is japanese | |
var lang = $location.search()['lang'] || default_lang ; | |
//if not in array, default value | |
if(languages.indexOf(lang) < 0) lang = default_lang ; | |
//get translation | |
$http.get(lang+'.json').success (function(data){ | |
$scope.users = data; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment