Skip to content

Editor Button

The module adds a button to the Crowdin Editor. Crowdin renders the button itself; a click opens one of the app’s editorRightPanel or modal modules, or sends an editor.button.click event to a right panel.

index.js
import crowdinModule from '@crowdin/app-project-module';
const configuration = {
baseUrl: 'https://123.ngrok.io',
clientId: 'clientId',
clientSecret: 'clientSecret',
name: 'Sample App',
identifier: 'sample-app',
description: 'Sample App description',
dbFolder: import.meta.dirname,
imagePath: import.meta.dirname + '/logo.png',
editorRightPanel: [{
modes: ['translate', 'review'],
supportsMultipleStrings: true,
uiPath: import.meta.dirname + '/public'
}],
editorButton: [
{
key: 'open-panel',
name: 'Open Sample App',
location: 'header-right',
type: 'panel',
modes: ['translate', 'review']
},
{
key: 'check-strings',
name: 'Check selected strings',
location: 'strings-menu',
type: 'event',
modes: ['translate', 'review']
}
]
};
crowdinModule.createApp(configuration);
OptionRequiredDescription
locationyesWhere the button appears: header-right or header-left (the Editor header), menu (the Editor’s Apps menu), translation-toolbar, or strings-menu (the strings context menu)
typeyesWhat a click does: panel opens an editorRightPanel module, modal opens a modal module, event sends editor.button.click to an editorRightPanel module. event is available at translation-toolbar and strings-menu only
modesyesThe Editor modes the button is shown in
moduleKeynoKey of the target module. Leave it out when the app declares a single module of the target type
namenoButton label and tooltip. Defaults to the app name
weightnoNon-negative integer that orders the buttons at one location; lower weights come first (default 100)
imagePath / imageUrlnoButton icon. Defaults to the app logo
environmentsnocrowdin, crowdin-enterprise, or both
keynoButton key. It must differ from the keys of the app’s right panels and modals

createApp throws at startup when a button’s target can’t be resolved: moduleKey names no module of the target type, the app declares no such module, or it declares several and moduleKey is missing. The Editor hides a button wherever its target is unavailable, for example in a mode the target panel’s modes leave out.

A button of the event type doesn’t open anything. Its target panel receives the click through the Crowdin Apps JS events:

AP.events.on('editor.button.click', (click) => {
if (click.location === 'strings-menu') {
console.log(click.key, click.stringIds, click.languageIds);
} else {
console.log(click.key, click.stringId, click.pluralId, click.languageIds);
}
});

A translation-toolbar button sends the string being translated (stringId, pluralId), a strings-menu button sends the selected strings (stringIds). Both carry languageIds, which is empty when no target language applies. Set supportsMultipleStrings: true on a panel that receives strings-menu clicks - without it, the Editor covers the panel while several strings are selected.