mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-05 00:23:33 +01:00
61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
(function() {
|
|
|
|
'use strict';
|
|
|
|
angular
|
|
.module('harbor.services.i18n')
|
|
.factory('I18nService', I18nService);
|
|
|
|
I18nService.$inject = ['$cookies', '$window'];
|
|
|
|
function I18nService($cookies, $window) {
|
|
var cookieOptions = {'path': '/'};
|
|
var messages = $.extend(true, {}, eval('locale_messages'));
|
|
var defaultLanguage = navigator.language || 'en-US';
|
|
var supportLanguages = {
|
|
'en-US': 'English',
|
|
'zh-CN': '中文'
|
|
};
|
|
var isSupportLanguage = function(language) {
|
|
for (var i in supportLanguages) {
|
|
if(language === i) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
return tr;
|
|
function tr() {
|
|
|
|
return {
|
|
'setCurrentLanguage': function(language) {
|
|
if(!angular.isDefined(language) || !isSupportLanguage(language)) {
|
|
language = defaultLanguage;
|
|
}
|
|
$cookies.put('language', language, cookieOptions);
|
|
},
|
|
'setDefaultLanguage': function() {
|
|
$cookies.put('language', defaultLanguage, cookieOptions);
|
|
},
|
|
'getCurrentLanguage': function() {
|
|
return $cookies.get('language') || defaultLanguage;
|
|
},
|
|
'getLanguageName': function(language) {
|
|
if(!angular.isDefined(language) || !isSupportLanguage(language)) {
|
|
language = defaultLanguage;
|
|
}
|
|
return supportLanguages[language];
|
|
},
|
|
'unset': function(){
|
|
$cookies.put('language', defaultLanguage, cookieOptions);
|
|
},
|
|
'getValue': function(key) {
|
|
return messages[key];
|
|
}
|
|
};
|
|
|
|
}
|
|
}
|
|
|
|
})(); |