experimental-ciao-react
v1.1.17
Published
React components and hooks for ciao-tools - runtime translation support
Maintainers
Readme
@ciao-tools/react
React hooks and components for Ciao Tools translations.
Installation
npm install @ciao-tools/reactUsage
import { useCt, CiaoProvider, LanguageSwitcher } from "@ciao-tools/react";
import manifest from "./ciao-manifest.json";
function App() {
return (
<CiaoProvider manifest={manifest}>
<LanguageSwitcher />
<Content />
</CiaoProvider>
);
}
function Content() {
const ct = useCt();
return <h1>{ct("Hello, world!")}</h1>;
}Exports
Hooks
useCt()- Returns the translation functionuseLanguage()- Language state and controlsuseCurrentLanguage()- Current language codeuseSetLanguage()- Function to change languageuseAvailableLanguages()- List of available languagesuseIsLoading()- Loading stateuseIsReady()- Ready state
Components
CiaoProvider- Translation provider with CDN loadingCTContextBlock- Group related strings for contextTrans- Translate JSX with nested elementsLanguageSwitcher- Language selection UI
Utilities
interpolate()- String interpolation with formattinggetLanguageInfo()- Get language metadataLANGUAGE_DATA- Language names, native names, and flags
Documentation
See docs.ciao-tools.com/react for full documentation.
License
MIT
