TacoTranslate
/
文档定价
 
5月04日

为 React 应用实现轻松本地化

您是否希望将您的 React 应用扩展到新的市场?TacoTranslate 使本地化 React 应用变得极其容易,让您无需繁琐操作即可触达全球用户。

为什么为 React 选择 TacoTranslate?

  • 无缝集成:专为 React 应用设计,TacoTranslate 无缝集成到您现有的工作流程中。
  • 自动收集字符串:无需再手动管理 JSON 文件。TacoTranslate 会自动从代码库中收集字符串。
  • AI 驱动的翻译:利用 AI 的强大能力,提供符合上下文并契合您应用语气的准确翻译。
  • 即时语言支持:只需点击即可添加对新语言的支持,使您的应用面向全球用户可访问。

工作原理

通过 npm 安装 TacoTranslate 包:

npm install tacotranslate

安装好该模块后,您需要创建一个 TacoTranslate 帐户、一个翻译项目,以及相应的 API 密钥。在此创建帐户。 这是免费的,无需提供信用卡信息。

在 TacoTranslate 应用程序的 UI 中,创建一个项目,然后进入其 API 密钥选项卡。创建一个 read 密钥和一个 read/write 密钥。我们会将它们保存为环境变量。read 密钥就是我们所称的 public,而 read/write 密钥是 secret。例如,你可以把它们添加到项目根目录的 .env 文件中。

您还需要添加两个环境变量: TACOTRANSLATE_DEFAULT_LOCALETACOTRANSLATE_ORIGIN

  • TACOTRANSLATE_DEFAULT_LOCALE: 默认的回退区域设置代码。在本例中,我们将其设置为 en(英语)。
  • TACOTRANSLATE_ORIGIN: 存放字符串的“文件夹”,例如您网站的 URL。 在此阅读有关 origins 的更多信息。
.env
TACOTRANSLATE_PUBLIC_API_KEY=123456
TACOTRANSLATE_SECRET_API_KEY=789010
TACOTRANSLATE_DEFAULT_LOCALE=en
TACOTRANSLATE_ORIGIN=your-website-url.com

请务必不要将秘密 read/write API 密钥泄露到客户端的生产环境中。

设置 TacoTranslate

在你的 React 应用中初始化 TacoTranslate,方法是将应用包裹在 TacoTranslate 的上下文提供器中:

import React, {useState} from 'react';
import TacoTranslate, {Translate} from 'tacotranslate/react';

const tacoTranslate = createTacoTranslateClient({
	apiKey: 'YOUR_API_KEY',
});

export default function App() {
	const [locale, setLocale] = useState('en');

	return (
		<TacoTranslate client={tacoTranslate} locale={locale}>
			<Translate string="Hello, world!"/>
		</TacoTranslate>
	);
}

现在您可以在应用程序的任何位置使用 Translate 组件来显示翻译后的文本!请务必查看 我们的文档,以获取更多信息以及针对您特定设置的实施指南。

import {Translate} from 'tacotranslate/react';

export default async function Component() {
	return (
		<Translate string="Hello? This is TacoTranslate speaking." />
	);
}

使用 TacoTranslate 的好处

  • 节省时间:自动化繁琐的本地化和字符串收集过程,节省宝贵时间。
  • 成本效益:减少对人工翻译的依赖,降低本地化成本。
  • 提高准确性:AI 驱动的翻译可确保上下文准确且高质量的译文。
  • 可扩展的解决方案:随着应用和用户群的增长,轻松添加对新语言的支持。

立即开始!

当您将任何字符串添加到 Translate 组件时,您的 React 应用将被自动翻译。请注意,只有在 API 密钥上具有 read/write 权限的环境,才能创建新的待翻译字符串。

我们建议设置一个封闭且安全的预发布(staging)环境,在其中测试您的生产应用,并在上线前添加新的字符串。这样可以防止任何人窃取您的秘密 API 密钥,并防止通过添加恶意字符串使您的翻译项目膨胀。

Be sure to check out the complete examples over at our GitHub profile. If you encounter any problems, feel free to reach out, and we’ll be more than happy to help.

TacoTranslate lets you automatically localize your React applications quickly to and from over 75 languages. Translate for free!

来自 Nattskiftet 的产品挪威制造