React reference
Ways
Root props
Common root props:
| Prop | Kiểu | Ghi chú |
|---|---|---|
apiKey | chuỗi | Bắt buộc. |
ngôn ngữ | chuỗi | Ngôn ngữ mục tiêu hiện tại. |
baseLocale | chuỗi | Ngôn ngữ nguồn. |
persistLocaleCookie | boolean | Default locale-cookie policy for the root runtime. |
bối cảnh | chuỗi | đối tượng | Optional root context. |
cacheTtl | số | Cache TTL for translation requests. |
messageFormatter | 'waysParser' | 'none' | fn | Parser or formatter override. |
suspenseTimeoutMs | số | Thời gian tối đa cho phép render bị chặn trước khi việc render fallback tiếp tục. |
fetcher | kiểu của fetch | Triển khai fetch tùy chỉnh. |
acceptedLocales | string[] | Optional explicit locale list. |
Scoped props
Nested scopes accept:
| Prop | Kiểu | Ghi chú |
|---|---|---|
bối cảnh | chuỗi | đối tượng | Bắt buộc. |
ngôn ngữ | chuỗi | Có sẵn, nhưng hãy dùng một root lồng nhau cho một phiên locale biệt lập. |
baseLocale | chuỗi | Ghi đè locale nguồn tuỳ chọn cho cây con. |
components | Record<string, component> | Components used inside translatable content. |
T
T is the JSX-first translation primitive.
| Prop | Kiểu | Ghi chú |
|---|---|---|
children | ReactNode | Bắt buộc. |
biến | Bản ghi<string, unknown> | Interpolation input. |
bối cảnh | chuỗi | đối tượng | Optional leaf context override. |
components | Record<string, component> | Component mapping for rich content. |
fixed | boolean | Skip translation for fixed branding-like content. |
useT()
useT() returns a translation function for strings, attributes, and logic.
const t = useT();
const label = t('Save changes');Runtime hooks
useTranslatedMemo()
A memoized value that recomputes when translations change.
useTranslationLoading()
Returns true while the current context is still loading.
useCurrentLocale()
Đọc locale đã chọn cho runtime gốc hiện tại.
useTargetLocale()
Đọc locale đích đang hoạt động cho phạm vi hiện tại.
useBaseLocale()
Đọc locale nguồn cho runtime gốc hiện tại.
useSetCurrentLocale()
Returns the setter for the root runtime locale.
useAcceptedLocales()
Đọc danh sách locale đã chấp nhận đã được phân giải từ runtime gốc.
LanguageSwitcher
Common props:
| Prop | Kiểu | Ghi chú |
|---|---|---|
currentLocale | chuỗi | Controlled locale. |
onLocaleChange | (locale) => void | Change handler. |
direction | 'up' | 'down' | Menu direction. |
styles / classNames | object | Styling overrides. |
unstyled | boolean | Disable built-in styles. |
Utility exports
@18ways/react also re-exports:
fetchAcceptedLocalesfetchConfigresolveOrigin