translation system implemented

This commit is contained in:
idoctnef
2016-09-25 14:48:10 +02:00
parent fb545e0c67
commit e9f1ff6e39
68 changed files with 49488 additions and 120 deletions

View File

@@ -4,7 +4,9 @@
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'starter.controllers'])
angular.module('starter', ['ionic',
'starter.controllers',
'pascalprecht.translate'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
@@ -36,7 +38,8 @@ angular.module('starter', ['ionic', 'starter.controllers'])
url: '/settings',
views: {
'menuContent': {
templateUrl: 'templates/settings.html'
templateUrl: 'templates/settings.html',
controller: 'SettingsCtrl'
}
}
})
@@ -80,4 +83,24 @@ angular.module('starter', ['ionic', 'starter.controllers'])
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/travels');
});
})
/* translator */
.config(['$translateProvider',function($translateProvider) {
/* get lang from the file translations.js */
for(lang in translations){
$translateProvider.translations(lang, translations[lang]);
}
if(window.localStorage.getItem('lang')) {
$translateProvider.preferredLanguage(window.localStorage.getItem('lang'));
}else{
$translateProvider.preferredLanguage('english');
};
$translateProvider.useSanitizeValueStrategy('escape');
}]);

View File

@@ -7,7 +7,7 @@ var urlapi="http://localhost:3000/api/";
//localStorage.setItem("c_token", "");
angular.module('starter.controllers', [])
angular.module('starter.controllers', ['pascalprecht.translate'])
.controller('AppCtrl', function($scope, $ionicModal, $timeout, $http, $window) {
// With the new view caching in Ionic, Controllers are only called
@@ -146,6 +146,8 @@ angular.module('starter.controllers', [])
.error(function(data, status, headers,config){
console.log('data error');
$scope.$broadcast('scroll.refreshComplete');//refresher stop
$ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 });
})
.then(function(result){
travels = result.data;
@@ -330,6 +332,8 @@ angular.module('starter.controllers', [])
console.log('data success');
console.log(data); // for browser console
$scope.travel = data; // for UI
console.log("b");
console.log($scope.travel);
})
.error(function(data, status, headers,config){
console.log('data error');
@@ -468,6 +472,9 @@ console.log($scope.newComment);
});
$scope.closeNewComment();
};
console.log("a");
console.log($scope.storageusername);
console.log($scope.travel.owner);
$scope.arrayObjectIndexOf = function(myArray, searchTerm, property) {
@@ -537,4 +544,18 @@ console.log($scope.newComment);
.then(function(result){
travels = result.data;
});
}).controller('SettingsCtrl', function($scope, $stateParams, $translate) {
if(localStorage.getItem('lang'))//initialization
{
$scope.lang=localStorage.getItem('lang');
}else{
localStorage.setItem('lang', 'english');
$scope.lang=localStorage.getItem('lang');
}
$scope.langChange = function(lang){
console.log(lang);
window.localStorage.setItem('lang', lang);
$translate.use(lang);
};
});

64
www/js/translations.js Normal file
View File

@@ -0,0 +1,64 @@
var translations = {
"english": {
"Actual_language": "Actual language: ",
"Menu": "Menu",
"Signup": "Signup",
"Login": "Login",
"Travels": "Travels",
"Users": "Users",
"Logout": "Logout",
"Settings": "Settings",
"Login": "Login",
"Username": "Username",
"Password": "Password",
"Mail": "Mail",
"Phone": "Phone",
"Telegram": "Telegram",
"Avatar": "Avatar",
"Close": "Close",
"New_Asking_Package": "New Asking Package",
"New_Asking_Travel": "New Asking Travel",
"New_Travel": "New Travel",
"Title": "Title",
"From": "From",
"To": "To",
"n_People": "nºPeople",
"n_Seats": "nºSeats",
"Date": "Date",
"Hour": "Hour",
"Phone_contact": "Phone contact",
"Telegram_user": "Telegram user",
"Need_to_carry_package": "Need to carry package",
"Can_carry_package": "Can carry package",
"Collectivized_car": "Collectivized car",
"Collectivized": "Collectivized",
"Description": "Description",
"Cancel": "Cancel",
"Create_asking_package": "Create asking package",
"Create_asking_travel": "Create asking travel",
"Create_travel": "Create travel",
"Travel": "Travel",
"Joined_users": "Joined users",
"Comments": "Comments",
"Ask_to_join": "Ask to join",
"Offer_car": "Offer car",
"Unjoin": "Unjoin",
"Unoffer_car": "Unoffer car",
"New_comment": "New comment",
"Post_comment": "Post comment",
"Pull_to_refresh": "Pull to refresh",
"search": "search",
"No_data_in_memory": "No data in memory",
"Pull_from_top_to_refresh": "Pull from top to refresh",
"User": "User",
"history_of": "history of",
"publications": "publications",
},
"catala": {
"Actual_language": "Idioma actual: ",
"Menu": "Menu",
"Settings": "Opcions"
}
};