TacoTranslate
/
說明文件定價
 
5月04日

React 應用程式國際化(i18n)的最佳解決方案

您是否想將您的 React 應用程式擴展到新的市場?TacoTranslate 讓在 React 應用中進行本地化變得非常簡單,讓您無需費心即可觸及全球受眾。

為什麼選擇 TacoTranslate 用於 React?

  • 無縫整合:專為 React 應用程式設計,TacoTranslate 能輕鬆整合進您現有的工作流程。
  • 自動字串收集:不再需要手動管理 JSON 檔案。TacoTranslate 會自動從程式碼庫收集字串。
  • AI 驅動的翻譯:運用 AI 的能力,提供符合上下文、貼合您應用程式語氣的精準翻譯。
  • 即時語言支援:只需一鍵即可新增語言支援,讓您的應用程式能夠在全球使用。

運作方式

使用 npm 安裝 TacoTranslate 套件:

npm install tacotranslate

當您安裝好模組後,您需要建立一個 TacoTranslate 帳戶、一個翻譯專案,以及相關的 API 金鑰。在這裡建立帳戶。它是免費的,並且不需要您提供信用卡資訊。

在 TacoTranslate 應用程式的 UI 中,建立一個專案,然後前往其 API keys 分頁。建立一個 read 金鑰,以及一個 read/write 金鑰。我們會把它們儲存為環境變數。read 金鑰就是我們所稱的 public,而 read/write 金鑰則是 secret。例如,你可以將它們加入到專案根目錄的 .env 檔案中。

你還需要再新增兩個環境變數: TACOTRANSLATE_DEFAULT_LOCALETACOTRANSLATE_ORIGIN.

  • TACOTRANSLATE_DEFAULT_LOCALE: 預設的備用語系代碼。在此範例中,我們會將其設為 en(英文)。
  • TACOTRANSLATE_ORIGIN: 儲存字串的「資料夾」,例如您網站的 URL。 在此處閱讀更多關於來源的資訊。
.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 權限的環境,才能建立要翻譯的新字串。

我們建議您設置一個封閉且安全的暫存環境,在那裡測試您的生產應用程式,並在上線前新增字串。這可以防止任何人竊取您的秘密 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 的產品挪威製造