Skip to content

Context, Theme, and Events

The SDK tells your app where it is rendered (context), keeps it in the host’s theme, and notifies it about what happens around it (events):

import {
AppUiProvider,
useCrowdinContext,
useCrowdinEvent,
} from "@crowdin/serverless-apps-sdk/react";
function App() {
return (
<AppUiProvider>
<Panel />
</AppUiProvider>
);
}
function Panel() {
const context = useCrowdinContext();
useCrowdinEvent("language.change", () => {
// refresh whatever depends on the selected language
});
return <p>Project: {context.project?.id}</p>;
}

useCrowdinContext() (and getContext() in the core) return a CrowdinContext:

FieldTypeDescription
app{ id, type, key }The app id, the module type being rendered, and its manifest key
user{ locale, timezone }The current Crowdin user’s locale and timezone (either can be null)
project{ id } or nullThe current project, when the module renders in a project context
organization{ id } or nullThe current organization, when there is one
isEnterprisebooleanWhether the host is Crowdin Enterprise
parentOriginstring or nullOrigin of the hosting Crowdin page
assetsBaseUrlstring or nullBase URL the app’s bundle assets are served from

useCrowdinEvent(name, handler) is fully typed - the payload type follows the event name. The core events.on(name, handler) accepts the same events with an untyped payload; cast it with the exported payload types (e.g. TranslationObject). These are the host events of the Crowdin Apps platform; the payloads are described in the supported events reference.

The table lists the events typed in this SDK version. The platform can start emitting new events at any time, and they work on any SDK version right away - both events.on and useCrowdinEvent accept any event name string.

EventFires when
string.changeThe active source string changes
string.selectedThe string selection changes (multiple selection)
textarea.editedThe translation textarea content is edited
translation.addedA translation is suggested
translation.deletedA translation is deleted
translation.restoredA translation is restored
translation.voteA translation is voted on
translation.approveA translation is approved
translation.disapproveA translation approval is revoked
language.changeThe target language changes
file.changeThe active file changes
asset.source.previewThe asset source preview is shown
asset.suggestion.previewAn asset suggestion preview is shown
theme.changedThe host switches between light and dark theme
intersection.changedA registered intersection observer reports a change
context.menu.clickThe user activates one of the app’s context-menu entries

AppUiProvider syncs the host theme: it toggles dark mode and applies Crowdin’s CSS variables, so the /ui components automatically match the Crowdin look.

Inside AppUiProvider, the useTheme() hook returns the current theme ({ mode: "light" | "dark" }) and re-renders when the host switches theme - use it for custom rendering that the CSS variables don’t cover.

The framework-free core offers the same capabilities without React: getContext(), getTheme(), onThemeChange(), events.on(), plus the typed host actions such as editor, project, profile, and modal.

import { getContext, events } from "@crowdin/serverless-apps-sdk";
const context = getContext();
events.on("language.change", () => {
// refresh whatever depends on the selected language
});