Git Product home page Git Product logo

lingascript's Introduction

LingaScript

This project is in early alpha stage, please use it at your own risk

LingaScript is the TypeScript with multilingal support, which enable users to write code with non-English languages.

Basically LingaScript is derived from TypeScript (and Javascript). LingaScript can be compiled to Javascript and be used across the Javascript ecosystem.

Non-english programming adventurers can easily add your local language, work together to improve the same core, and get benifit for the shared programming tools with better local language support.

Current Support Languages

You can find available built version with lingascript-[lang] in npm.

Usage

Install LingaScript via command

npm install -g lingascript-[lang]

Then you get the tsc command. (same as TypeScript)

Create test.ts file.

let isDone = false

or you can use TypeScript-style type check format:

let isDone:boolean = false

Then run command

tsc test.ts

to compile and get output test.js

let isDone = false

To show with locale diagnostic messages, pass the --locale [lang] param in tsc, ex:

tsc --locale zh-cn test.ts

More [native language] code examples in https://github.com/gasolin/lingascript/tree/master/examples/[lang] .

Build

$ git clone https://github.com/gasolin/lingascript.git
$ cd lingascript
$ npm install -g jake
$ npm install
$ npm run build:cn

build:cn will build for Simplified Chinese support and build:tw will build for Traditional Chinese support.

Once build is complete, you can run command node /built/local/tsc.js to compile source code in examples/cn with simplified chinese.

node typescript/built/local/tsc.js -p examples/cn

The example comes from TypeScript's Basic types tutorial.

You can config the tsconfig.json file for different output target (es5, es6, es2018...).

{
  "compilerOptions": {
      "outDir": "./built",
      "allowJs": true,
      "target": "es6",
      "diagnostics": true,
      "locale": "zh-CN"
  },
  "include": [
      "./src/**/*"
  ]
}

Develop

LingaScript use file-patch to patch TypeScript's compiler.

Check TypeScript Build Instruction for more detail about building TypeScript.

Normal Validation phase

The npm run build:cn will do

  1. patch clean TypeScript with .diff files in src/. The related scripts are stored in scripts/ folder.

  2. npm run build will be used to build the patched TypeScript

  3. Run npm run test:cn to make sure the built tool works.

Test different languages

For example, to test Traditional Chinese, you can run commands:

$ npm run clean
$ npm run build:tw
$ npm run test:tw

Rebuild from a clean typescript/ folder

You need to remove TypeScript for a clean patch. To re-build from the clean TypeScript, you can run

$ npm run clean
$ npm run build:cn

check the clean and build:cn script package.json's scripts section for the execute detail.

Debugging phase

  1. You can disable patch process by removing the prebuild script in package.json's scripts section. If you plan to change default keywords, remove cp src/[lang]/language.ts typescript/src/compiler/language.ts && from the build:[lang] script in package.json's scripts section to avoid overwrite from src/[lang].

  2. Follow Normal Validation phase, if the modifications works, we can backup the modified files from typescript/src to src/ via

npm run backup

Edit scripts/backup.sh to include the new modified files.

  1. To generate .diff files, compare the backup-ed modified files with the clean typescript/src folder via
npm run diff

Edit scripts/diff.sh to include the new modified files.

Upgrade TypeScript Version

To upgrade the TypeScript's version (to v3.4.0 for example):

$ npm run upgrade-ts
$ cd typescript
$ git checkout v3.4.0
$ cd ..
$ git add typescript

The TypeScript version follows https://github.com/Microsoft/TypeScript/releases

Build faster

Modify the build:ts script in package.json's scripts section. Replace jake LKG(replace lib/ with last known good build) to jake local(for local build, not replaced lib/).

Changelog

Check CHANGELOG for more detail.

License

Apache-2.0 License

Credit

LingaScript is inspired by zhpy(周蟒) and CTS

lingascript's People

Contributors

gasolin avatar nobodxbodon avatar testacount1 avatar zaoqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lingascript's Issues

wrap keyword matching code to functions

current patch use XXX == 'keyword' || XXX == 'trans_keyword' inline to support different languages

could be replaced by a set of isKeyword[Keyword] function and wrap the matching detail inside of the function

ex, instead of XXX == 'Symbol' || XXX == '中文'

replace to isKeyword(XXX)

and define function

function isKeywordSymbol(value) {
  return value == 'Symbol' || value == '中文' 
}

The change could be proposed to TypeScript for maintainability.

By replacing the isKeyword[Keyword] functions, LingaScript could even support parse multi-native-language keywords in the same compiler

alias for build-in type methods

["a", "b", "c"].length can be written as ["a", "b", "c"].长度

Should work In Example:

EN:

let strLength2: number = (someValue2 as string).length;

CN:

变量 strLength2: 数字 = (someValue2 转为 文字).长度;

issue with package.json sample in readme

Followed steps here, and ./node_modules/bin/tsc doesn't work for me. I change it to ./node_modules/lingascript-cn/bin/tsc to successfully run npm run compile. I wonder if this change is indeed necessary or I missed something during the setup? I'll create a draft PR including this.

transpile ts(en) to ts(cn)

2-way conversion is useful to make sure the conversion is right

this might not possible since transpile ts(en) to js will lose some context

support twjs / cnjs subfix

Related Package (please complete the following information):

  • Package lingascript-tw/lingascript-cn

Is your feature request related to a problem? Please describe.

need separate subfix to support syntax highlight correctly, or the editor will show errors

Describe the solution you'd like

support twjs / cnjs subfix

Additional context

Some user experice sharing in #19

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.