Skip to content

Commit

Permalink
Merge pull request #6 from FlowSquad/fix/selection_bug
Browse files Browse the repository at this point in the history
Fix #5: Plugin not working in Camunda Modeler v.4.8+
  • Loading branch information
flowsquad-bot authored May 27, 2021
2 parents 9d35f79 + 063c037 commit 9ea570d
Show file tree
Hide file tree
Showing 32 changed files with 43,346 additions and 5,374 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ To use this plugin in your installation, follow these simple steps:
2. Download the latest release artifact
3. Extract it and put it inside the "resources/plugins" directory relative to your `{APP_DATA_DIRECTORY}` or `{USER_DATA_DIRECTORY}`.
4. Restart the modeler
5. Click Plugins > Choose Language and select the language of your choice
5. Click on the language dropdown in the toolbar and select the language of your choice

## Development

Expand Down Expand Up @@ -80,16 +80,13 @@ If you want to add a new language, follow these steps, after you set up your loc
// ...
```
5. Open the "menu/menu.js" file and add a new entry to it:
5. Open the "config/I18NPlugin.js" file and add a new entry to the language options:
```javascript
// ...
{
label: 'Français',
enabled: () => menuState.bpmn,
action: function () {
electronApp.emit('menu:action', 'language.changed', 'fr');
}
}
const options = [
// ...
{value: 'fr', label: 'Français'}
]
// ...
```
6. Create a pull request to this repository and help us with adding new languages and improving the existing ones! :)
Expand All @@ -98,7 +95,7 @@ If you want to add a new language, follow these steps, after you set up your loc

```
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@ import translate from './translate';
* Creates the plugin structure and tells the modeler, how to initialize it.
*/
export default {
__init__: [ 'translate' ],
translate: [ 'type', translate ]
translateModule: translate,
__init__: ['translate'],
translate: ['type', translate]
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,4 +27,4 @@ export default {
...dmnJs,
...propertiesPanel,
...other
};
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -77,4 +77,4 @@ export default {
'unsupported bpmnElement for {plane}: {rootElement}': 'Nicht unterstütztes bpmnElement für {plane}: {rootElement}',
'unrecognized flowElement {element} in context {context}': 'FlowElement {element} im Context {context} nicht erkannt',
'HELLO {you}!': 'HALLO {you}!'
};
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,4 +78,4 @@ export default {
'Set Value': 'Wert setzen',
'Strings must be in double quotes.': 'Strings müssen von doppelten Anführungszeichen umschlossen werden',
'Type': 'Typ',
};
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -93,4 +93,4 @@ export default {
'Annotation': 'Annotation',
'Output Expression': 'Output-Expression',
'Data Type': 'Datentyp'
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -199,4 +199,4 @@ export default {
'Wait for Completion': 'Auf Abschluss warten',
'[unknown template: {templateId}]': '[Unbekanntes Template: {templateId}]',
'{label} must not contain whitespace': '{label} darf keine Leerzeichen enthalten'
};
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,4 +27,4 @@ export default {
...dmnJs,
...propertiesPanel,
...other
};
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -77,4 +77,4 @@ export default {
'unsupported bpmnElement for {plane}: {rootElement}': 'unsupported bpmnElement for {plane}: {rootElement}',
'unrecognized flowElement {element} in context {context}': 'unrecognized flowElement {element} in context {context}',
'HELLO {you}!': 'HALLO {you}!'
};
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -78,4 +78,4 @@ export default {
'Set Value': 'Set Value',
'Strings must be in double quotes.': 'Strings must be in double quotes.',
'Type': 'Type',
};
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -93,4 +93,4 @@ export default {
'Annotation': 'Annotation',
'Output Expression': 'Output Expression',
'Data Type': 'Data Type'
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -199,4 +199,4 @@ export default {
'Wait for Completion': 'Wait for Completion',
'[unknown template: {templateId}]': '[unknown template: {templateId}]',
'{label} must not contain whitespace': '{label} darf keine Leerzeichen enthalten'
};
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,8 +23,8 @@ import other from './pt-br/other';
* Joins and exports the translated strings.
*/
export default {
...bpmnJs,
...dmnJs,
...propertiesPanel,
...other
...bpmnJs,
...dmnJs,
...propertiesPanel,
...other
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020 FlowSquad GmbH
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,6 @@
* limitations under the License.
*/

import {config} from '../configuration';
import de from "./languages/de.js";
import en from "./languages/en.js";
import pt_br from "./languages/pt-br.js";
Expand All @@ -29,68 +28,28 @@ const languages = {
// The default language to use if none is specified in the configuration
const defaultLanguage = "en";

// The key in the configuration that specifies the language
const CONFIG_KEY = "editor_language";

// The events to listen to / send
const I18N_EVENT = "i18n.changed";
const MENU_EVENT = "language.changed";
const INIT_ACTION = "editorActions.init";
const SELECTION_EVENT = "selection.changed";

// Contains all missing translations discovered to prevent logging them
// multiple times.
const missing = [];

console.log("Please help us translate by creating a pull request!");

/**
* This function initializes the translation plugin.
*
* @param eventBus The application's event bus
* @return The translator function
*/
export default function Translator(eventBus) {
let currentLanguage = languages[defaultLanguage];

// Read the language from configuration
config.get(CONFIG_KEY).then((language) => {

// Check if the specified language exists
if (languages[language] && language !== defaultLanguage) {

// Set the language as current
currentLanguage = languages[language];

// Notify parts of the application that the language has changed. Triggers a re-rendering.
eventBus.fire(I18N_EVENT);
eventBus.fire(SELECTION_EVENT, {newSelection: []});
}
});

// After the editor has initialized, register the menu listeners
eventBus.on(INIT_ACTION, function (event) {
const editorActions = event.editorActions;
editorActions.register(MENU_EVENT, function (language) {

// Persist the new language
config.set(CONFIG_KEY, language);

// Set the language as above
currentLanguage = languages[language];
eventBus.fire(I18N_EVENT);
eventBus.fire(SELECTION_EVENT, {newSelection: []});
});
});
export default function Translator() {
let currentLanguage = languages[this.currentLanguage()];

// Return the translation function. It takes the template string and the parameters,
// translates it and returns it.
return (template, parameters) => {

// If the requested string is not available in the current language
if (!currentLanguage[template]) {
// Check if it was already printed to the console
if (missing.indexOf(template) === -1) {
// Print the missing translation to the console ´
console.log("Missing translation: " + template, parameters);
console.log(`Missing translation: ${template}`);
missing.push(template);
}
}
Expand All @@ -100,10 +59,14 @@ export default function Translator(eventBus) {

// Replace all parameters in the template string with the provided values
return translation.replace(/{([^}]+)}/g, function (_, key) {
return (parameters || {})[key] || '{' + key + '}';
return (parameters || {})[key] || '{' + key + '}'
});
};
};

Translator.prototype.currentLanguage = function () {
return defaultLanguage;
}

// Specify what values should be injected into the function above
Translator.$inject = ['eventBus'];
Translator.$inject = [];
43 changes: 43 additions & 0 deletions client/config/ConfigModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2021 FlowSquad GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import React from 'camunda-modeler-plugin-helpers/react';
import {Modal} from 'camunda-modeler-plugin-helpers/components';

const Title = Modal.Title || (({children}) => <h2>{children}</h2>);
const Body = Modal.Body || (({children}) => <div>{children}</div>);
const Footer = Modal.Footer || (({children}) => <div>{children}</div>);


export default function ConfigModal({onClose}) {

return (<Modal onClose={onClose}>
<Title>
Language changed
</Title>
<Body>
<p>
Restart the modeler to apply the configuration.
</p>
</Body>
<Footer>
<div id="languageChangeButton">
<button type="button" class="btn btn-primary" onClick={() => onClose()}>Ok</button>
</div>
</Footer>
</Modal>);
}

Loading

0 comments on commit 9ea570d

Please sign in to comment.