12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', '../../app/nls/StringResources', '../../lib/@waca/core-client/js/core-client/utils/Lexicon'], function (_, DashboardStringResources, Lexicon) {
- var _stringService = {
- /**
- * @param {object} options
- */
- init: function init() /*options*/{
- this.polys = [{
- priority: 100,
- resource: DashboardStringResources
- }];
- },
- /**
- * Register a new StringResource bundle.
- *
- * @param {object} stringResource The StringResource to register. Must implement a get(key, interpolationOptions)
- * function which returns the key if the resource was not found
- * @param {number} priority Priority (number) given to this new resource, lower priority is more important.
- * Default resource has priority 100.
- */
- register: function register(stringResource, priority) {
- var newPoly = {
- priority: priority,
- resource: stringResource
- };
- if (_.find(this.polys, function (poly) {
- return poly.priority === priority && poly.resource === stringResource;
- })) {
- // We allow duplicate priorities and duplicate resources. Just not both.
- return;
- }
- var newIndex = _.sortedIndex(this.polys, newPoly, 'priority');
- this.polys.splice(newIndex, 0, newPoly);
- },
- /**
- * Get the string resource for the given key and interpolation options. Checks the Storytelling resources first and if
- * not found it checks the Dashboard resources.
- *
- * @param {string} key The key of the string to return
- * @param {object} interpolationOptions Optional interpolation options (see poly.t documentation for details)
- * @returns {string} The string to display
- */
- 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;
- });
- //# sourceMappingURL=DashboardStringService.js.map
|