Liferay.Loader.define("portal-search-ranking-web@2.0.50/js/utils/language.es", ['module', 'exports', 'require'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.getPluralMessage = getPluralMessage;
    exports.sub = sub;

    /**
     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
     *
     * The contents of this file are subject to the terms of the Liferay Enterprise
     * Subscription License ("License"). You may not use this file except in
     * compliance with the License. You can obtain a copy of the License by
     * contacting Liferay, Inc. See the License for the specific language governing
     * permissions and limitations under the License, including but not limited to
     * distribution rights of the Software.
     */
    var SPLIT_REGEX = /({\d+})/g;
    /**
     * Uses the singular language key if the count is 1. Otherwise uses the plural
     * language key.
     * @param {string} singular The language key in singular form.
     * @param {string} plural The language key in plural form.
     * @param {number} count The amount to display in the message.
     * @param {boolean} toString If the message should be converted to a string.
     * @return {(string|Array)} The translated message.
     */

    function getPluralMessage(singular, plural) {
      var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
      var toString = arguments.length > 3 ? arguments[3] : undefined;
      var message = count === 1 ? singular : plural;
      return sub(message, [count], toString);
    }
    /**
     * Utility function for substituting variables into language keys.
     *
     * Examples:
     * sub(Liferay.Language.get('search-x'), ['all'])
     * => 'search all'
     * sub(Liferay.Language.get('search-x'), [<b>all<b>], false)
     * => 'search <b>all</b>'
     *
     * @param {string} langKey This is the language key used from our properties file
     * @param {string} args Arguments to pass into language key
     * @param {string} join Boolean used to indicate whether to call `.join()` on
     * the array before it is returned. Use `false` if subbing in JSX.
     * @return {(string|Array)}
     */

    function sub(langKey, args) {
      var join = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
      var keyArray = langKey.split(SPLIT_REGEX).filter(function (val) {
        return val.length !== 0;
      });

      for (var i = 0; i < args.length; i++) {
        var arg = args[i];
        var indexKey = "{".concat(i, "}");
        var argIndex = keyArray.indexOf(indexKey);

        while (argIndex >= 0) {
          keyArray.splice(argIndex, 1, arg);
          argIndex = keyArray.indexOf(indexKey);
        }
      }

      return join ? keyArray.join('') : keyArray;
    }
    //# sourceMappingURL=language.es.js.map
  }
});
//# sourceMappingURL=language.es.js.map