เริ่มต้นใช้งาน
การติดตั้ง
To install TacoTranslate in your application, open your terminal and navigate to the root directory of your project. Then, run the following command to install with npm:
npm install tacotranslateThis assumes you already have an application set up. See examples for more information.
การใช้งานพื้นฐาน
ตัวอย่างด้านล่างนี้แสดงวิธีสร้างไคลเอนต์ TacoTranslate ห่อแอปพลิเคชันของคุณด้วยโปรไวเดอร์ TacoTranslate และใช้คอมโพเนนต์ Translate เพื่อแสดงข้อความที่แปลแล้ว
import createTacoTranslateClient from 'tacotranslate';
import {TacoTranslate, Translate} from 'tacotranslate/react';
const tacoTranslateClient = createTacoTranslateClient({apiKey: 'YOUR_API_KEY'});
function Page() {
return <Translate string="Hello, world!" />;
}
export default function App() {
return (
<TacoTranslate client={tacoTranslateClient} locale="es">
<Page />
</TacoTranslate>
);
}ตัวอย่างนี้ตั้งค่าให้ใช้ภาษาสเปน (locale="es") ดังนั้นคอมโพเนนต์ Translate จะแสดงผล "¡Hola, mundo!".
ตัวอย่าง
ไปที่ โฟลเดอร์ตัวอย่างบน GitHub ของเรา เพื่อเรียนรู้เพิ่มเติมเกี่ยวกับวิธีการตั้งค่า TacoTranslate โดยเฉพาะสำหรับกรณีการใช้งานของคุณ เช่น การใช้กับ Next.js App Router หรือการใช้ Create React App.
เรายังมี CodeSandbox ตั้งค่าไว้ให้คุณ ดูตัวอย่างได้ที่นี่.