This plugin reads and writes resources that are stored as .po file. The following features are supported:
- ID (
"msgid": "id"
) - messages (
"msgstr": "value"
)
Use a .pot file in your project. It is easier to manage the ids in a file instead of in the code
- Create a new file named
inlang.config.js
in the root of your git repository. - Copy/paste the following code into the config
- Adapt the referenceLanguage, languages and pathPattern (your saved translation files)
If you need more help read the inlang documentation
/**
* @type {import("@inlang/core/config").DefineConfig}
*/
export async function defineConfig(env) {
// importing plugin from local file for testing purposes
const plugin = await env.$import("https://cdn.jsdelivr.net/gh/jannesblobel/inlang-plugin-po@1/dist/index.js");
const pluginConfig = {
// Replace pathPattern with the path where your languages are stored.
pathPattern: "./example/locale/{language}/LC_MESSAGES/django.po",
// Your referenceResourcePath could be
// null or "./example/locale/en/LC_MESSAGES/django.pot",
// dependent if you use pot file as you referenceLanguage
referenceResourcePath: null,
};
return {
// it is necessary to add a referenceLanguage even if referenceResourcePath = null
referenceLanguage: "en",
languages: await plugin.getLanguages({
referenceLanguage: "en",
...env,
pluginConfig,
}),
readResources: (args) =>
plugin.readResources({ ...args, ...env, pluginConfig }),
writeResources: (args) =>
plugin.writeResources({ ...args, ...env, pluginConfig }),
};
}
For additional usage information, take a look at example.
Run the following commands in your terminal (node and npm must be installed):
npm install
npm run dev
npm run dev
will start the development environment which automatically compiles the src/index.ts files to JavaScript (dist/index.js), runs tests defined in *.test.ts
files and watches changes.
Run npm run build
to generate a build.
The dist directory is used to distribute the plugin directly via CDN like jsDelivr. Using a CDN works because the inlang config uses dynamic imports to import plugins.
Read the jsDelivr documentation on importing from GitHub.