react-locomigo
v1.1.0
Published
React SDK for Locomigo localization
Maintainers
Readme
react-locomigo
React SDK for Locomigo localization platform.
Installation
npm install react-locomigoUsage
import locomigo from "react-locomigo";
// Initialize with default options - automatically extracts all text from DOM
locomigo.initialize();
// Initialize with custom options
locomigo.initialize({
locale: "es-ES",
supportedLocales: ["en-US", "es-ES", "fr-FR"],
realtime: false,
});
// Access extracted texts and translation matrix
const extractedTexts = locomigo.getExtractedTexts();
const translations = locomigo.getTranslations();
console.log("Extracted texts:", extractedTexts);
console.log("Translation matrix:", translations);Features
Auto Text Extraction
When you call locomigo.initialize(), the SDK automatically:
- Scans the DOM for text content in common elements (
p,h1-h6,span,button,a,label,li) - Extracts and deduplicates all translatable text
- Creates a translation matrix with the current locale
- Excludes non-translatable content (numbers, symbols, very short text)
Available Methods
locomigo.initialize(options)- Initialize SDK and auto-extract DOM textlocomigo.getExtractedTexts()- Returns array of all extracted text stringslocomigo.getTranslations()- Returns translation matrix (keys = text, values = locale translations)
Options
locale(string, default: 'en-US') - The default localesupportedLocales(string[], default: []) - Array of supported locales (will be synced from platform in future)realtime(boolean, default: true) - Enable realtime updates (will be implemented in future)
TypeScript Support
This package includes TypeScript definitions.
import locomigo, { LocomigOptions } from "react-locomigo";
const options: LocomigOptions = {
locale: "en-US",
supportedLocales: ["en-US", "es-ES"],
realtime: true,
};
locomigo.initialize(options);