<commit_before>// Copyright 2002-2013, University of Colorado Boulder

/**
 * String plugin, loads a string using a syntax like:
 * var title = require( 'string!JOHN_TRAVOLTAGE/johnTravoltage.name' );
 *
 * The reasons we need our own string plugin:
 * So we can only include the (possibly) strings that are needed for a sim
 * So we can enumerate all of the used strings, for purposed of a translation utility
 * For uniformity with image and audio plugin
 *
 * TODO: Can we use require( 'string!JOHN_TRAVOLTAGE:johnTravoltage.name' ) instead of require( 'string!JOHN_TRAVOLTAGE/johnTravoltage.name' )?
 * TODO: exclude the plugin itself from build file.  RequireJS docs said there is an easy way to do so
 * TODO: Currently hard coded to use English.  Provide support for any language.
 * TODO: Should we build all strings into the final HTML file, or separate HTML file per language?
 * TODO: Provide fallbacks to higher languages for missing strings
 * TODO: Could lump strings together into one script block--perhaps it would be readable by the translation utility and the runtime.
 *       This could facilitate rewriting the html in place.
 * @author <NAME>
 */
define( ['text'], function( text ) {

  //Keep track of the strings that are used during dependency resolution so they can be looked up at build time
  var buildMap = {};

  var locale = 'en';

  var parse = (typeof JSON !== 'undefined' && typeof JSON.parse === 'function') ? JSON.parse : function( text ) { return eval( '(' + text + ')' ); };

  return {
    load: function( name, parentRequire, onload, config ) {

      var url = parentRequire.toUrl( name );
//      console.log( 'found url: ' + url );
      var question = url.lastIndexOf( '?' );
      var key = question < 0 ? url.substring( url.lastIndexOf( '/' ) + 1 ) : url.substring( url.lastIndexOf( '/' ) + 1, question );

      var project = name.substring( 0, name.indexOf( '/' ) );

      var stringPath = project.toLowerCase().split( '_' ).join( '-' ) + '-strings_' + locale;

      //Load it through the module system
//        debugger;
//      console.log( 'getting text for: ' + project + '/../strings/' + stringPath + '.json' );

      var a = url.substring( 0, url.lastIndexOf( '/' ) );
      var pathToFile = a.substring( 0, a.lastIndexOf( '/' ) ) + '/strings/' + stringPath + '.json';

//      console.log( 'checking path: ', pathToFile );

      var pathToUse = config.isBuild ? pathToFile : project + '/../strings/' + stringPath + '.json';
      text.get( pathToUse, function( stringFile ) {

          //put parsed json in the loaded file so we don't have to reparse
          if ( config.isBuild ) {
            buildMap[name] = parse( stringFile );
            onload( null );
          }

          else {

            //TODO: move the config.isBuild call here, by putting the stringFile data into the buildMap, like in the json plugin
//            console.log( 'loaded through module system: ' + stringFile );
//            console.log( 'checking query parameter:', key );
            var queryParameterValue = window.phetcommon.getQueryParameter( key );
            if ( queryParameterValue ) {
              onload( queryParameterValue );
            }
            else {
              onload( parse( stringFile )[key] );
            }
          }
        },
        onload.error, {
          accept: 'application/json'
        }
      );
    },

    //write method based on RequireJS official text plugin by <NAME><commit_msg>first steps toward moving BAM to string! plugin<commit_after>// Copyright 2002-2013, University of Colorado Boulder

/**
 * String plugin, loads a string using a syntax like:
 * var title = require( 'string!JOHN_TRAVOLTAGE/johnTravoltage.name' );
 *
 * The reasons we need our own string plugin:
 * So we can only include the (possibly) strings that are needed for a sim
 * So we can enumerate all of the used strings, for purposed of a translation utility
 * For uniformity with image and audio plugin
 *
 * TODO: Can we use require( 'string!JOHN_TRAVOLTAGE:johnTravoltage.name' ) instead of require( 'string!JOHN_TRAVOLTAGE/johnTravoltage.name' )?
 * TODO: exclude the plugin itself from build file.  RequireJS docs said there is an easy way to do so
 * TODO: Currently hard coded to use English.  Provide support for any language.
 * TODO: Should we build all strings into the final HTML file, or separate HTML file per language?
 * TODO: Provide fallbacks to higher languages for missing strings
 * TODO: Could lump strings together into one script block--perhaps it would be readable by the translation utility and the runtime.
 *       This could facilitate rewriting the html in place.
 * @author <NAME>
 */
define( ['text'], function( text ) {

  //Keep track of the strings that are used during dependency resolution so they can be looked up at build time
  var buildMap = {};

  var locale = 'en';

  var parse = (typeof JSON !== 'undefined' && typeof JSON.parse === 'function') ? JSON.parse : function( text ) { return eval( '(' + text + ')' ); };

  return {
    load: function( name, parentRequire, onload, config ) {

      var url = parentRequire.toUrl( name );
//      console.log( 'found url: ' + url );
      var question = url.lastIndexOf( '?' );
      var key = question < 0 ? url.substring( url.lastIndexOf( '/' ) + 1 ) : url.substring( url.lastIndexOf( '/' ) + 1, question );

      var project = name.substring( 0, name.indexOf( '/' ) );
      if ( project.toLowerCase() === 'bam' ) {
        project = 'build-a-molecule';
      }

      var stringPath = project.toLowerCase().split( '_' ).join( '-' ) + '-strings_' + locale;

      //Load it through the module system
//        debugger;
//      console.log( 'getting text for: ' + project + '/../strings/' + stringPath + '.json' );

      var a = url.substring( 0, url.lastIndexOf( '/' ) );
      var pathToFile = a.substring( 0, a.lastIndexOf( '/' ) ) + '/strings/' + stringPath + '.json';

//      console.log( 'checking path: ', pathToFile );

      var pathToUse = config.isBuild ? pathToFile : project + '/../strings/' + stringPath + '.json';
      text.get( pathToUse, function( stringFile ) {

          //put parsed json in the loaded file so we don't have to reparse
          if ( config.isBuild ) {
            buildMap[name] = parse( stringFile );
            onload( null );
          }

          else {

            //TODO: move the config.isBuild call here, by putting the stringFile data into the buildMap, like in the json plugin
//            console.log( 'loaded through module system: ' + stringFile );
//            console.log( 'checking query parameter:', key );
            var queryParameterValue = window.phetcommon.getQueryParameter( key );
            if ( queryParameterValue ) {
              onload( queryParameterValue );
            }
            else {
              var parsed = parse( stringFile );
              if ( parsed[key] ) {
                onload( parsed[key] );
              }
              else {
                console.log( 'string not found for key: ' + key );
                onload( key );
              }
            }
          }
        },
        onload.error, {
          accept: 'application/json'
        }
      );
    },

    //write method based on RequireJS official text plugin by <NAME>
{'fraction_non_alphanumeric': 0.11521620142309798, 'fraction_numerical': 0.0038314176245210726, 'mean_word_length': 2.455791962174941, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1047615', 'n_tokens_mistral': 2073, 'n_tokens_neox': 1978, 'n_words': 755}