optimize language resource loading
This commit is contained in:
parent
7d659562d8
commit
d9ca568b9f
|
@ -39,7 +39,6 @@
|
|||
"angular-cookies": "1.4.10",
|
||||
"angular-animate": "1.4.10",
|
||||
"angular-translate": "^2.11.0",
|
||||
"angular-translate-loader-static-files": "^2.11.0",
|
||||
"angular-moment": "1.0.0-beta.6",
|
||||
"angular-websocket": "^1.1.0",
|
||||
"angular-utf8-base64": "^0.0.5",
|
||||
|
|
|
@ -271,7 +271,6 @@
|
|||
<script src="../bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
|
||||
<script src="../bower_components/sweetalert/dist/sweetalert.min.js"></script>
|
||||
<script src="../bower_components/angular-translate/angular-translate.min.js"></script>
|
||||
<script src="../bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.min.js"></script>
|
||||
<script src="../bower_components/angular-moment/angular-moment.min.js"></script>
|
||||
<script src="../bower_components/angular-websocket/angular-websocket.min.js"></script>
|
||||
<script src="../bower_components/angular-utf8-base64/angular-utf8-base64.min.js"></script>
|
||||
|
@ -322,6 +321,7 @@
|
|||
<script src="scripts/filters/volumn.js"></script>
|
||||
<script src="scripts/services/ariaNgCommonService.js"></script>
|
||||
<script src="scripts/services/ariaNgFileService.js"></script>
|
||||
<script src="scripts/services/ariaNgLanguageLoader.js"></script>
|
||||
<script src="scripts/services/ariaNgMonitorService.js"></script>
|
||||
<script src="scripts/services/ariaNgNotificationService.js"></script>
|
||||
<script src="scripts/services/ariaNgSettingService.js"></script>
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
{
|
||||
"Simplified Chinese": "简体中文",
|
||||
"Operation Succeeded": "操作成功",
|
||||
"Connection Succeeded": "连接成功",
|
||||
"Error": "错误",
|
||||
|
|
|
@ -7,12 +7,10 @@
|
|||
.setStorageType('localStorage')
|
||||
.setStorageCookie(365, '/');
|
||||
|
||||
$translateProvider.useStaticFilesLoader({
|
||||
prefix: 'langs/',
|
||||
suffix: '.json'
|
||||
}).useLoaderCache(true)
|
||||
.preferredLanguage('en')
|
||||
.fallbackLanguage('en')
|
||||
$translateProvider.useLoader('ariaNgLanguageLoader')
|
||||
.useLoaderCache(true)
|
||||
.preferredLanguage(ariaNgConstants.defaultLanguage)
|
||||
.fallbackLanguage(ariaNgConstants.defaultLanguage)
|
||||
.useSanitizeValueStrategy('escapeParameters');
|
||||
|
||||
NotificationProvider.setOptions({
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
title: 'AriaNg',
|
||||
appPrefix: 'AriaNg',
|
||||
optionStorageKey: 'Options',
|
||||
languageStorageKeyPrefix: 'Language',
|
||||
languagePath: '/langs',
|
||||
languageFileExtension: '.json',
|
||||
defaultLanguage: 'en',
|
||||
globalStatStorageCapacity: 120,
|
||||
taskStatStorageCapacity: 300,
|
||||
lazySaveTimeout: 500,
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').config(['$translateProvider', function ($translateProvider) {
|
||||
$translateProvider.translations('en', {
|
||||
'English': 'English',
|
||||
angular.module('ariaNg').config(['$translateProvider', 'ariaNgConstants', function ($translateProvider, ariaNgConstants) {
|
||||
var defaultLanguageResource = {
|
||||
'Operation Succeeded': 'Operation Succeeded',
|
||||
'Connection Succeeded': 'Connection Succeeded',
|
||||
'Error': 'Error',
|
||||
|
@ -106,7 +105,7 @@
|
|||
'Manual Download': 'Manual Download',
|
||||
'Support multiple URLs, one URL per line.': 'Support multiple URLs, one URL per line.',
|
||||
'Your browser does not support loading file!': 'Your browser does not support loading file!',
|
||||
'The selected file type is invalid': 'The selected file type is invalid',
|
||||
'The selected file type is invalid!': 'The selected file type is invalid!',
|
||||
'Failed to load file!': 'Failed to load file!',
|
||||
'Download Completed': 'Download Completed',
|
||||
'BT Download Completed': 'BT Download Completed',
|
||||
|
@ -520,6 +519,8 @@
|
|||
'truncate-console-readout.name': 'Truncate Console Output',
|
||||
'truncate-console-readout.description': 'Truncate console readout to fit in a single line.'
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$translateProvider.translations(ariaNgConstants.defaultLanguage, defaultLanguageResource);
|
||||
}])
|
||||
})();
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
|
||||
angular.module('ariaNg').constant('ariaNgLanguages', {
|
||||
'en': {
|
||||
name: 'English'
|
||||
name: 'English',
|
||||
displayName: 'English'
|
||||
},
|
||||
'zh_CN': {
|
||||
name: 'Simplified Chinese'
|
||||
name: 'Simplified Chinese',
|
||||
displayName: '简体中文'
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
35
src/scripts/services/ariaNgLanguageLoader.js
Normal file
35
src/scripts/services/ariaNgLanguageLoader.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
angular.module('ariaNg').factory('ariaNgLanguageLoader', ['$http', '$q', 'localStorageService', 'ariaNgConstants', 'ariaNgLanguages', function ($http, $q, localStorageService, ariaNgConstants, ariaNgLanguages) {
|
||||
return function (options) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
if (!ariaNgLanguages[options.key]) {
|
||||
deferred.reject(options.key);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
var languageKey = ariaNgConstants.languageStorageKeyPrefix + '.' + options.key;
|
||||
var languageResource = localStorageService.get(languageKey);
|
||||
|
||||
if (languageResource) {
|
||||
deferred.resolve(languageResource);
|
||||
}
|
||||
|
||||
var languagePath = ariaNgConstants.languagePath + '/' + options.key + ariaNgConstants.languageFileExtension;
|
||||
|
||||
$http({
|
||||
url: languagePath,
|
||||
method: 'GET'
|
||||
}).success(function (data) {
|
||||
localStorageService.set(languageKey, data);
|
||||
return deferred.resolve(data);
|
||||
}).error(function (data) {
|
||||
return deferred.reject(options.key);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
}]);
|
||||
})();
|
|
@ -6,7 +6,7 @@
|
|||
</div>
|
||||
<div class="setting-value col-sm-8">
|
||||
<select class="form-control" style="width: 100%;" ng-model="context.settings.language"
|
||||
ng-options="type as (language.name | translate) for (type, language) in context.languages"
|
||||
ng-options="type as language.displayName for (type, language) in context.languages"
|
||||
ng-change="settingService.setLanguage(context.settings.language)">
|
||||
</select>
|
||||
</div>
|
||||
|
|
Reference in a new issue