harbor/static/resources/js/services/i18n/services.i18n.js

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-05-13 12:48:06 +02:00
(function() {
'use strict';
angular
.module('harbor.services.i18n')
.factory('I18nService', I18nService);
2016-05-14 07:34:54 +02:00
I18nService.$inject = ['$cookies', '$window'];
2016-05-13 12:48:06 +02:00
2016-05-14 07:34:54 +02:00
function I18nService($cookies, $window) {
var cookieOptions = {'path': '/'};
var messages = $.extend(true, {}, eval('locale_messages'));
2016-06-22 13:56:21 +02:00
var defaultLanguage = 'en-US';
var supportLanguages = {
2016-05-13 12:48:06 +02:00
'en-US': 'English',
'zh-CN': '中文'
};
var isSupportLanguage = function(language) {
for (var i in supportLanguages) {
if(language === String(i)) {
return true;
}
}
return false;
2016-05-23 12:29:17 +02:00
};
2016-05-13 12:48:06 +02:00
return tr;
function tr() {
2016-05-23 12:29:17 +02:00
2016-05-13 12:48:06 +02:00
return {
'setCurrentLanguage': function(language) {
if(!angular.isDefined(language) || !isSupportLanguage(language)) {
2016-05-13 12:48:06 +02:00
language = defaultLanguage;
}
$cookies.put('language', language, cookieOptions);
},
'setDefaultLanguage': function() {
$cookies.put('language', defaultLanguage, cookieOptions);
2016-05-13 12:48:06 +02:00
},
'getCurrentLanguage': function() {
return $cookies.get('language') || defaultLanguage;
},
'getLanguageName': function(language) {
if(!angular.isDefined(language) || !isSupportLanguage(language)) {
language = defaultLanguage;
}
2016-06-22 13:56:21 +02:00
$cookies.put('language', language, cookieOptions);
return supportLanguages[language];
},
'getSupportLanguages': function() {
return supportLanguages;
},
'unset': function(){
$cookies.put('language', defaultLanguage, cookieOptions);
2016-05-13 12:48:06 +02:00
},
'getValue': function(key) {
return messages[key];
2016-05-13 12:48:06 +02:00
}
2016-05-23 12:29:17 +02:00
};
2016-05-13 12:48:06 +02:00
}
}
})();