Skip to content

Commit 4db64a0

Browse files
committed
added ai context
1 parent e33980c commit 4db64a0

File tree

16 files changed

+2719
-10307
lines changed

16 files changed

+2719
-10307
lines changed

package-lock.json

Lines changed: 2679 additions & 5234 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const getConf = async () => {
1515
const localeDir = await config.getValueOrThrow('localeDir', { saveOnInput: true });
1616
const folderName = await config.getValueOrThrow('inputLanguageFolderName', { saveOnInput: true });
1717
const lang = (await config.getValueOrThrow('inputLanguage', { saveOnInput: true })) as LangPair['lang'];
18-
return { apiKey, localeDir, folderName, lang };
18+
const context = await config.getValue('context', { saveOnInput: true });
19+
return { apiKey, localeDir, folderName, lang, context };
1920
};
2021

2122
program
@@ -41,7 +42,7 @@ program
4142
.description('translate i18 json files')
4243
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4344
.action(async (options) => {
44-
const { apiKey, folderName, lang, localeDir } = await getConf();
45+
const { apiKey, folderName, lang, localeDir, context } = await getConf();
4546
const result = await translateLocaleFolder({
4647
srcLang: {
4748
folderName,
@@ -50,6 +51,7 @@ program
5051
apiKey,
5152
cwd: process.cwd(),
5253
localeDir,
54+
context,
5355
});
5456
console.log(
5557
chalk.green(

packages/cli/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aexol/dev-translate",
3-
"version": "0.1.0",
3+
"version": "0.1.2",
44
"private": false,
55
"main": "./lib/index.js",
66
"author": "Aexol, Artur Czemiel",
@@ -17,10 +17,10 @@
1717
"lib"
1818
],
1919
"dependencies": {
20-
"@aexol/dev-translate-config": "^0.1.0",
21-
"@aexol/dev-translate-core": "^0.1.0",
20+
"@aexol/dev-translate-config": "^0.1.2",
21+
"@aexol/dev-translate-core": "^0.1.2",
2222
"chalk": "^5.3.0",
2323
"chokidar": "^3.6.0",
2424
"commander": "^11.0.0"
2525
}
26-
}
26+
}

packages/config/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ export type LangPair = {
4040
};
4141

4242
export type ProjectOptions = {
43+
// name of folder with files from input language
4344
inputLanguageFolderName: string;
45+
// input language language code
4446
inputLanguage: string;
47+
// your devtranslate.app api key
4548
apiKey: string;
49+
// folder where you store locale folders with language names
4650
localeDir: string;
51+
// ai context for translations
52+
context?: string;
4753
};
4854

4955
// eslint-disable-next-line @typescript-eslint/ban-types

packages/config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aexol/dev-translate-config",
3-
"version": "0.1.0",
3+
"version": "0.1.2",
44
"private": false,
55
"main": "./lib/index.js",
66
"author": "Aexol, Artur Czemiel",

packages/core/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ export const translateLocaleFolder = async ({
132132
apiKey,
133133
cwd,
134134
localeDir,
135+
context,
135136
}: {
136137
cwd: string;
137138
localeDir: string;
138139
apiKey: string;
139140
srcLang: LangPair;
141+
context?: string;
140142
}) => {
141143
const { localePath, localeSrcFiles, outLangs, srcLangPath } = getLocalePaths({ cwd, localeDir, srcLang });
142144
const translateChain = await Chain('https://backend.devtranslate.app/graphql', {
@@ -165,6 +167,7 @@ export const translateLocaleFolder = async ({
165167
content: srcFileContent,
166168
inputLanguage: srcLang.lang,
167169
languages: [outputLang.lang],
170+
context,
168171
},
169172
},
170173
{

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aexol/dev-translate-core",
3-
"version": "0.1.0",
3+
"version": "0.1.2",
44
"private": false,
55
"main": "./lib/index.js",
66
"author": "Aexol, Artur Czemiel",

packages/nextjs-dev-translate-plugin/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ export type DevTranslateOptions = {
88
folderName: string;
99
lang: LangPair['lang'];
1010
localeDir: string;
11+
context?: string;
1112
};
1213

13-
const setupFileWatcher = async (opts: {
14-
apiKey: string;
15-
folderName: string;
16-
lang: LangPair['lang'];
17-
localeDir: string;
18-
}) => {
19-
const { apiKey, folderName, lang, localeDir } = opts;
14+
const setupFileWatcher = async (opts: DevTranslateOptions) => {
15+
const { apiKey, folderName, lang, localeDir, context } = opts;
2016
const directoryToWatch = path.join(process.cwd(), localeDir, opts.folderName);
2117
const translate = async () => {
2218
await translateLocaleFolder({
@@ -25,6 +21,7 @@ const setupFileWatcher = async (opts: {
2521
lang,
2622
},
2723
apiKey,
24+
context,
2825
cwd: process.cwd(),
2926
localeDir,
3027
});
@@ -50,6 +47,10 @@ const setupFileWatcher = async (opts: {
5047

5148
// Plugin function to be used in next.config.js
5249
export function withDevTranslate(nextConfig: NextConfig = {}, options: DevTranslateOptions): NextConfig {
50+
const env = process.env.NODE_ENV;
51+
if (env !== 'development') {
52+
return nextConfig;
53+
}
5354
setupFileWatcher(options);
5455
return {
5556
...nextConfig,

packages/nextjs-dev-translate-plugin/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aexol/nextjs-dev-translate-plugin",
3-
"version": "0.1.0",
3+
"version": "0.1.2",
44
"private": false,
55
"main": "./lib/index.js",
66
"author": "Aexol, Artur Czemiel",
@@ -15,7 +15,7 @@
1515
"commonjs"
1616
],
1717
"dependencies": {
18-
"@aexol/dev-translate-core": "^0.1.0",
18+
"@aexol/dev-translate-core": "^0.1.2",
1919
"chokidar": "^3.6.0"
2020
},
2121
"peerDependencies": {
@@ -28,4 +28,4 @@
2828
"import": "./lib/index.js",
2929
"require": "./commonjs/index.js"
3030
}
31-
}
31+
}

0 commit comments

Comments
 (0)