Skip to content

Commit

Permalink
Update inlang.config.js (#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsJacobsen committed Jun 3, 2023
1 parent e0cda4b commit f577522
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
2 changes: 2 additions & 0 deletions docs/docs/content/i18n.md
Expand Up @@ -27,6 +27,8 @@ To customize an existing language or to load a new language, put one or more `.j

### Using InLang (external service)

[![translation badge](https://inlang.com/badge?url=github.com/knadh/listmonk)](https://inlang.com/editor/github.com/knadh/listmonk?ref=badge)

- Visit [https://inlang.com/editor/github.com/knadh/listmonk](https://inlang.com/editor/github.com/knadh/listmonk)
- To make changes and push them, you need to log in to GitHub using OAuth and fork the project from the UI.
- Translate the text in the input fields on the UI. You can use the filters to see only the necessary translations.
Expand Down
43 changes: 13 additions & 30 deletions inlang.config.js
@@ -1,34 +1,17 @@
/**
* See https://inlang.com/documentation
*/
export async function defineConfig(env) {
const plugin = await env.$import(
"https://cdn.jsdelivr.net/gh/samuelstroschein/inlang-plugin-json@1/dist/index.js"
);
const { default: pluginJson } = await env.$import(
'https://cdn.jsdelivr.net/gh/samuelstroschein/inlang-plugin-json@2.3.1/dist/index.js'
);

const pluginConfig = {
pathPattern: "./i18n/{language}.json",
};
const { default: standardLintRules } = await env.$import(
'https://cdn.jsdelivr.net/gh/inlang/standard-lint-rules@2/dist/index.js'
);

return {
referenceLanguage: "en",
languages: await getLanguages(env),
readResources: (args) =>
plugin.readResources({ ...args, ...env, pluginConfig }),
writeResources: (args) =>
plugin.writeResources({ ...args, ...env, pluginConfig }),
};
return {
referenceLanguage: 'en',
plugins: [pluginJson({
pathPattern: './i18n/{language}.json',
variableReferencePattern: ["{", "}"]
}), standardLintRules()]
};
}


/**
* Automatically derives the languages in this repository.
*/
async function getLanguages(env) {
// replace the path
const files = await env.$fs.readdir("./i18n");
// files that end with .json
// remove the .json extension to only get language name
const languages = files.filter((name) => name.endsWith(".json")).map((name) => name.replace(".json", ""));
return languages;
}

0 comments on commit f577522

Please sign in to comment.