Đặt câu hỏi và nhận tóm tắt tài liệu bằng cách tham chiếu trang này và nhà cung cấp AI bạn chọn
Bằng cách tích hợp Intlayer MCP Server vào trợ lý AI ưa thích của bạn, bạn có thể truy xuất toàn bộ tài liệu trực tiếp từ ChatGPT, DeepSeek, Cursor, VSCode, v.v.
Xem tài liệu MCP ServerNội dung của trang này đã được dịch bằng AI.
Xem phiên bản mới nhất của nội dung gốc bằng tiếng AnhNếu bạn có ý tưởng để cải thiện tài liệu này, vui lòng đóng góp bằng cách gửi pull request trên GitHub.
Liên kết GitHub tới tài liệuSao chép Markdown của tài liệu vào bộ nhớ tạm
Insertion Content / Insertion in Intlayer
How Insertion Works
In Intlayer, insertion content is achieved through the insertion function, which identifies placeholder fields in a string (such as {{name}} or {{age}}) that can be replaced dynamically at runtime. This approach allows you to create flexible, template-like strings where specific parts of the content are determined by data passed in from your application.
When integrated with React Intlayer or Next Intlayer, you can simply provide the data object containing the values for each placeholder, and Intlayer will automatically render the content with the placeholders replaced.
Setting Up Insertion Content
To set up insertion content in your Intlayer project, create a content module that includes your insertion definitions. Below are examples in various formats.
Sao chép đoạn mã vào khay nhớ tạm (clipboard)
import { insert, type Dictionary } from "intlayer";const myInsertionContent = { key: "my_key", content: { myInsertion: insert( "Hello, my name is {{name}} and I am {{age}} years old!" ), },} satisfies Dictionary;export default myInsertionContent;Using Insertion Content with React Intlayer
To utilize insertion content within a React component, import and use the useIntlayer hook from the react-intlayer package. This hook retrieves the content for the specified key and allows you to pass in an object that maps each placeholder in your content to the value you wish to display.
Sao chép đoạn mã vào khay nhớ tạm (clipboard)
import type { FC } from "react";import { useIntlayer } from "react-intlayer";const InsertionComponent: FC = () => { const { myInsertion } = useIntlayer("my_key"); return ( <div> <p> { /* Output: "Hello, my name is John and I am 30 years old!" */ myInsertion({ name: "John", age: "30" }) } </p> <p> { /* You can reuse the same insertion with different values */ myInsertion({ name: "Alice", age: "25" }) } </p> </div> );};export default InsertionComponent;Additional Resources
For more detailed information on configuration and usage, refer to the following resources:
These resources offer further insights into the setup and usage of Intlayer across various environments and frameworks.