original_string: public function string_for_js($identifier, $component, $a = null) {
          if (!$component) {
              throw new coding_exception('The $component parameter is required for page_requirements_manager::string_for_js().');
          }
          if (isset($this->stringsforjs_as[$component][$identifier]) and $this->stringsforjs_as[$component][$identifier] !== $a) {
              throw new coding_exception("Attempt to re-define already required string '$identifier' " .
                      "from lang file '$component' with different \$a parameter?");
          }
          if (!isset($this->stringsforjs[$component][$identifier])) {
              $this->stringsforjs[$component][$identifier] = new lang_string($identifier, $component, $a);
              $this->stringsforjs_as[$component][$identifier] = $a;
          }
      }
code: public function string_for_js($identifier, $component, $a = null) {
          if (!$component) {
              throw new coding_exception('The $component parameter is required for page_requirements_manager::string_for_js().');
          }
          if (isset($this->stringsforjs_as[$component][$identifier]) and $this->stringsforjs_as[$component][$identifier] !== $a) {
              throw new coding_exception("Attempt to re-define already required string '$identifier' " .
                      "from lang file '$component' with different \$a parameter?");
          }
          if (!isset($this->stringsforjs[$component][$identifier])) {
              $this->stringsforjs[$component][$identifier] = new lang_string($identifier, $component, $a);
              $this->stringsforjs_as[$component][$identifier] = $a;
          }
      }
code_tokens: public function string_for_js ( $ identifier , $ component , $ a = null ) { if ( ! $ component ) { throw new coding_exception ( 'The $component parameter is required for page_requirements_manager::string_for_js().' ) ; } if ( isset ( $ this -> stringsforjs_as [ $ component ] [ $ identifier ] ) and $ this -> stringsforjs_as [ $ component ] [ $ identifier ] !== $ a ) { throw new coding_exception ( "Attempt to re-define already required string '$identifier' " . "from lang file '$component' with different \$a parameter?" ) ; } if ( ! isset ( $ this -> stringsforjs [ $ component ] [ $ identifier ] ) ) { $ this -> stringsforjs [ $ component ] [ $ identifier ] = new lang_string ( $ identifier , $ component , $ a ) ; $ this -> stringsforjs_as [ $ component ] [ $ identifier ] = $ a ; } }
docstring: Make a language string available to JavaScript.
  
  All the strings will be available in a M.str object in the global namespace.
  So, for example, after a call to $PAGE->requires->string_for_js('course', 'moodle');
  then the JavaScript variable M.str.moodle.course will be 'Course', or the
  equivalent in the current language.
  
  The arguments to this function are just like the arguments to get_string
  except that $component is not optional, and there are some aspects to consider
  when the string contains {$a} placeholder.
  
  If the string does not contain any {$a} placeholder, you can simply use
  M.str.component.identifier to obtain it. If you prefer, you can call
  M.util.get_string(identifier, component) to get the same result.
  
  If you need to use {$a} placeholders, there are two options. Either the
  placeholder should be substituted in PHP on server side or it should
  be substituted in Javascript at client side.
  
  To substitute the placeholder at server side, just provide the required
  value for the placeholder when you require the string. Because each string
  is only stored once in the JavaScript (based on $identifier and $module)
  you cannot get the same string with two different values of $a. If you try,
  an exception will be thrown. Once the placeholder is substituted, you can
  use M.str or M.util.get_string() as shown above:
  
  // Require the string in PHP and replace the placeholder.
  $PAGE->requires->string_for_js('fullnamedisplay', 'moodle', $USER);
  // Use the result of the substitution in Javascript.
  alert(M.str.moodle.fullnamedisplay);
  
  To substitute the placeholder at client side, use M.util.get_string()
  function. It implements the same logic as {@link get_string()}:
  
  // Require the string in PHP but keep {$a} as it is.
  $PAGE->requires->string_for_js('fullnamedisplay', 'moodle');
  // Provide the values on the fly in Javascript.
  user = { firstname : 'Harry', lastname : 'Potter' }
  alert(M.util.get_string('fullnamedisplay', 'moodle', user);
  
  If you do need the same string expanded with different $a values in PHP
  on server side, then the solution is to put them in your own data structure
  (e.g. and array) that you pass to JavaScript with {@link data_for_js()}.
  
  @param string $identifier the desired string.
  @param string $component the language file to look in.
  @param mixed $a any extra data to add into the string (optional).
docstring_tokens: Make a language string available to JavaScript .