輕鬆為 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。 在此閱讀更多關於來源的資訊。
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!