@@ -75,7 +75,7 @@ export const rosettaTranslations = pgTable('rosetta_translations', {
7575** Option A: Use ` @sylphx/rosetta-drizzle ` (Recommended)**
7676
7777``` typescript
78- // lib/i18n /storage.ts
78+ // lib/rosetta /storage.ts
7979import { DrizzleStorageAdapter } from ' @sylphx/rosetta-drizzle' ;
8080import { db } from ' @/db' ;
8181import { rosettaSources , rosettaTranslations } from ' @/db/schema' ;
@@ -90,7 +90,7 @@ export const storage = new DrizzleStorageAdapter({
9090** Option B: Implement ` StorageAdapter ` manually**
9191
9292``` typescript
93- // lib/i18n /storage.ts
93+ // lib/rosetta /storage.ts
9494import type { StorageAdapter } from ' @sylphx/rosetta' ;
9595import { db } from ' @/db' ;
9696import { eq , inArray , notInArray } from ' drizzle-orm' ;
@@ -150,16 +150,16 @@ export const storage: StorageAdapter = {
150150};
151151```
152152
153- ### 3. Initialize I18n
153+ ### 3. Initialize Rosetta
154154
155155``` typescript
156- // lib/i18n /index.ts
157- import { I18n } from ' @sylphx/rosetta/server' ;
156+ // lib/rosetta /index.ts
157+ import { Rosetta } from ' @sylphx/rosetta/server' ;
158158import { OpenRouterAdapter } from ' @sylphx/rosetta/adapters' ;
159159import { cookies } from ' next/headers' ;
160160import { storage } from ' ./storage' ;
161161
162- export const i18n = new I18n ({
162+ export const rosetta = new Rosetta ({
163163 storage ,
164164 translator: new OpenRouterAdapter ({
165165 apiKey: process .env .OPENROUTER_API_KEY ! ,
@@ -179,20 +179,20 @@ export { t, flushCollectedStrings, getTranslationsForClient, getLocale } from '@
179179
180180``` tsx
181181// app/layout.tsx
182- import { i18n , flushCollectedStrings , getTranslationsForClient , getLocale } from ' @/lib/i18n ' ;
183- import { I18nProvider } from ' @sylphx/rosetta-react' ;
182+ import { rosetta , flushCollectedStrings , getTranslationsForClient , getLocale } from ' @/lib/rosetta ' ;
183+ import { RosettaProvider } from ' @sylphx/rosetta-react' ;
184184
185185export default async function RootLayout({ children }: { children: React .ReactNode }) {
186- return i18n .init (async () => {
186+ return rosetta .init (async () => {
187187 const content = (
188188 <html lang = { getLocale ()} >
189189 <body >
190- <I18nProvider
190+ <RosettaProvider
191191 locale = { getLocale ()}
192192 translations = { getTranslationsForClient ()}
193193 >
194194 { children }
195- </I18nProvider >
195+ </RosettaProvider >
196196 </body >
197197 </html >
198198 );
@@ -208,7 +208,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo
208208
209209** Server Components:**
210210``` tsx
211- import { t } from ' @/lib/i18n ' ;
211+ import { t } from ' @/lib/rosetta ' ;
212212
213213export function ServerComponent() {
214214 return (
@@ -238,98 +238,98 @@ export function ClientComponent() {
238238Create API routes to manage translations:
239239
240240``` typescript
241- // app/api/i18n /sources/route.ts
242- import { i18n } from ' @/lib/i18n ' ;
241+ // app/api/rosetta /sources/route.ts
242+ import { rosetta } from ' @/lib/rosetta ' ;
243243import { NextResponse } from ' next/server' ;
244244
245- // GET /api/i18n /sources - Get all sources with translation status
245+ // GET /api/rosetta /sources - Get all sources with translation status
246246export async function GET() {
247- const sources = await i18n .getSourcesWithStatus ();
247+ const sources = await rosetta .getSourcesWithStatus ();
248248 return NextResponse .json (sources );
249249}
250250```
251251
252252``` typescript
253- // app/api/i18n /stats/route.ts
254- import { i18n } from ' @/lib/i18n ' ;
253+ // app/api/rosetta /stats/route.ts
254+ import { rosetta } from ' @/lib/rosetta ' ;
255255import { NextResponse } from ' next/server' ;
256256
257- // GET /api/i18n /stats - Get translation statistics
257+ // GET /api/rosetta /stats - Get translation statistics
258258export async function GET() {
259- const stats = await i18n .getStats ();
259+ const stats = await rosetta .getStats ();
260260 return NextResponse .json (stats );
261261}
262262```
263263
264264``` typescript
265- // app/api/i18n /translate/route.ts
266- import { i18n } from ' @/lib/i18n ' ;
265+ // app/api/rosetta /translate/route.ts
266+ import { rosetta } from ' @/lib/rosetta ' ;
267267import { NextResponse } from ' next/server' ;
268268
269- // POST /api/i18n /translate - Generate translation for a string
269+ // POST /api/rosetta /translate - Generate translation for a string
270270export async function POST(req : Request ) {
271271 const { text, locale, context } = await req .json ();
272- const translation = await i18n .generateAndSave (text , locale , context );
272+ const translation = await rosetta .generateAndSave (text , locale , context );
273273 return NextResponse .json ({ translation });
274274}
275275```
276276
277277``` typescript
278- // app/api/i18n /translate/batch/route.ts
279- import { i18n } from ' @/lib/i18n ' ;
278+ // app/api/rosetta /translate/batch/route.ts
279+ import { rosetta } from ' @/lib/rosetta ' ;
280280import { NextResponse } from ' next/server' ;
281281
282- // POST /api/i18n /translate/batch - Batch translate strings
282+ // POST /api/rosetta /translate/batch - Batch translate strings
283283export async function POST(req : Request ) {
284284 const { items, locale } = await req .json ();
285- const result = await i18n .batchTranslate (items , locale );
285+ const result = await rosetta .batchTranslate (items , locale );
286286 return NextResponse .json (result );
287287}
288288```
289289
290290``` typescript
291- // app/api/i18n /translations/route.ts
292- import { i18n } from ' @/lib/i18n ' ;
291+ // app/api/rosetta /translations/route.ts
292+ import { rosetta } from ' @/lib/rosetta ' ;
293293import { NextResponse } from ' next/server' ;
294294
295- // PUT /api/i18n /translations - Save manual translation
295+ // PUT /api/rosetta /translations - Save manual translation
296296export async function PUT(req : Request ) {
297297 const { locale, hash, text } = await req .json ();
298- await i18n .saveTranslationByHash (locale , hash , text , { autoGenerated: false });
298+ await rosetta .saveTranslationByHash (locale , hash , text , { autoGenerated: false });
299299 return NextResponse .json ({ success: true });
300300}
301301```
302302
303303``` typescript
304- // app/api/i18n /review/route.ts
305- import { i18n } from ' @/lib/i18n ' ;
304+ // app/api/rosetta /review/route.ts
305+ import { rosetta } from ' @/lib/rosetta ' ;
306306import { NextResponse } from ' next/server' ;
307307
308- // POST /api/i18n /review - Mark translation as reviewed
308+ // POST /api/rosetta /review - Mark translation as reviewed
309309export async function POST(req : Request ) {
310310 const { hash, locale } = await req .json ();
311- await i18n .markAsReviewed (hash , locale );
311+ await rosetta .markAsReviewed (hash , locale );
312312 return NextResponse .json ({ success: true });
313313}
314314```
315315
316316``` typescript
317- // app/api/i18n /export/route.ts
318- import { i18n } from ' @/lib/i18n ' ;
317+ // app/api/rosetta /export/route.ts
318+ import { rosetta } from ' @/lib/rosetta ' ;
319319import { NextResponse } from ' next/server' ;
320320
321- // GET /api/i18n /export?locale=zh-TW - Export translations
321+ // GET /api/rosetta /export?locale=zh-TW - Export translations
322322export async function GET(req : Request ) {
323323 const { searchParams } = new URL (req .url );
324324 const locale = searchParams .get (' locale' ) ?? ' zh-TW' ;
325- const data = await i18n .exportTranslations (locale );
325+ const data = await rosetta .exportTranslations (locale );
326326 return NextResponse .json (data );
327327}
328328
329- // POST /api/i18n /export - Import translations
329+ // POST /api/rosetta /export - Import translations
330330export async function POST(req : Request ) {
331331 const { locale, data } = await req .json ();
332- const count = await i18n .importTranslations (locale , data );
332+ const count = await rosetta .importTranslations (locale , data );
333333 return NextResponse .json ({ imported: count });
334334}
335335```
@@ -359,12 +359,12 @@ export function TranslationDashboard() {
359359 const [selectedLocale, setSelectedLocale] = useState (' zh-TW' );
360360
361361 useEffect (() => {
362- fetch (' /api/i18n /sources' ).then (r => r .json ()).then (setSources );
363- fetch (' /api/i18n /stats' ).then (r => r .json ()).then (setStats );
362+ fetch (' /api/rosetta /sources' ).then (r => r .json ()).then (setSources );
363+ fetch (' /api/rosetta /stats' ).then (r => r .json ()).then (setStats );
364364 }, []);
365365
366366 const handleTranslate = async (source : Source ) => {
367- const res = await fetch (' /api/i18n /translate' , {
367+ const res = await fetch (' /api/rosetta /translate' , {
368368 method: ' POST' ,
369369 headers: { ' Content-Type' : ' application/json' },
370370 body: JSON .stringify ({
@@ -375,20 +375,20 @@ export function TranslationDashboard() {
375375 });
376376 const { translation } = await res .json ();
377377 // Refresh sources
378- fetch (' /api/i18n /sources' ).then (r => r .json ()).then (setSources );
378+ fetch (' /api/rosetta /sources' ).then (r => r .json ()).then (setSources );
379379 };
380380
381381 const handleBatchTranslate = async () => {
382382 const untranslated = sources .filter (s => ! s .translations [selectedLocale ]);
383- await fetch (' /api/i18n /translate/batch' , {
383+ await fetch (' /api/rosetta /translate/batch' , {
384384 method: ' POST' ,
385385 headers: { ' Content-Type' : ' application/json' },
386386 body: JSON .stringify ({
387387 items: untranslated .map (s => ({ hash: s .hash , text: s .text , context: s .context })),
388388 locale: selectedLocale ,
389389 }),
390390 });
391- fetch (' /api/i18n /sources' ).then (r => r .json ()).then (setSources );
391+ fetch (' /api/rosetta /sources' ).then (r => r .json ()).then (setSources );
392392 };
393393
394394 return (
@@ -479,10 +479,10 @@ export function TranslationDashboard() {
479479
480480### Server (` @sylphx/rosetta/server ` )
481481
482- #### ` I18n ` class
482+ #### ` Rosetta ` class
483483
484484``` typescript
485- const i18n = new I18n ({
485+ const rosetta = new Rosetta ({
486486 storage: StorageAdapter , // Required: your storage adapter
487487 translator?: TranslateAdapter , // Optional: for auto-translation
488488 defaultLocale?: string , // Default: 'en'
@@ -491,33 +491,33 @@ const i18n = new I18n({
491491});
492492
493493// Core methods
494- await i18n .init (fn ) // Initialize context and run function
495- await i18n .getClientData () // Get data for client hydration
496- await i18n .loadTranslations (locale ) // Load translations for a locale
494+ await rosetta .init (fn ) // Initialize context and run function
495+ await rosetta .getClientData () // Get data for client hydration
496+ await rosetta .loadTranslations (locale ) // Load translations for a locale
497497
498498// Source/translation management
499- await i18n .getSources () // Get all source strings
500- await i18n .getUntranslated (locale ) // Get untranslated strings for locale
501- await i18n .saveTranslation (locale , text , translation , context ? )
499+ await rosetta .getSources () // Get all source strings
500+ await rosetta .getUntranslated (locale ) // Get untranslated strings for locale
501+ await rosetta .saveTranslation (locale , text , translation , context ? )
502502
503503// Auto-translation
504- await i18n .generateTranslation (text , locale , context ? )
505- await i18n .generateAndSave (text , locale , context ? )
506- await i18n .generateAllUntranslated (locale , onProgress ? )
507- await i18n .batchTranslate (items , locale )
504+ await rosetta .generateTranslation (text , locale , context ? )
505+ await rosetta .generateAndSave (text , locale , context ? )
506+ await rosetta .generateAllUntranslated (locale , onProgress ? )
507+ await rosetta .batchTranslate (items , locale )
508508
509509// Admin methods
510- await i18n .getSourcesWithStatus (locales ) // Get sources with translation status
511- await i18n .getStats (locales ) // Get translation statistics
512- await i18n .markAsReviewed (hash , locale )
513- await i18n .saveTranslationByHash (locale , hash , text , options ? )
514- await i18n .exportTranslations (locale )
515- await i18n .importTranslations (locale , data , options ? )
510+ await rosetta .getSourcesWithStatus (locales ) // Get sources with translation status
511+ await rosetta .getStats (locales ) // Get translation statistics
512+ await rosetta .markAsReviewed (hash , locale )
513+ await rosetta .saveTranslationByHash (locale , hash , text , options ? )
514+ await rosetta .exportTranslations (locale )
515+ await rosetta .importTranslations (locale , data , options ? )
516516
517517// Utilities
518- await i18n .getAvailableLocales () // Get locales that have translations (from DB)
519- i18n .getDefaultLocale () // Get default locale
520- i18n .invalidateCache () // Clear translation cache
518+ await rosetta .getAvailableLocales () // Get locales that have translations (from DB)
519+ rosetta .getDefaultLocale () // Get default locale
520+ rosetta .invalidateCache () // Clear translation cache
521521` ` `
522522
523523#### ` t (text , params ? )` function
@@ -539,11 +539,11 @@ getTranslationsForClient() // Get translations for client provider
539539### React ( ` @sylphx / rosetta - react ` )
540540
541541` ` ` tsx
542- import { I18nProvider , useT , useLocale } from ' @sylphx/rosetta-react' ;
542+ import { RosettaProvider , useT , useLocale } from ' @sylphx/rosetta-react' ;
543543
544- < I18nProvider locale = " en" translations = {translations }>
544+ < RosettaProvider locale = " en" translations = {translations }>
545545 {children }
546- < / I18nProvider >
546+ < / RosettaProvider >
547547
548548const t = useT (); // Get translation function
549549const locale = useLocale (); // Get current locale
0 commit comments