Skip to content

Commit

Permalink
fix: better doc and auto choose api
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Oct 16, 2024
1 parent 4085577 commit d0b43f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ All commands are run from the root of the project, from a terminal:

The website aims at having an automatic i18n done via various scripts in the `scripts` directory.

The [translations.tsx](./scripts/translations.tsx) script is used to translate the website content into the desired language. It has two methods to create translations, via `OpenAI API`, and the other via `api.datpmt.com`. To use the OpenAI API method, make sure you have an `OPENAI_API_KEY` as the environment variable set. To use the other API, just un-comment the `translateText` function call using it.
The [translations.tsx](./scripts/translations.tsx) script is used to translate the website content into the desired language. It has two methods to create translations, via `OpenAI API` or `Anthropic API`, and the other via `api.datpmt.com`. To use the OpenAI API method, make sure you have an `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` as the environment variable set. To use the other API, just un-comment the `translateText` function call using it.

Now, let's say that you want to update translations or add a new locale, `fr`.

Expand Down
7 changes: 6 additions & 1 deletion scripts/translate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,10 @@ export const translateTextDatpmt = async (text: string, lang: string) => {
return await response.json()
}

export const translateText = translateTextAnthropic
export const translateText = (text: string, lang: string) => {
if (process.env.ANTHROPIC_API_KEY) return translateTextAnthropic(text, lang)
if (process.env.OPENAI_API_KEY) return translateTextOpenAI(text, lang)
return translateTextDatpmt(text, lang)
}

export const translateTexts = translateTextsAnthropic

0 comments on commit d0b43f0

Please sign in to comment.