swc-plugin-translation-converter is a plugin for swc used to convert i18next namespace resource expressions into their serialized representation.
NOTE: we don't have the capacity to maintain this all the time, bug support and updates are not guaranteed.
// i18next setup
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
const l = {
translationNamespace: {
helloWorld: "Hello world!",
},
};
i18n.use(initReactI18next).init({
resources: {
en: l,
},
lng: "en",
fallbackLng: "en",
});
// example usage
import React from "react";
const Component = () => {
const { t } = useTranslation();
// swc-plugin-translation-converter will convert the below into
// t("translationNamespace:helloWorld")
return <div>{t(l.translationNamespace.helloWorld)}</div>;
};
If you don't already have swc setup, you can follow their getting started guide.
Add swc-plugin-jsx-remove-attribute to your dependencies like so:
Yarn v1:
yarn add https://github.com/Fullscript/swc-plugin-translation-converter.git#1.0.0
Yarn v2 (and onwards):
yarn add @fullscript/swc-plugin-translation-converter@https://github.com/Fullscript/swc-plugin-translation-converter.git#1.0.0
NPM:
npm install https://github.com/Fullscript/swc-plugin-translation-converter.git#1.0.0
Wherever your SWC configuration is located, add the following:
{
jsc: {
//...
experimental: {
plugins: [["@fullscript/swc-plugin-translation-converted", {}]];
}
}
}
Bug reports and pull requests are welcome :)
- Run:
cargo test
- fixtures are located in
tests/__swc_snapshots__/src/lib.rs
and named the same as the test they're associated to
- Run:
yarn build
- Commit and push!