Skip to content
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 .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREDENTIALS='{"type":"service_account","project_id":"","private_key_id":"","private_key":"","client_email":"","client_id":"","auth_uri":"","token_uri":"","auth_provider_x509_cert_url":"","client_x509_cert_url":"","universe_domain":""}'
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bin/
lib/
node_modules/

package-lock.json
pnpm-lock.yaml
env.ts
.env
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# `@samchon/json-translator`
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/samchon/json-translator/blob/master/LICENSE)
[![npm version](https://img.shields.io/npm/v/@samchon/json-translator.svg)](https://www.npmjs.com/package/@samchon/json-translator)
[![Downloads](https://img.shields.io/npm/dm/@samchon/json-translator.svg)](https://www.npmjs.com/package/@samchon/json-translator)
[![Build Status](https://github.com/samchon/json-translator/workflows/build/badge.svg)](https://github.com/samchon/json-translator/actions?query=workflow%3Abuild)

Translate JSON file via Google Translate API.

`@samchon/json-translate` is a wrapper library that translates JSON files using the Google Translate API. It has optimization logic that reduces costs and elapsed time by minimizing the number of API calls.

Here is an example code translating `swagger.json` file.

```typescript
import { OpenApi } from "@samchon/openapi";
import { JsonTranslator } from "@samchon/json-translator";

const fetchOpenApiDocument = async (): Promise<OpenApi.IDocument> => {
const response: Response = await fetch(
"https://raw.githubusercontent.com/samchon/shopping-backend/refs/heads/master/packages/api/swagger.json",
);
return response.json();
}

const main = async (): Promise<void> => {
const translator: JsonTranslator = new JsonTranslator({
credentials: { ... },
});
const input: OpenApi.IDocument = await fetchOpenApiDocument();
const output: OpenApi.IDocument = await translator.translate({
input,
to: "ko",
filter: (explore) =>
explore.key === "title" ||
explore.key === "description" ||
explore.key === "summary" ||
explore.key === "x-wrtn-placeholder",
});
console.log(output);
};
main().catch(console.error);
```
7 changes: 7 additions & 0 deletions assets/input/bbs.article.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "c1cbfc65-51fe-4cc3-b162-568fdedb1c41",
"title": "[Article] Hello, nice to meet you.",
"body": "Nice to meet you translate-json users.\n\nThis is an example JSON file embodying a BBS article.\n\nLet's see how this content be translated into other languages.",
"created_at": "2024-09-26T19:45:47.145Z",
"updated_at": "2024-10-22T03:49:25.790Z"
}
Loading