Giter VIP home page Giter VIP logo

yc-i18n-transformers's Introduction

yc-i18n-transformers

Transform source code related to i18n staff. During transforming process, keysets with translations will be emitted. No more manual manipulation with .json files

Prerequisites:

  • you know that node.js is and have one installed

Tool description and options:

npx yc-i18n-transformers --help

Usage:

  • for example, during development process you have received the following code:

    // src/Button.tsx
    
    // this import needed to understand where the import of i18n functions should be from
    // I18NCODEMOD - implementation of this function is at your discretion
    import { I18NCODEMOD } from "~/utils/i18n";
    
    const Button = () => (
      <Button>
        {I18NCODEMOD("example.keyset", "parrot", "Попугай", "Parrot")}
      </Button>
    );

    You can also omit the first argument (keyset name) and bind the keyset name from the -b (bind) option.

    // assume that kayset name come from cli args
    const Button = () => (
      <Button>{I18NCODEMOD("parrot", "Попугай", "Parrot")}</Button>
    );
    npx yc-i18n-transformers -s ui -n I18NCODEMOD -b 'zoo'
  • in you project root directory run command:

    npx yc-i18n-transformers -s src -n I18NCODEMOD -p "i18n@<keyset>"
  • source files will be formatted into this code:

    // src/Button.tsx
    import i18n from "~/utils/i18n";
    
    const Button = () => <Button>{i18n("example.keyset", "parrot")}</Button>;
  • and files with keysets will be emitted near the transformed file

        src
        │   Button.tsx
    +   └───[email protected]
    +       │   ru.json
    +       │   en.json
    +       │   keyset.json
    +       │   context.json

    Use -k option to emit/edit keysets on one dir: npx yc-i18n-transformers -s src/ui -n I18NCODEMOD -k "src/i18n-keysets"

        src
        └───ui
        │   │   Button.tsx
    +   └───i18n-keysets
    +       └───example.keyset
    +           │   ru.json
    +           │   en.json
    +           │   keyset.json
    +           │   context.json

Quick try

git clone https://github.com/IsaevAlexandr/yc-i18n-transformers.git
cd yc-i18n-transformers/examples/singleKeysetDir
npx yc-i18n-transformers -s ui -k i18n/keysets -n i18nCODEMODE

development

npm i
# for local development try this commands
npm run dev --  -s examples -n i18nPartial -b foo.bar -k examples/singleKeysetDir/i18n-keysets
npm run dev --  -s examples -n i18nCODEMODE -k examples/singleKeysetDir/i18n-keysets
npm run dev --  -s examples -n i18nCODEMODE -p "i18n@<keyset>"
npm run dev --  -s examples -n i18nCODEMODE -k examples/singleKeysetDir/i18n-keysets -f js

yc-i18n-transformers's People

Contributors

isaevalexandr avatar

Watchers

 avatar  avatar

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.