Tác giả:
    Ngày tạo:2026-09-19Cập nhật lần cuối:2026-09-19

    Gói remix-intlayer

    Gói remix-intlayer cung cấp các công cụ cần thiết để tích hợp Intlayer vào các ứng dụng Remix 3. Gói bao gồm middleware để phát hiện locale của yêu cầu, quyền truy cập vào context của yêu cầu, và các hook để lấy từ điển và quản lý locale.

    Cài đặt

    bash
    npm install remix-intlayer
    

    Các Exports của gói

    Middleware

    ExportLoạiMô tảTài liệu liên quan
    intlayerHàm MiddlewareMiddleware cho Remix 3 giúp phát hiện locale của yêu cầu, quản lý chuyển hướng và điền vào context yêu cầu.Middleware intlayer

    Lưu trữ Context

    ExportLoạiMô tảTài liệu liên quan
    IntlayerKhóa RequestContext / Lưu trữKhóa context yêu cầu được sử dụng để lấy trạng thái Intlayer từ context yêu cầu Remix 3 (context.get(Intlayer)).Context Intlayer

    Hooks

    ExportLoạiMô tảTài liệu liên quan
    useIntlayerHookLấy và xử lý nội dung từ điển theo khóa cho locale hiện tại của yêu cầu.Hook useIntlayer
    useDictionaryHookTrả về nội dung của đối tượng từ điển đã import tương ứng với locale hiện tại của yêu cầu.Hook useDictionary
    useLocaleHookCung cấp quyền truy cập vào locale yêu cầu hiện tại, locale mặc định và danh sách locale có sẵn.Hook useLocale

    Bắt đầu nhanh

    Cấu hình Router với Middleware

    src/server.ts
    import { createRouter } from "remix/router";
    import { intlayer } from "remix-intlayer";
    
    export const router = createRouter({
      middleware: [intlayer()],
    });
    

    Sử dụng nội dung trong View và Component

    src/views/home.ts
    import { useIntlayer } from "remix-intlayer";
    
    export const HomeView = () => {
      const content = useIntlayer("home");
    
      return `<h1>${content.title}</h1><p>${content.description}</p>`;
    };