@procore/ai-translations
v0.6.1
Published
Library that provides a solution to use AI to translate text into a language
Maintainers
Keywords
Readme
@procore/ai-translations
React package for AI-powered UI string translation in frontend apps. It provides:
AITranslationProviderto initialize translation contextAITranslateTextto render translated textuseAITranslationfor direct access to translation and progress state
Need deeper implementation details? See the internal guide: README.internal.md.
This package supports two runtime strategies:
frontend_translations: browser-based translation (Chrome-family AI APIs)backend_translations: server-side translation API
For Procore-specific operational details, see README.internal.md.
Installation
yarn add @procore/ai-translationsPeer dependencies:
react>= 16 < 19react-dom>= 16 < 19@procore/web-sdk-mfe-utils> 1.0.0 < 2
Quick Start
import React from 'react';
import {
AITranslationProvider,
AITranslateText,
} from '@procore/ai-translations';
export function AppRoot() {
return (
<AITranslationProvider
tool="timecard"
companyId={1}
projectId={10}
userId={42}
locale="es"
enableAIT={true}
companyLocale="de-DE"
projectLocale="fr-CA"
>
<AITranslateText text="Hello world" shouldTranslate={true} />
</AITranslationProvider>
);
}Public API
AITranslationProvider
Required props:
locale: string- target locale (BCP-47, for examplees,fr,de)tool: string- tool/MFE identifier used to scope translation eventscompanyId: numberprojectId: numberuserId: number
Optional props:
enableAIT?: boolean(defaulttrue) - whenfalse, returns source text without translationcompanyLocale?: string- company-level locale from environment metadata (e.g."de-DE"); passed through to context for downstream consumers such as AmplitudeprojectLocale?: string- project-level locale from environment metadata (e.g."fr-CA"); passed through to context for downstream consumers such as Amplitude
AITranslateText
Props:
text: stringshouldTranslate: booleanshowHighlight?: boolean(defaultfalse)translatedIconProps?: TranslatedIconProps
useAITranslation()
Returns:
ait(text: string): Promise<string>- translates text or returns cached valuelocale: stringcompanyLocale: string | undefined- company-level locale from environment metadataprojectLocale: string | undefined- project-level locale from environment metadatatool: stringtranslationProgress: { progress: number; current: number; total: number } | nullmodelDownloadProgress: ModelDownloadProgress | nullrenderVersion: number | undefined
Feature flag helpers
AI_TRANSLATION_FEATURE_FLAG_KEYgetAITranslationLDId(domain: string)
How It Works
flowchart LR
consumerApp[ConsumerApp] --> provider[AITranslationProvider]
provider --> aitCall["ait(text)"]
aitCall --> registryCheck[TranslationRegistryCheck]
registryCheck --> returnCached[ReturnCachedText]
registryCheck --> queueText[QueueText]
queueText --> manager[TranslationManager]
manager --> strategy[TranslatorStrategy]
strategy --> frontendClient[ChromeFrontendClient]
strategy --> backendClient[BackendApiClient]
frontendClient --> persist[PersistToIndexedDB]
backendClient --> persist
persist --> publish[PublishTranslationEvents]
publish --> rerender[AITranslateTextRerender]
rerender --> translatedUi[DisplayTranslatedText]At runtime, strings are registered through ait(), processed in batches, cached in memory and IndexedDB, and then rerendered via package events.
Configuration
The provider uses useConfig (React Query) to fetch translation config and refetch every 30 minutes.
Expected remote config shape:
type ToolConfig = {
strategy: 'frontend_translations' | 'backend_translations';
supportedLocales: string[];
translationBatchSize: number;
renderingBatchSize: number;
apiTimeout: number;
apiVersion: string;
};Operational Notes
AITranslateTextanduseAITranslationmust be used insideAITranslationProvider.- Frontend strategy depends on Chrome-family AI support; behavior differs by browser support.
- Backend/config endpoints are resolved from
window.location.originunder/rest/. - Translation cache uses IndexedDB; some restricted browser environments may limit persistence.
Development
From packages/ai-translations:
yarn build
yarn test
yarn lint
yarn storybook
yarn cypress:run