React reference

Ways

Root props

Common root props:

PropKiểuGhi chú
apiKeychuỗiBắt buộc.
ngôn ngữchuỗiNgôn ngữ mục tiêu hiện tại.
baseLocalechuỗiNgôn ngữ nguồn.
persistLocaleCookiebooleanDefault locale-cookie policy for the root runtime.
bối cảnhchuỗi | đối tượngOptional root context.
cacheTtlsốCache TTL for translation requests.
messageFormatter'waysParser' | 'none' | fnParser or formatter override.
suspenseTimeoutMssốThời gian tối đa cho phép render bị chặn trước khi việc render fallback tiếp tục.
fetcherkiểu của fetchTriển khai fetch tùy chỉnh.
acceptedLocalesstring[]Optional explicit locale list.

Scoped props

Nested scopes accept:

PropKiểuGhi chú
bối cảnhchuỗi | đối tượngBắt buộc.
ngôn ngữchuỗiCó sẵn, nhưng hãy dùng một root lồng nhau cho một phiên locale biệt lập.
baseLocalechuỗiGhi đè locale nguồn tuỳ chọn cho cây con.
componentsRecord<string, component>Components used inside translatable content.

T

T is the JSX-first translation primitive.

PropKiểuGhi chú
childrenReactNodeBắt buộc.
biếnBản ghi<string, unknown>Interpolation input.
bối cảnhchuỗi | đối tượngOptional leaf context override.
componentsRecord<string, component>Component mapping for rich content.
fixedbooleanSkip translation for fixed branding-like content.

useT()

useT() returns a translation function for strings, attributes, and logic.

tsx
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:

PropKiểuGhi chú
currentLocalechuỗiControlled locale.
onLocaleChange(locale) => voidChange handler.
direction'up' | 'down'Menu direction.
styles / classNamesobjectStyling overrides.
unstyledbooleanDisable built-in styles.

Utility exports

@18ways/react also re-exports:

  • fetchAcceptedLocales
  • fetchConfig
  • resolveOrigin
Đang đổi ngôn ngữ
Tài liệu tham chiếu React