Name

global.CreateUXTranslations

Description

Creates the required translation from the strings passed to translation functions

Script

var CreateUXTranslations = Class.create();
CreateUXTranslations.prototype = {
  initialize: function() {},

  stripEndQuotes: function(str) {
      if (
          (str.charAt(0) === '"' && str.charAt(str.length - 1) === '"') ||
          (str.charAt(0) === "'" && str.charAt(str.length - 1) === "'")
      ) {
          return str.substr(1, str.length - 2);
      }
  },

  getRequiredTranslations: function(script, type) {
      var isClientTransformScript = typeof type !== 'undefined' && type.toString() === "transform" ? true : false;
      var functionRegex = isClientTransformScript ? /helpers.translateSync\((.*?)\)/g : /helpers.translate\((.*?)\)/g;
      var translations = [];
      while ((match = functionRegex.exec(script)) !== null) {
          var firstArg = match[1].split(',').map(function(arg) {
              return arg.trim();
          })[0];
          translations.push({
              message: this.stripEndQuotes(firstArg)
          });
      }
      return translations;
  },

  type: 'CreateUXTranslations'
};

Sys ID

d205af87050ae510f877765300c33ce4

Offical Documentation

Official Docs: