12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 'use strict';
- define(['underscore', '../../app/nls/StringResources', '../../lib/@waca/core-client/js/core-client/utils/Lexicon'], function (_, DashboardStringResources, Lexicon) {
- var _stringService = {
-
- init: function init() /*options*/{
- this.polys = [{
- priority: 100,
- resource: DashboardStringResources
- }];
- },
-
- register: function register(stringResource, priority) {
- var newPoly = {
- priority: priority,
- resource: stringResource
- };
- if (_.find(this.polys, function (poly) {
- return poly.priority === priority && poly.resource === stringResource;
- })) {
-
- return;
- }
- var newIndex = _.sortedIndex(this.polys, newPoly, 'priority');
- this.polys.splice(newIndex, 0, newPoly);
- },
-
- get: function get(key, interpolationOptions) {
- var msg = key;
- for (var i = 0; i < this.polys.length; i++) {
- msg = this.polys[i].resource.get(key, interpolationOptions);
- if (key != msg && msg.indexOf(Lexicon.NOT_TRANSLATED) !== 0) {
- break;
- }
- }
- return msg;
- },
- destroy: function destroy() {
- this.polys = null;
- }
- };
- function StringService(options) {
- this.init(options);
- }
- Object.keys(_stringService).forEach(function (key) {
- StringService.prototype[key] = _stringService[key];
- });
- return StringService;
- });
|