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