ืืืฃ ืืื ืืฉ ืชืื ืืช ืืคืืืงืฆืื ืืืื ื.
ืฉืืื ืืช ืฉืืืชืื ืืงืืื ืกืืืื ืฉื ืืืกืื ืขื ืืื ืืคื ืื ืืืฃ ืืื ืืืกืคืง ื-AI ืฉืชืืืจื
ืืืกืืืจืืืช ืืจืกืืืช
- "ืขืืืื ืืฉืืืืฉ ื-API ืฉื useIntlayer ื-Solid ืืืืฉื ืืฉืืจื ืืืืคืืื ืื"v8.9.04.5.2026
- "ืืืกืคืช ืคืงืืืช init"v7.5.930.12.2025
- "ืืืกืืืจืื ืจืืฉืื ืืช"v5.5.1029.6.2025
ืืชืืื ืฉื ืืืฃ ืืื ืชืืจืื ืืืืฆืขืืช AI.
ืฆืคืืื ืืืจืกื ืืืืจืื ื ืฉื ืืชืืื ืืืงืืจื ืืื ืืืืชืื ืืฉ ืืื ืจืขืืื ืืฉืืคืืจ ืืชืืขืื ืืื, ืื ืชืืกืกื ืืชืจืื ืขื ืืื ืืืฉืช Pull Request ื-GitHub.
ืงืืฉืืจ GitHub ืืชืืขืืืืขืชืงืช ื-Markdown ืฉื ืืืกืื ืืืื
ืชืจืืื ืืชืจ Create React App ืืืืฆืขืืช Intlayer
ืจืื ืืช ืชืื ืืช ืืืคืืืงืฆืื ื-GitHub.
ืืืืข ืืืืืจ ื-Intlayer ืขื ืคื ื ืืืืคืืช?
ืืืฉืืืื ืืคืชืจืื ืืช ืืืืืืืื ืืื react-i18next ืื i18next,โ Intlayer ืืืืขื ืขื ืืืคืืืืืืฆืืืช ืืืื ืืช ืืืื:
Intlayer ืืืชืืืช ืืคืขืื ืืฆืืจื ืืืฉืืืช ืขื React ืขื ืืื ืืชื ืืืืจืช ืชืืื ืืจืืช ืืจืืื (component-level scoping), ืืขืื ืช ืชืจืืืืื ืขืฆืื (lazy-loading) ืืื ืืืืืืืช ืืืจืืฉืืช ืืืจืืืช ืืื ืืื (i18n) ืืงื ื ืืืื ืจืื.
ืืืงืื ืืืขืื ืงืืืฆื JSON ืขืฆืืืื ืืชืื ืืืคืื ืฉืืื, ืืขื ื ืจืง ืืช ืืชืืื ืื ืืืฅ. Intlayer ืืกืืืขืช ืืืคืืืช ืืช ืืืื ื-bundle ืืืืคืื ืฉืืื ืืขื 50%.
ืืืืจืช ืชืืื ืืชืืื ืืจืืช ืืจืืื ืืคืฉืืช ืืช ืืชืืืืงื ืืืคืืืงืฆืืืช ืืืืืืช. ื ืืชื ืืฉืืคื ืื ืืืืืง ืชืืงืืืช ืคืืฆ'ืจ ืืืืืช ืืืื ืืฉืืช ืืขืืืก ืืื ืืื ืฉื ืกืงืืจืช ืื ืืกืืก ืงืื ืืชืืื ืฉืืื. ืื ืืกืฃ, Intlayer ืืกืคืงืช ืืืคืืกืืืช ืืืื (fully typed) ืืื ืืืืืื ืืช ืชืงืื ืืช ืืชืืื.
ืืืงืื ืืชืืื ืืฆื ืืจืืืืื ืืฆืืฆื ืืช ืืืงืฉืจ ืื ืืจืฉ ืขืืืจ ืืืืื ืฉืคื ืืืืืื (LLMs). Intlayer ืืกืคืงืช ืื ืืืืืช ืืืื ืืืื CLI ืืืืืงืช ืชืจืืืืื ืืกืจืื, LSP, MCP ื-agent skills, ืืื ืืืคืื ืืช ืืืืืืช ืืคืืชืื ืืืืงื ืขืื ืืืชืจ ืขืืืจ ืกืืื ื AI.
ืืฉืชืืฉื ืืืืืืืฆืื ืืชืจืืื ืืฆืื ืืจ ื-CI/CD ืฉืืื ืืืืฆืขืืช ื-LLM ืฉืืืจืชื, ืืขืืืช ืกืคืง ื-AI ืฉืืื. Intlayer ืืฆืืขื ืื ืืกืฃ ืืืืจ (compiler) ืืืืืืืฆืื ืฉื ืืืืืฅ ืชืืื, ืืื ืคืืืคืืจืืช ืืื ืืืืคืฉืจืช ืชืจืืื ืืจืงืข.
ืืืืืจ ืงืืืฆื JSON ืืืืืื ืืจืืืืื ืขืืื ืืืจืื ืืืขืืืช ืืืฆืืขืื ืืชืืืืชืืืช. Intlayer ืืืฆืขืช ืืืคืืืืืืฆืื ืฉื ืืขืื ืช ืืชืืื ืืืื ืืื ืืื.
ืืขืืจ ืืืืืชื ืคืชืจืื i18n,โ Intlayer ืืกืคืงืช ืขืืจื ืืืืชื ืืืืกืื ืขืฆืื ื-ืืขืจืืช CMS ืืืื ืืืกืืืขืื ืื ืื ืชืืื ืจื-ืืฉืื ื ืืืื ืืืช, ืืืืคืฉืจืื ืฉืืชืืฃ ืคืขืืื ืืืง ืขื ืืชืจืืืื, ืืืชืื ืชืืื ืืืืจื ืฆืืืช ื ืืกืคืื. ื ืืชื ืืืืกื ืชืืื ืืืืคื ืืงืืื ื/ืื ืืจืืืง.
ืืืจืื ืฉืื ืืืจ ืฉืื ืืืืืจืช Intlayer ืืืคืืืงืฆืืืช React
ืืชืงื ืช ืชืืืืืช
ืืชืงืื ื ืืช ืืืืืืืช ืื ืืจืฉืืช ืืืืฆืขืืช npm:
bashืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
ืืืื
--interactiveืืื ืืืคืฆืืื ืื. ืืฉืชืืฉื ื-intlayer-cli initืื ืืชื ืกืืื AI.ืคืงืืื ืื ืชืืื ืืช ืืกืืืื ืฉืืื ืืชืชืงืื ืืช ืืืืืืืช ืื ืืจืฉืืช. ืืืืืื:
bashืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
intlayer
ืืืืืช ืืืืื ืืืกืคืงืช ืืื ืืื ืืื ืื ืืืื ืชืฆืืจื, ืชืจืืื, ืืฆืืจืช ืชืืื, ืืจื ืกืคืืืฆืื ื-ืคืงืืืืช CLI.
react-intlayer
ืืืืืื ืืืฉืืืช ืืช Intlayer ืืืคืืืงืฆืืืช React. ืืื ืืกืคืงืช ืกืคืงื ืืงืฉืจ (context providers) ื-hooks ืขืืืจ ืืื ืืื ื-React.
react-scripts-intlayer
ืืืืืช ืืช ืืคืงืืืืช ืืืชืืกืคืื ืฉื
react-scripts-intlayerืืฉืืืื Intlayer ืืืคืืืงืฆืืืช ืืืืกืกืืช Create React App. ืชืืกืคืื ืืื ืืืืกืกืื ืขื craco ืืืืืืื ืชืฆืืจื ื ืืกืคืช ืขืืืจ ืืืื ืืืจ Webpack.
ืืืืจืช ืืคืจืืืงื ืฉืืื
ืฆืจื ืงืืืฅ ืืืืจืืช ืืื ืืืืืืจ ืืช ืฉืคืืช ืืืคืืืงืฆืื:
intlayer.config.tsืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
import { Locales, type IntlayerConfig } from "intlayer"; const config: IntlayerConfig = { internationalization: { locales: [ Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH, // ืฉืืจ ืืฉืคืืช ืฉืืื ], defaultLocale: Locales.ENGLISH, }, }; export default config;ืืืืฆืขืืช ืงืืืฅ ืชืฆืืจื ืื, ืชืืืื ืืืืืืจ ืืชืืืืช URL ืืงืืืืืช, ืืคื ืืืช middleware, ืฉืืืช ืขืืืืืช, ืืืงืื ืืกืืืืืช ืฉื ืงืืืฆื ืืฆืืจืช ืืชืืื, ืืืืื ืืืืื ืฉื Intlayer ืืืกืืฃ ืืขืื. ืืจืฉืืื ืืืืื ืฉื ืืคืจืืืจืื ืืืืื ืื, ืขืืื ื ืืชืืขืื ืืชืฆืืจื.
ืฉืืืื Intlayer ืืืืืจืืช ื-CRA ืฉืืื
ืฉื ื ืืช ืืกืงืจืืคืืื ืฉืืื ืืฉืืืืฉ ื-react-intlayer:
package.jsonืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
ืืกืงืจืืคืืื ืฉื
react-scripts-intlayerืืืืกืกืื ืขื CRACO. ืชืืืื ืื ืืืืฉ ืืืืจื ืืืชืืืช ืืืฉืืช ืืืืืกืกืช ืขื ืชืืกืฃ ื-craco ืฉื intlayer. ืจืื ืืืืื ืืื.ืืฆืืจื ืขื ืืชืืื ืฉืืื
ืฆืจื ืื ืืื ืืช ืืฆืืจืืช ืืชืืื ืฉืืื ืืืืกืื ืืชืจืืืืื:
src/app.content.tsxืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
import { t, type Dictionary } from "intlayer"; import React, { type ReactNode } from "react"; const appContent = { key: "app", content: { getStarted: t<ReactNode>({ he: ( <> ืขืจืื ืืช <code>src/App.tsx</code> ืืฉืืจื ืืื ืืืขืื ืืืืฉ </> ), en: ( <> Edit <code>src/App.tsx</code> and save to reload </> ), fr: ( <> รditez <code>src/App.tsx</code> et enregistrez pour recharger </> ), es: ( <> Edita <code>src/App.tsx</code> y guarda para recargar </> ), }), reactLink: { href: "https://reactjs.org", content: t({ he: "ืืืื React", en: "Learn React", fr: "Apprendre React", es: "Aprender React", }), }, }, } satisfies Dictionary; export default appContent;ืืฆืืจืืช ืืชืืื ืฉืืื ืืืืืืช ืืืืืช ืืืืืจืืช ืืื ืืงืื ืืืคืืืงืฆืื, ืื ืขืื ืื ืืืืืืช ืืกืคืจืืืช
contentDir(ืืืจืืจืช ืืืื,./src) ืืชืืืืืช ืืกืืืืช ืงืืืฅ ืืฆืืจืช ืืชืืื (ืืืจืืจืช ืืืื,.content.{json,ts,tsx,js,jsx,mjs,cjs,md,mdx,yaml,yml}).ืืคืจืืื ื ืืกืคืื, ืขืืื ื ืืชืืขืื ืืฆืืจืช ืชืืื.
ืื ืงืืืฅ ืืชืืื ืฉืืื ืืืื ืงืื TSX, ืืืืืฅ ืืืืื
import React from "react";ืืงืืืฅ ืืชืืื.ืฉืืืืฉ ื-Intlayer ืืงืื ืฉืืื
ืืฉื ืืืืืื ื ืืชืืื ืฉืืื ืืื ืจืืื ืืืคืืืงืฆืื:
src/App.tsxืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
import logo from "./logo.svg"; import "./App.css"; import type { FC } from "react"; import { IntlayerProvider, useIntlayer } from "react-intlayer"; const AppContent: FC = () => { const content = useIntlayer("app"); return ( <div className="App"> <img src={logo} className="App-logo" alt="logo" /> {content.getStarted} <a className="App-link" href={content.reactLink.href.value} target="_blank" rel="noopener noreferrer" > {content.reactLink.content} </a> </div> ); }; const App: FC = () => ( <IntlayerProvider> <AppContent /> </IntlayerProvider> ); export default App;ืืขืจื: ืื ืืจืฆืื ืื ืืืฉืชืืฉ ืืชืืื ืฉืืื ืืืืคืืื ืืืจืืืชื (
string), ืืืืalt,title,href,aria-labelืืืืืื, ืชืืืื ืืืฉืชืืฉ ืืขืจื ืฉื ืืคืื ืงืฆืื, ืืืื:tsxืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
ืืืืืข ื ืืกืฃ ืขื ื-hook ืืฉื
useIntlayer, ืขืืื ื ืืชืืขืื.ืฉืื ืื ืฉืคืช ืืชืืื ืฉืืื
ืืืคืฆืืื ืืืืื ืืฉื ืืช ืืช ืฉืคืช ืืชืืื, ืชืืืื ืืืฉืชืืฉ ืืคืื ืงืฆืื
setLocaleืืืกืืคืงืช ืขื ืืื ื-hook ืืฉืuseLocale. ืคืื ืงืฆืื ืื ืืืคืฉืจืช ืืงืืืข ืืช ืฉืคืช ืืืคืืืงืฆืื ืืืขืืื ืืช ืืชืืื ืืืชืื.src/components/LocaleSwitcher.tsxืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
import { Locales } from "intlayer"; import { useLocale } from "react-intlayer"; const LocaleSwitcher = () => { const { setLocale } = useLocale(); return ( <button onClick={() => setLocale(Locales.English)}> Change Language to English </button> ); };ืืืืืข ื ืืกืฃ ืขื ื-hook ืืฉื
useLocale, ืขืืื ื ืืชืืขืื.ืืืกืคืช ื ืืชืื ืืืชืื ืฉืคื ืืืคืืืงืฆืื ืฉืืื
ืืืคืฆืืื ืืืืืจืช ืฉืื ืื ืืื ืืืฆืืจ ื ืชืืืื ืืืืืืืื ืืื ืฉืคื. ืืืืจ ืฉืืืืฉื ืขืืืจ SEO ืืืชืืืืช URL ืืืชืืืืช ืืื ืืขื ืืืคืืฉ. ืืืืื:
plaintextืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
ืืืจืืจืช ืืืื, ืื ืชืืืื ืืื ื ืืืืืื ืงืืืืืช ืขืืืจ ืฉืคืช ืืจืืจืช ืืืืื. ืื ืืจืฆืื ืื ืืืืกืืฃ ืงืืืืืช ืืฉืคืช ืืจืืจืช ืืืืื, ืชืืืื ืืืืืืจ ืืช ืืืคืฉืจืืช
middleware.prefixDefaultื-trueืืืืืจืืช ืฉืืื. ืจืื ืืช ืชืืขืื ืืชืฆืืจื ืืืืืข ื ืืกืฃ.ืืื ืืืืกืืฃ ื ืืชืื ืืืชืื ืฉืคื ืืืคืืืงืฆืื ืฉืืื, ืชืืืื ืืืฆืืจ ืจืืื
LocaleRouterืฉืขืืืฃ ืืช ื ืชืืื ืืืคืืืงืฆืื ืืื ืื ื ืืชืื ืืืืกืก ืฉืคื. ืื ื ืืืืื ืืืืฆืขืืช React Router:src/components/LocaleRouter.tsxืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
// ืืืืื ืชืืืืืช ืืคืื ืงืฆืืืช ื ืืจืฉืืช import { type Locales, configuration, getPathWithoutLocale } from "intlayer"; // ืคืื ืงืฆืืืช ืขืืจ ืืืืคืืกืื ื-intlayer import type { FC, PropsWithChildren } from "react"; // ืืืคืืกื React ืขืืืจ ืจืืืืื ืคืื ืงืฆืืื ืืืื ื-props import { IntlayerProvider } from "react-intlayer"; // Provider ืขืืืจ ืืงืฉืจ ืืื ืืื import { BrowserRouter, Routes, Route, Navigate, useLocation, } from "react-router-dom"; // ืจืืืื Router ืื ืืืื ื ืืืื // ืืืืืฅ ืืืืจืืช ื-Intlayer const { internationalization, middleware } = configuration; const { locales, defaultLocale } = internationalization; /** * ืจืืื ืืืืคื ืืืืงืืืืฆืื ืืขืืืฃ ืจืืืื ืืื ืขื ืืงืฉืจ ืืฉืคื ืืืชืืื. * ืืื ืื ืื ืืืืื ืืืืืืช ืฉืคื ืขื ืืกืืก ืืชืืืช ื-URL. */ const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({ children, locale, }) => { const { pathname, search } = useLocation(); // ืงืืืช ื ืชืื ื-URL ืื ืืืื // ืงืืืขืช ืืฉืคื ืื ืืืืืช, ืขื ืืืจื ืืฉืคืช ืืจืืจืช ืืืืื ืื ืื ืกืืคืงื const currentLocale = locale ?? defaultLocale; // ืืกืจืช ืงืืืืืช ืืฉืคื ืืื ืชืื ืืื ืืืช ื ืชืื ืืกืืก const pathWithoutLocale = getPathWithoutLocale( pathname // ื ืชืื ื-URL ืื ืืืื ); /** * ืื middleware.prefixDefault ืืื true, ืฉืคืช ืืจืืจืช ืืืืื ืชืืื ืฆืจืืื ืืืืืช ืขื ืงืืืืืช. */ if (middleware.prefixDefault) { // ืืืืืช ืืฉืคื if (!locale || !locales.includes(locale)) { // ื ืืชืื ืืืืฉ ืืฉืคืช ืืจืืจืช ืืืืื ืขื ืื ืชืื ืืืขืืืื return ( <Navigate to={`/${defaultLocale}/${pathWithoutLocale}${search}`} replace // ืืืืคืช ืจืฉืืืช ืืืืกืืืจืื ืื ืืืืืช ืืืืฉื /> ); } // ืขืืืคืช ืืืืืื ื-IntlayerProvider ืืืืืจืช ืืฉืคื ืื ืืืืืช return ( <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider> ); } else { /** * ืืืฉืจ middleware.prefixDefault ืืื false, ืฉืคืช ืืจืืจืช ืืืืื ืืื ื ืืงืืืช ืงืืืืืช. * ืืฉ ืืืืื ืฉืืฉืคื ืื ืืืืืช ืชืงืคื ืืืื ื ืฉืคืช ืืจืืจืช ืืืืื. */ if ( currentLocale.toString() !== defaultLocale.toString() && !locales .filter( (locale) => locale.toString() !== defaultLocale.toString() // ืื ืืืืืช ืฉืคืช ืืจืืจืช ืืืืื ) .includes(currentLocale) // ืืืืงื ืื ืืฉืคื ืื ืืืืืช ืืืคืืขื ืืจืฉืืืช ืืฉืคืืช ืืชืงืคืืช ) { // ืืคื ืื ืืืืฉ ืื ืชืื ืืื ืงืืืืืช ืฉืคื return <Navigate to={`${pathWithoutLocale}${search}`} replace />; } // ืขืืืคืช ืืืืืื ื-IntlayerProvider ืืืืืจืช ืืฉืคื ืื ืืืืืช return ( <IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider> ); } }; /** * ืจืืื ืจืืืืจ ืืืืืืจ ื ืชืืืื ืกืคืฆืืคืืื ืืื ืฉืคื. * ืืื ืืฉืชืืฉ ื-React Router ืืื ืื ืื ื ืืืื ืืืจื ืืจ ืจืืืืื ืืืชืืืื ืืฉืคื. */ export const LocaleRouter: FC<PropsWithChildren> = ({ children }) => ( <BrowserRouter> <Routes> {locales .filter( (locale) => middleware.prefixDefault || locale !== defaultLocale ) .map((locale) => ( <Route // ืชืื ืืช ื ืชืื ืืืืืืช ืืฉืคื (ืืืฉื /en/, /fr/) ืืืชืืื ืืื ืื ืชืืืื ืฉืืืจืื path={`/${locale}/*`} key={locale} element={<AppLocalized locale={locale}>{children}</AppLocalized>} // ืขืืืคืช ืืืืืื ืื ืืืื ืฉืคื /> ))} { // ืื ืงืืืืืช ืขืืืจ ืฉืคืช ืืจืืจืช ืืืืื ืืืืืืช, ืจื ืืจ ืืช ืืืืืื ืืฉืืจืืช ืื ืชืื ืืฉืืจืฉ !middleware.prefixDefault && ( <Route path="*" element={ <AppLocalized locale={defaultLocale}>{children}</AppLocalized> } // ืขืืืคืช ืืืืืื ืื ืืืื ืฉืคื /> ) } </Routes> </BrowserRouter> );ืืืืจ ืืื, ืชืืืื ืืืฉืชืืฉ ืืจืืื
LocaleRouterืืืคืืืงืฆืื ืฉืืื:src/App.tsxืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
import { LocaleRouter } from "./components/LocaleRouter"; import type { FC } from "react"; // ... ืจืืื ื-AppContent ืฉืืื const App: FC = () => ( <LocaleRouter> <AppContent /> </LocaleRouter> );ืฉืื ืื ื-URL ืืขืช ืฉืื ืื ืฉืคื
ืืืคืฆืืื ืืืืื ืืฉื ืืช ืืช ื-URL ืืืฉืจ ืืฉืคื ืืฉืชื ื, ืชืืืื ืืืฉืชืืฉ ื-prop ืืฉื
onLocaleChangeืืืกืืคืง ืขื ืืื ื-hook ืืฉืuseLocale. ืืืงืืื, ื ืืชื ืืืฉืชืืฉ ื-hooks ืืฉืuseLocationื-useNavigateื-react-router-domืืื ืืขืืื ืืช ื ืชืื ื-URL.src/components/LocaleSwitcher.tsxืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
import { useLocation, useNavigate } from "react-router-dom"; import { Locales, getHTMLTextDir, getLocaleName, getLocalizedUrl, } from "intlayer"; import { useLocale } from "react-intlayer"; import { type FC } from "react"; const LocaleSwitcher: FC = () => { const { pathname, search } = useLocation(); // ืงืืืช ื ืชืื ื-URL ืื ืืืื. ืืืืืื: /fr/about?foo=bar const navigate = useNavigate(); const { locale, availableLocales, setLocale } = useLocale({ onLocaleChange: (locale) => { // ืื ืืืช ืืชืืืช ื-URL ืขื ืืฉืคื ืืืขืืืื ืช // ืืืืืื: /es/about?foo=bar const pathWithLocale = getLocalizedUrl(`${pathname}${search}`, locale); // ืขืืืื ื ืชืื ื-URL navigate(pathWithLocale); }, }); return ( <div> <button popoverTarget="localePopover">{getLocaleName(locale)}</button> <div id="localePopover" popover="auto"> {availableLocales.map((localeItem) => ( <a href={getLocalizedUrl(location.pathname, localeItem)} hrefLang={localeItem} aria-current={locale === localeItem ? "page" : undefined} onClick={(e) => { e.preventDefault(); setLocale(localeItem); }} key={localeItem} > <span> {/* ืืฉืคื - ืืืฉื FR */} {localeItem} </span> <span> {/* ืฉื ืืฉืคื ืืฉืคื ืขืฆืื - ืืืฉื Franรงais */} {getLocaleName(localeItem, locale)} </span> <span dir={getHTMLTextDir(localeItem)} lang={localeItem}> {/* ืฉื ืืฉืคื ืืฉืคื ืื ืืืืืช - ืืืฉื Francรฉs ืืฉืืฉืคื ืื ืืืืืช ืืืืืจืช ื-Locales.SPANISH */} {getLocaleName(localeItem)} </span> <span dir="ltr" lang={Locales.ENGLISH}> {/* ืฉื ืืฉืคื ืืื ืืืืช - ืืืฉื French */} {getLocaleName(localeItem, Locales.ENGLISH)} </span> </a> ))} </div> </div> ); };ืืคื ืืืช ืืชืืขืื:
ืขืืืื ืืืคืืื ื ืฉืคื ืืืืืื ื-HTML
ืืืคืฆืืื ืืืืืฉืจ ืืืคืืืงืฆืื ืฉืืื ืชืืืืช ืืืกืคืจ ืฉืคืืช, ืืืื ื ืืขืืื ืืช ืืืืคืืื ืื
langื-dirืืชืืืช<html>ืืื ืฉืืชืืืื ืืฉืคื ืื ืืืืืช. ืคืขืืื ืื ืืืืืื:- ื ืืืฉืืช (Accessibility): ืงืืจืื ืืกื ืืืื ืืืืืืืช ืืกืืืขืืช ืืกืชืืืื ืขื ืืืืคืืื
langืื ืืื ืืื ืืืืืช ืืืคืจืฉ ืืช ืืชืืื ืืืืืืง. - ืจืื ืืืจ ืืงืกื: ืืืืคืืื
dir(ืืืืื) ืืืืื ืฉืืืงืกื ืืจืื ืืจ ืืกืืจ ืื ืืื (ืืืฉื ืืฉืืื ืืืืื ืืื ืืืืช, ืืืืืื ืืฉืืื ืืขืืจืืช ืื ืืขืจืืืช), ืื ืฉืืืื ื ืืงืจืืืืช. - SEO: ืื ืืขื ืืืคืืฉ ืืฉืชืืฉืื ืืืืคืืื
langืืื ืืงืืืข ืืช ืฉืคืช ืืืฃ, ืื ืฉืขืืืจ ืืืฆืื ืืช ืืชืืื ืืืืชืื ืื ืืื ืืชืืฆืืืช ืืืืคืืฉ.
ืืืืฆืขืืช ืขืืืื ืืื ืื ืฉื ืืืคืืื ืื ืืื ืืขืช ืฉืื ืื ืฉืคื, ืืชื ืืืืืืื ืืืืื ืขืงืืืช ืื ืืืฉื ืืืฉืชืืฉืื ืืื ืืฉืคืืช ืื ืชืืืืช.
ืืืืืฉ ื-Hook
ืฆืจื hook ืืืชืื ืืืฉืืช ืื ืืืื ืืืคืืื ื ื-HTML. ื-hook ืืืืื ืืฉืื ืืื ืฉืคื ืืืขืืื ืืช ืืืืคืืื ืื ืืืชืื:
src/hooks/useI18nHTMLAttributes.tsxืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
import { useEffect } from "react"; import { useLocale } from "react-intlayer"; import { getHTMLTextDir } from "intlayer"; /** * ืืขืืื ืืช ืืืคืืื ื `lang` ื-`dir` ืฉื ืืืื ื ื-<html> ื-HTML ืืืชืื ืืฉืคื ืื ืืืืืช. * - `lang`: ืืืืืข ืืคืืคื ืื ืืื ืืขื ืืืคืืฉ ืืืื ืฉืคืช ืืืฃ. * - `dir`: ืืืืื ืืืืื ืงืจืืื ื ืืื (ืืืฉื 'ltr' ืืื ืืืืช, 'rtl' ืืขืืจืืช ืืืขืจืืืช). * * ืขืืืื ืืื ืื ืื ืืืื ื ืืจืื ืืืจ ืืงืกื ืชืงืื, ื ืืืฉืืช ื-SEO. */ export const useI18nHTMLAttributes = () => { const { locale } = useLocale(); useEffect(() => { // ืขืืืื ืืืคืืื ืืฉืคื ืืฉืคื ืื ืืืืืช. document.documentElement.lang = locale; // ืืืืจืช ืืืืื ืืืงืกื ืืืชืื ืืฉืคื ืื ืืืืืช. document.documentElement.dir = getHTMLTextDir(locale); }, [locale]); };ืฉืืืืฉ ื-Hook ืืืคืืืงืฆืื ืฉืืื
ืฉืืื ืืช ื-hook ืืจืืื ืืจืืฉื ืฉืืื ืื ืฉืืืคืืื ื ื-HTML ืืชืขืืื ื ืืื ืฉืื ืื ืฉืคื:
src/App.tsxืืขืชืงืช ืงืืืืขืชืงืช ืืงืื ืืืื
import type { FC } from "react"; import { IntlayerProvider, useIntlayer } from "react-intlayer"; import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes"; import "./App.css"; const AppContent: FC = () => { // ืืคืขืืช ื-hook ืืขืืืื ืืืคืืื ื lang ื-dir ืืชืืืช <html> ืืืชืื ืืฉืคื. useI18nHTMLAttributes(); // ... ืฉืืจ ืืจืืื ืฉืืื }; const App: FC = () => ( <IntlayerProvider> <AppContent /> </IntlayerProvider> ); export default App;ืืืืฆืขืืช ืืืืช ืฉืื ืืืื ืืื, ืืืคืืืงืฆืื ืฉืืื:
- ืชืืืื ืฉืืืคืืื ืืฉืคื (
lang) ืืฉืงืฃ ืืจืืื ืืช ืืฉืคื ืื ืืืืืช, ืืืจ ืืืฉืื ื-SEO ืืืืชื ืืืืช ืืืคืืคื. - ืชืชืืื ืืช ืืืืื ืืืงืกื (
dir) ืืืชืื ืืฉืคื, ืืชืฉืคืจ ืืช ืืงืจืืืืช ืืืฉืืืืฉืืืช ืขืืืจ ืฉืคืืช ืืขืืืช ืืืืื ื ืงืจืืื ืฉืื ืื. - ืชืกืคืง ืืืืื ื ืืืฉื ืืืชืจ, ืฉืื ืืื ืืืืืืืช ืืกืืืขืืช ืชืืืืืช ืืืืคืืื ืื ืืื ืืื ืืคืขืื ืืฆืืจื ืืืืืืช.
- ื ืืืฉืืช (Accessibility): ืงืืจืื ืืกื ืืืื ืืืืืืืช ืืกืืืขืืช ืืกืชืืืื ืขื ืืืืคืืื
ืืืืจืช TypeScript
Intlayer ืืฉืชืืฉืช ืืืจืืืช ืืืืืืื (module augmentation) ืืื ืืืื ืืช ืืืชืจืื ืืช TypeScript ืืืืคืื ืืช ืืกืืก ืืงืื ืฉืืื ืืืืง ืืืชืจ.


ืืืื ืฉืืืืจืืช ื-TypeScript ืฉืืื ืืืืืืช ืืช ืืืืคืืกืื ืฉื ืืฆืจื ืืืืืืืืช.
ืืขืชืงืช ืืงืื ืืืื
ืืืืจืช Git
ืืืืืฅ ืืืชืขืื ืืืงืืฆืื ืฉื ืืฆืจื ืขื ืืื Intlayer ืืื ืืื ืืข ืืช ืฉืืืจืชื ืืืืืจ ื-Git ืฉืืื.
ืืฉื ืื, ืืืกืืคื ืืช ืืืืจืื ืืืื ืืงืืืฅ .gitignore:
ืืขืชืงืช ืืงืื ืืืื
ืืจืืืช VS Code
ืืื ืืฉืคืจ ืืช ืืืืืืช ืืคืืชืื ืฉืืื ืขื Intlayer, ืชืืืื ืืืชืงืื ืืช ืืจืืืช Intlayer ืืจืฉืืืช ื-VS Code.
ืืจืืื ืื ืืกืคืงืช:
- ืืฉืืื ืืืืืืืืช (Autocompletion) ืขืืืจ ืืคืชืืืช ืชืจืืื.
- ืืืืื ืฉืืืืืช ืืืื ืืืช ืขืืืจ ืชืจืืืืื ืืกืจืื.
- ืชืฆืืื ืืงืืืื ืืืืืขืช (Inline previews) ืฉื ืชืืื ืืชืืจืื.
- ืคืขืืืืช ืืืืจืืช (Quick actions) ืืืฆืืจื ืืขืืืื ืคืฉืืืื ืฉื ืชืจืืืืื.
ืืคืจืืื ื ืืกืคืื ืขื ืืฉืืืืฉ ืืืจืืื, ืขืืื ื ืืชืืขืื ืืจืืืช ื-VS Code ืฉื Intlayer.
ืืืขืืืง ืขืื
ืืื ืืืขืืืง ืขืื, ืชืืืื ืืืืืืข ืืช ืืขืืจื ืืืืืชื ืื ืืืืฆืื ืืช ื ืืืื ืืชืืื ืฉืืื ืืืืฆื ืืืืฆืขืืช ื-CMS.
ืฉืืืืช ื ืคืืฆืืช
react-i18next/i18next: ืื ืคืืฆืื ืืืืชืจ, ืขื ืืจืืื ืฉืืืช (namespaces) ืฉื JSON ืื ืืขื ืื ืืืื ืจืืฆื.react-intlื-Lingui: ืคืืจืื ืืืืขืืช ICU, ืืืืกืกื ืืืืืฅ (extraction).Intlayer: ืืคืชืจืื ืืืชืงืื ืืืืชืจ. ืชืืื ืืืฆืืจ ืืื ืืงืื ืืืกืืก ืืงืื ืฉืืื (ืืฆื ืื ืจืืื ืื ืืืืคื ืืจืืื) ืืืงืืืคื ืืืื ืืื ืืื ืืืืฆืขืืชreact-scripts-intlayer, ืืขื ืืืคืืกืืืช ืืืื, ืขื ืชืจืืื ื-AI, ืขืืจื ืืืืชื ื-CMS.
ืืืืืช Create React App ืขืืืคืช ืชืฆืืจืช webpack ืืฉืื, ืืืื ืืฉืืืื ืืชืืฆืข ืืืืฆืขืืช ืชืืืืฃ ืชืืื react-scripts-intlayer ืืืงืื react-scripts, ืืื ืืืืฆืขืืช ืชืืกืฃ ืฉืืชื ืจืืฉืืื ืืขืฆืืื. ืจืื ืืืืข Intlayer ืืืช ืืืื ืืืืฆืืขืื (benchmark).
ืืจืื ืคืืืช ืืืืืจื ืืืืกืกืช ืืจืืื ืฉืืืช (namespaces), ืืืืืื ืฉืืฃ ืืื ื ืืืจืื ืืขืืื ืงืืืื ืฉืืื ื ืืจื ืืจ. ืืืืืจ ืืืื ืืื ืืื ืืืืืฃ ืงืจืืืืช useIntlayer ืืจืฉืืืืช ืืืืืื ืืืืืืงืืช ืฉืืจืืื ืืฉืชืืฉ ืืื, ืื ืฉืืคืชืืืช ืฉืืื ื ืืฉืืืืฉ ืืฉืคืืช ืฉืืื ื ืืฉืืืืฉ ืืืฉืืืื, ื-ืืืืื ืื ืืื ืืืื ืืคืฆืืื ืืช ืืฉืืจ ืืคื ืฉืคื. ืืืฉืืืื ืืืืืคืืช ืืืงืืืืืช, Intlayer ืืคืืืชื ืืช ืืืื ื-bundle ืืืืฃ ืืขื 50%. ืจืื ืืืคืืืืืืฆืืืช bundle ืืืช ืืืื ืืืืฆืืขืื.
ืื, ืืืฉื ื ืฉื ื ืืกืืืืื. ืชืืืื ืืืืจ ืืช ืืชืืื ืืืืจืื ืืืืฆืขืืช ืืืจืื ืืืืืจื ื-react-i18next ืื ืืืจืื ืืืืืจื ื-i18next. ืืืืืคืื, ืชืืืื ืืฉืืืจ ืขื ื-API ืืงืืื ืฉืืื ืืืืืื: ืืชืืื ืืชืืืืืช (compat adapters) ืืืฉืคืื ืืืืืง ืืช ืืืชื ื-API ืฉื react-i18next, react-intl ื-i18next, ืื ืืืืฉืื ืืืืฆืขืืช ืืืืื ื Intlayer, ืื ืฉืืืืืืืื ืืฉืชื ืื ืืงืื ืืจืืื ื ืฉืืจ ืืขืื ื.
ืื. ืชืืกืฃ ืกื ืืจืื ื-JSON ืฉืืืจ ืขื ืงืืืฆื /messages/{locale}/{namespace}.json ืืืงืืจ ืืืืช ืืืืืฆืจ ืืื ืืืืื ื Intlayer, ืืฉื ื ืืืืืื ืื. ืชืืกืฃ ืกื ืืจืื ื-PO ืขืืฉื ืืช ืืืชื ืืืืจ ืขืืืจ ืงืืืืื gettext, ื-ืงืืฆืื ืืคื ืฉืคื (per locale files) ืืืคืฉืจืื ืืคืฆื ืชืืื ืืคื ืฉืคื ืืืงืื ืืงืืฅ ืฉืคืืช ืืงืืืฅ ืืืื.
ืื. ืืจืืฆื npx intlayer extract ื-Intlayer ืชืงืจื ืืช ืืจืืืืื ืฉืืื, ืชืืืฅ ืืช ืืืืจืืืืช ืืืืฆืืืช ืืืฉืชืืฉ ืืชืืชืื ืงืืืฅ .content ืืฆื ืื ืจืืื, ืื ืฉืชืกืงืจื diff ืืืงืื ืืืขืชืืง ืืืจืืืืช ืืงืืืื ืืืช ืืืช.
ืขืืืจ ืชืืืื ืืืืืืื ืืืืืืื, ืืืืืจ ืฉื Intlayer (Intlayer Compiler) ืืืฆืข ืืช ืืืชื ืคืขืืื ืืืื ืืื ืืื: ืืื ืกืืจืง ืืช ืงืื ืืืงืืจ ืฉื ื-JSX, TSX, Vue ื-Svelte ืฉืืื ืืื ืฉืื ืื, ืืืืฆืจ ืืช ืืืืืื ืื ืืฉืืืจ ืขืืืื ืืกืื ืืจื ืื ืืืืฆืขืืช ืืืืคืช ืืืืืืื ืืื (HMR), ืื ืฉืืื ืฆืืจื ืืชืืืง ืืคืชืืืช ืืื ืืช ืืื.
ืฉืชื ืืืืืืช ืฉืืืื ืืืืืจ ืืคื ื ืืคืขืืช ืืืืืจ: ืืื ืคืืขื ืืืืฆืขืืช ื ืืชืื ืกืืื, ืื ืฉืืืจืืืืช ืฉืงืืืืืช ืจืง ืืืื ืจืืฆื, ืืืื ืงืืื ืฉืืืื ื-API ืื ืฉืืืช ื-CMS, ืืื ื ื ืืืฉืืช ืื. ืื ืืกืฃ, ืขืืื ืืืืืื ืืื ืืงืกื ืืืืฆื ืืืฉืชืืฉ ืืืื ืืืืืงืช ืืคืืืงืฆืื ืืื className="active" ืื ืงืื ืกืืืืก, ืื ืฉืืืจืฉ ืืื ืืืืืจืื (annotations) ืืืกืืก ืงืื ืืืื. ืคืงืืืช extract ื ืื ืขืช ืืฉืชืืื ืืื ืฉืืื ืืฉืืืจื ืืชืื ืืชืืืื ืืืงืจื.
ืืืืฉื ืืืื, ืืืื ืืืคืฆืืื ืืืื:
- ืืจืืืช VS Code: ืงืคืืฆื ืืืคืชื
useIntlayerืื ืงืืืฅ ืืชืืื ืฉืืฆืืืจ ืขืืื, ืืืืืฅ ืชืืื ืืจืืื, ืืืจืฆืช build, fill, test, push ื-pull ืืืื ืืคืงืืืืช ืื ืืืฉืื ืืช Intlayer ืืืขืืืืช. - ืฉืจืช LSP: ืืืชื ืืืืขืืช ืืื ืขืืจื ืืชืืื ื-LSP, ืขื ืืขืืจ ืืืืืจื (go to definition), ืืืคืืฉ ืื ืืืคื ืืืช, ืชืฆืืื ืืงืืืื ืืจืืืืฃ (hover) ืฉื ืขืจื ืืชืืจืื, ืืฉืืื ืืืืืืืืช ืฉื ืืคืชืืืช ืืฉืืืช, ืืืชืจืื ืืืฉืจ ืืคืชื ืืื ื ืืืฆืืจ ืืฉืื ืืงืื. ืืื ืื ืืคืขื ื ืงืจืืืืช
i18next,react-i18next,next-intlื-use-intl, ืื ืฉืืกืืืข ืืืื ืืืืืจื. - ืฉืจืช MCP: ืืืฉืฃ ืืช ืืชืืขืื ืื-CLI ืฉื Intlayer ื-Cursor, VS Code, Claude Desktop, Claude Code ื-ChatGPT, ืื ืฉืขืืืจ ืืขื ื ืืชืื ืชืืขืื ืขืืื ื ืืืงืื ืื ืืฉ, ืืืืื ืืืจืืฅ ืคืงืืืืช ืืื
intlayer fillืืขืฆืื. - Agent skills: ืืืืื ืืืืช ืืืืงืืืช ืืืื
intlayer-config,intlayer-cliื-intlayer-content, ืืชืืกืคืช ืืืืื ืืช ืืืขืืืืช ืืื framework, ืืืืืืืช ืกืืื ืขื ืืขืจื ืื ืืชืื ืืืืคืืกื ืฆืืชื ืืชืืื ืฉืืื. - ืชืืกืฃ ESLint: ืืืื
no-raw-textืืชืจืืข ืขื ืืืจืืืืช ืืืื ืืช ืืงืื (hardcoded), ืขื ืืืืื ื ืืกืคืื ืขืืืจ ืืคืชืืืช ืืืืื ืกืืืืื ืืชืืื ืฉืืื ื ืืฉืืืืฉ.
