Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
babel-plugin-c-3po
Advanced tools
[![travis](https://api.travis-ci.org/c-3po-org/babel-plugin-c-3po.svg)](https://travis-ci.org/c-3po-org) [![codecov](https://codecov.io/gh/c-3po-org/babel-plugin-c-3po/branch/master/graph/badge.svg)](https://codecov.io/gh/c-3po-org/babel-plugin-c-3po)
Solution for providing gettext like translations into your project. Uses es6 native template syntax.
Plugin functions:
Key features: The core features of this tool are:
npm install --save-dev babel-plugin-c-3po && npm install --save c-3po
Here is how you code will look like while using this plugin:
import { t } from 'c-3po';
const name = 'Mike';
console.log(t`Hello ${name}`);
So you can see that you can use native es6 template formatting. To make your string translatable, all you need to do is to place 't' tag.
Translator will see this inside .po files:
#: src/page.js:8
msgid "Hello ${ name }"
msgstr ""
Here is how you can handle plural forms:
This function has something similar with standart ngettext but behaves a little bit different. It assumes that you have only one form in your sources and other forms will be added in .po files. This is because different languages has different number of plural forms, and there are cases when your default language is not english, so it doesn't make sense to specify 2 plural forms at all.
import { ngettext, msgid } from 'c-3po';
const name = 'Mike';
const n = 5;
console.log(ngettext(msgid`Mike has ${n} banana`, `Mike has ${n} bananas`, n));
Output in .po files:
#: src/PluralDemo.js:18
msgid "Mike has ${ n } banana"
msgid_plural "Mike has ${ n } bananas"
msgstr[0] ""
msgstr[1] ""
There are no additional setup for making this plugin work inside jsx. (just add babel-plugin-react plugin to your .babelrc)
import React from 'react';
import { t, ngettext, msgid } from 'c-3po';
class PluralDemo extends React.Component {
constructor(props) {
super(props);
this.state = { count: 0 };
this.countInc = this.countInc.bind(this);
}
countInc() {
this.setState({ count: this.state.count + 1 });
}
render() {
const n = this.state.count;
return (
<div>
<h3>{ t`Deadly boring counter demo (but with plurals)` }</h3>
<div>{ ngettext(msgid`You have clicked ${n} time`, `You have clicked ${n} times`, n) }</div>
<button onClick={this.countInc}>{ t`Click me` }</button>
</div>
)
}
}
export default PluralDemo;
If for some reason you need to disable c-3po plugin transformation for some code block you can use special comment globally to disable the whole file or inside some code block (function):
/* disable c-3po */
// or
function test() {
/* disable c-3po */
}
Feel free to contribute, make sure to cover your contributions with tests. Test command:
make test
FAQs
[![travis](https://api.travis-ci.org/c-3po-org/babel-plugin-c-3po.svg)](https://travis-ci.org/c-3po-org) [![codecov](https://codecov.io/gh/c-3po-org/babel-plugin-c-3po/branch/master/graph/badge.svg)](https://codecov.io/gh/c-3po-org/babel-plugin-c-3po)
We found that babel-plugin-c-3po demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.