MCPcopy Index your code
hub / github.com/BANG88/typescript-react-intl

github.com/BANG88/typescript-react-intl @v0.4.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.1 ↗ · + Follow
58 symbols 104 edges 13 files 4 documented · 7% 1 cross-repo links updated 6y ago★ 523 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

typescript-react-intl

Extracts string messages from TypeScript React components or ts files that use React Intl. You can use it in React Native too.

Build Status

Usage

If you have many files to processes,you can get contents use node-glob with fs module Custom component support since version 0.3.0. checkout tests/index.js

npm i typescript-react-intl -D
var parse = require("typescript-react-intl").default;

// results is an array
// contents is your tsx file
var results = parse(contents);

// or if you want support custom components
var results = parse(contents, {
  tagNames: ["MyComponent", "StyledText"],
});

React-intl

Only support <FormattedMessage/> and defineMessages We don't use <FormattedHtmlMessage/>

Examples

var fs = require("fs");
var glob = require("glob");
var parser = require("typescript-react-intl").default;

function runner(pattern, cb) {
  var results = [];
  pattern = pattern || "src/**/*.@(tsx|ts)";
  glob(pattern, function(err, files) {
    if (err) {
      throw new Error(err);
    }
    files.forEach((f) => {
      var contents = fs.readFileSync(f).toString();
      var res = parser(contents);
      results = results.concat(res);
    });

    cb && cb(results);
  });
}

// demo
runner(null, function(res) {
  var locale = {};

  res.forEach((r) => {
    locale[r.id] = r.defaultMessage;
  });

  var locales = {
    en: locale,
  };

  // save file to disk。you can save as a json file,just change the ext and contents as you want.
  fs.writeFileSync(
    `src/translations/all.ts`,
    `export default ${JSON.stringify(locales, null, 2)}\r`,
  );
});

Extension points exported contracts — how you extend this code

Message (Interface)
(no doc)
index.ts
Message (Interface)
(no doc)
lib/index.d.ts
Options (Interface)
(no doc)
index.ts
Options (Interface)
(no doc)
lib/index.d.ts

Core symbols most depended-on inside this repo

copyIfMessageKey
called by 3
index.ts
isValidMessage
called by 3
index.ts
copyIfMessageKey
called by 3
lib/index.js
isValidMessage
called by 3
lib/index.js
extractMessagesForNode
called by 2
index.ts
findMethodCallsWithName
called by 2
index.ts
extractMessagesForNode
called by 2
lib/index.js
findMethodCallsWithName
called by 2
lib/index.js

Shape

Function 36
Class 12
Method 6
Interface 4

Languages

TypeScript100%

Modules by API surface

index.ts17 symbols
lib/index.js15 symbols
test/app/index.tsx7 symbols
app.js4 symbols
test/app/wrappedComponent.tsx3 symbols
test/app/myComponent.tsx3 symbols
test/app/empty.tsx3 symbols
test/app/anotherText.tsx3 symbols
lib/index.d.ts2 symbols
test/app/statelessComponent.tsx1 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add typescript-react-intl \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact