為 React 應用程式輕鬆在地化
想把您的 React 應用程式擴展到新市場嗎?TacoTranslate 讓本地化 React 應用程式變得非常簡單,讓您能輕鬆觸及全球受眾,免除繁瑣步驟。
為什麼要為 React 選擇 TacoTranslate?
- 無縫整合:專為 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_LOCALE
和 TACOTRANSLATE_ORIGIN
.
TACOTRANSLATE_DEFAULT_LOCALE
:預設的後備語系代碼。在此範例中,我們會將它設為en
(英語)。TACOTRANSLATE_ORIGIN
:字串將被儲存的「資料夾」,例如您網站的 URL。 在此閱讀更多關於 origins 的資訊。
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 的 Context 提供者 中:
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!