Coder Social home page Coder Social logo

fallenmax / a18n Goto Github PK

View Code? Open in Web Editor NEW
263.0 8.0 7.0 3.76 MB

Automated I18n solution for JavaScript/TypeScript/React

Home Page: https://www.npmjs.com/package/a18n

License: MIT License

JavaScript 0.35% TypeScript 99.65%
i18n internationalization typescript react code-modification

a18n's People

Contributors

fallenmax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

a18n's Issues

setLocale not working in useEffect

function App() {
const [language, setLanguage] = useState('');
useEffect(() => {
const language = Cookies.get('lang') || getUrlParam('lang') || navigator.language || 'zh';
a18n.setLocale(language);
setLanguage(language);
}, []);

return (

……
);
}

setLocale not working like above.

Share locale resource between a18n instances via specifying the same namespace

Proposal

From different a18n code/instances in same page, a18n.getA18n(sameNamespace) always yield same a18n instance (i.e. sharing locale/resource/cache)

a18n might store locale resources in global (window) underlying.

Background

In micro-frontend or application/components architecture, we might have multiple parts of system, each of which independently depends on a18n (probably with different versions) , but would like to share same locale resources for consistency.

To simplify the process of passing locale resources to each part, a18n could provide a mechanism to explicitly share global locale resources.

Limitation

Instances will not be shared across tab/worker/iframe, some user-land sharing solutions are still required in these scenarios.

[CLI] Add `check` command?

Proposal

Add a18n check command, that checks:

  1. If not all texts are translated, list untranslated texts and report failure
  2. Provide option to re-parse code and check for un-extracted texts
  3. Provide option to re-parse code and check for un-wrapped texts

Background

This command can be integrated into CI pipeline to check if there are texts missing translation.

Better handling of JSX text?

Proposal

Maybe we should wrap JSX Text as a whole?
(Inspired by ttag)

let desc  = <strong>nice</strong>
let vdom =  <div>Today is a {desc} day <div>

// should be wrapped as:

let desc  = <strong>nice</strong>
let vdom =   <div>{a18n.x`Today is a {desc} day`}<div>  // a18n.x returns array instead of string

// and extracted to key: "Today is a %1 day"

Background

Currently we only wrap StringLiteral and TemplateLiterals inside JSX Element children, this:

  1. breaks a complete sentence in JSX children into multiple texts, and is not ideal.
  2. does not support scenario like <span>aaa <strong>bbb</strong> ccc</span>

issue with vscode

SNAG-1217

im using node

> npx a18n wrap src -write
npx a18n wrap src -write
	^^^^

Uncaught SyntaxError: Unexpected identifier

or im do it wrong?

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.