Coder Social home page Coder Social logo

Comments (2)

mydea avatar mydea commented on August 22, 2024

Hmm, sorry to hear that. I was not aware that esprima - what we now use to parse .js files - does not support TypeScript.

Right now, we don't really have the resources to implement this - so you probably need to stay on 2.x for now.

However, we'd love to accept a PR for that! Feel free to ask if you need any guidance. Roughly speaking, this is what would need to be done:

  • Create a new file lib/utils/commands/utils/parse-ts.js based on https://github.com/Cropster/ember-l10n/blob/master/lib/commands/utils/parse-js.js
  • Look for a good TS AST parser - basically an equivalent to http://esprima.org/. Replace the esprima logic from parse-js with the AST logic of the TS parser.
  • In the file /lib/commands/extract.js, adapt the method _extractFromJS() to call parseJsFile() only on files ending with .js, and call the new parseTsFile() afterwards for files ending with .ts. You can use let jsFiles = this._getFiles(options, 'js'); and let tsFiles = this._getFiles(options, 'ts'); to get the appropriate files.

The whole method would look something like this:

_extractFromJS(options) {
    let jsFiles = this._getFiles(options, 'js');
    let tsFiles = this._getFiles(options, 'ts');

    let outputFile = this.potFile;
    let potFile = this._getFileName(outputFile);

    jsFiles.forEach(file => {
      if (this._shouldSkipFile(file)) {
        this.ui.writeLine(chalk.yellow(`Skipping ${file}...`));
        return;
      }
      
      this.ui.writeLine(chalk.white(`Extracting ${file} >>> ${potFile}...`));

      parseJsFile(file, options, this.messageGettextItems);
    });

    tsFiles.forEach(file => {
      if (this._shouldSkipFile(file)) {
        this.ui.writeLine(chalk.yellow(`Skipping ${file}...`));
        return;
      }
      
      this.ui.writeLine(chalk.white(`Extracting ${file} >>> ${potFile}...`));

      parseTsFile(file, options, this.messageGettextItems);
    });

    this.ui.writeLine(chalk.green.bold(`\nExtracted ${files.length} files ✔`));
  },

from ember-l10n.

mydea avatar mydea commented on August 22, 2024

This has been fixed in 3.2.0, which now uses a different parser which also allows to parse ts files! I haven't tried this in a production app, but there is a test that covers that. Please let us know if you encounter any issues.

from ember-l10n.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.