Answer the question
In order to leave comments, you need to log in
`
AngularJS, controllers and models can't see?
i`m need to create multi language Client Side Application, can you help me with my problem.
I have files
index.html
<!DOCTYPE html>
<html ng-app="app" ng-controller="Language as lang">
<head>...</head>
<body>
<div>{{lang.translation.GameName}}</div>
<script type="text/javascript" src="/js/less.min.js"></script>
<script type="text/javascript" src="/js/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/main.js"></script>
</body>
</html>
services.ang.js
app.service('TranslateSRV', '$scope', '$http', function($scope){
$scope.translateText = function($scope, $http, language){
$http.get('../json/language.json').then(function(data){
return data.data[language];
});
};
});
controllers.ang.js
app.controller('Language', 'TranslateSRV', function(TranslateSRV){
this.language = 'en';
this.translation = {};
this.translate = function() {
this.translation = TranslateSRV.translateText($scope, $http,this.language);
};
this.translate();
});
language.json
{
"ua":{
"GameName":"Правда або дія",
"ChoseLang":"Оберіть мову гри"
},
"ru":{
"GameName":"Правда или действие",
"ChoseLang":"Выберите язык игры"
},
"en":{
"GameName":"Truth or Dare",
"ChoseLang":"Please choose game language"
}
}
Errors
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question