Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TypeScript config #23

Merged
merged 7 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
node_modules
.pnp
.pnp.js
package-lock.json

# testing
coverage
Expand Down
Binary file modified bun.lockb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default {
import { defineConfig } from "languine";

export default defineConfig({
version: "0.6.2",
locale: {
source: "en",
Expand All @@ -13,4 +15,4 @@ export default {
provider: "openai",
model: "gpt-4-turbo",
},
};
});
16 changes: 0 additions & 16 deletions examples/expo/languine.config.mjs

This file was deleted.

18 changes: 18 additions & 0 deletions examples/expo/languine.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { defineConfig } from "languine";

export default defineConfig({
version: "0.6.6",
locale: {
source: "en",
targets: ["es"],
},
files: {
json: {
include: ["locales/native/[locale].json", "locales/[locale].json"],
},
},
llm: {
provider: "openai",
model: "gpt-4-turbo",
},
});
14 changes: 7 additions & 7 deletions examples/expo/locales/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// For more information on Expo Localization and usage: https://docs.expo.dev/guides/localization
import { getLocales } from "expo-localization";
import { I18n } from "i18n-js";
import { getLocales } from 'expo-localization';
import { I18n } from 'i18n-js';

const translations = {
en: require("./en.json"),
es: require("./es.json"),
};
en: require('./en.json'),
es: require('./es.json')
}

const i18n = new I18n(translations);

i18n.locale = getLocales().at(0)?.languageCode ?? "en";
i18n.locale = getLocales().at(0)?.languageCode ?? 'en';

i18n.enableFallback = true;

export default i18n;
export default i18n;
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
export default {
version: "1.0.0",
import { defineConfig } from "languine";

export default defineConfig({
version: "0.6.6",
locale: {
source: "en",
targets: ["sv"],
},
files: {
json: {
include: ["locales/[locale].json"],
include: ["locales"],
},
},
llm: {
provider: "openai",
model: "gpt-4-turbo",
},
};
});
2 changes: 1 addition & 1 deletion examples/i18next/locales/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"interpolated": "Ha en trevlig dag, {{name}}!",
"pluralKey_one": "Det här är ett fint exempel.",
"pluralKey_other": "Det här är fina exempel."
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Biome, Distribution } from "@biomejs/js-api";
import { defineConfig } from "languine";

const biome = await Biome.create({
distribution: Distribution.NODE,
});

export default {
export default defineConfig({
version: "1.0.0",
locale: {
source: "en",
Expand All @@ -21,12 +22,12 @@ export default {
},
hooks: {
// Optional: Format the content with Biome
afterTranslate: ({ content, filePath }) => {
afterTranslate: async ({ content, filePath }) => {
const formatted = biome.formatContent(content.toString(), {
filePath,
});

return formatted.content;
},
},
};
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default {
import { defineConfig } from "languine";

export default defineConfig({
version: "0.5.6",
locale: {
source: "en",
Expand All @@ -14,4 +16,4 @@ export default {
model: "mistral:latest",
temperature: 0,
},
};
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default {
import { defineConfig } from "languine";

export default defineConfig({
version: "1.0.0",
locale: {
source: "en",
Expand All @@ -13,4 +15,4 @@ export default {
provider: "openai",
model: "gpt-4-turbo",
},
};
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default {
import { defineConfig } from "languine";

export default defineConfig({
version: "0.6.2",
locale: {
source: "en",
Expand All @@ -13,4 +15,4 @@ export default {
provider: "openai",
model: "gpt-4-turbo",
},
};
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default {
import { defineConfig } from "languine";

export default defineConfig({
version: "0.6.2",
locale: {
source: "en",
Expand All @@ -13,4 +15,4 @@ export default {
provider: "openai",
model: "gpt-4-turbo",
},
};
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default {
import { defineConfig } from "languine";

export default defineConfig({
version: "0.6.2",
locale: {
source: "en",
Expand All @@ -13,4 +15,4 @@ export default {
provider: "openai",
model: "gpt-4-turbo",
},
}
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default {
import { defineConfig } from "languine";

export default defineConfig({
version: "0.6.2",
locale: {
source: "en",
Expand All @@ -13,4 +15,4 @@ export default {
provider: "openai",
model: "gpt-4-turbo",
},
};
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default {
import { defineConfig } from "languine";

export default defineConfig({
version: "0.6.2",
locale: {
source: "en",
Expand All @@ -13,4 +15,4 @@ export default {
provider: "openai",
model: "gpt-4-turbo",
},
}
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@languine/core",
"version": "1.0.0",
"private": true,
"workspaces": ["packages/*", "apps/*"],
"workspaces": ["packages/*", "apps/*", "examples/*"],
"license": "MIT",
"scripts": {
"build": "turbo build",
Expand Down
16 changes: 9 additions & 7 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"name": "languine",
"version": "0.6.5",
"version": "0.6.6",
"type": "module",
"bin": "dist/index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/config.js",
"types": "dist/config.d.ts",
"license": "MIT",
"scripts": {
"clean": "rm -rf .turbo node_modules",
"lint": "biome check .",
"format": "biome format --write .",
"typecheck": "tsc --noEmit",
"build": "tsup src/index.ts --format esm --dts --clean",
"dev": "tsup src/index.ts --format esm --watch --clean",
"build": "tsup --clean",
"dev": "tsup --watch --clean",
"start": "node dist/index.js"
},
"files": ["dist", "README.md"],
"dependencies": {
"jiti": "^2.4.2",
"sucrase": "^3.35.0",
"@ai-sdk/openai": "^1.0.11",
"@clack/prompts": "^0.9.0",
"@types/plist": "^3.0.5",
"@types/xml2js": "^0.4.14",
"ai": "^4.0.22",
"chalk": "^5.4.1",
"dedent": "^1.5.3",
Expand All @@ -36,6 +36,8 @@
"zod": "^3.24.1"
},
"devDependencies": {
"@types/plist": "^3.0.5",
"@types/xml2js": "^0.4.14",
"@types/diff": "^6.0.0",
"tsup": "^8.3.5",
"typescript": "^5.7.2"
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ export async function init(preset?: string) {
message: "Which model should be used for translations?",
options: models,
})) as string;
const configContent = `import { defineConfig } from "languine";

const configContent = `export default {
export default defineConfig({
version: "${require("../../package.json").version}",
locale: {
source: "${sourceLanguage}",
Expand All @@ -183,7 +184,7 @@ export async function init(preset?: string) {
provider: "${provider}",
model: "${model}",
},
}`;
})`;

try {
const targetLangs = [
Expand Down
Loading
Loading