Skip to content

Commit 9793026

Browse files
authored
Improve translation plugin as done in gridstudy-app (#455)
Signed-off-by: sBouzols <[email protected]>
1 parent 1c2395c commit 9793026

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

src/components/app-wrapper.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ import messages_en from '../translations/en.json';
4848
import messages_fr from '../translations/fr.json';
4949
import network_modification_locale_en from '../translations/dynamic/network-modifications-locale-en';
5050
import network_modification_locale_fr from '../translations/dynamic/network-modifications-locale-fr';
51-
import messages_plugins_en from '../plugins/translations/en.json';
52-
import messages_plugins_fr from '../plugins/translations/fr.json';
51+
import messages_plugins from '../plugins/translations';
5352
import aggrid_locale_fr from '../translations/external/aggrid-locale-fr';
5453
import backend_locale_fr from '../translations/external/backend-locale-fr';
5554
import backend_locale_en from '../translations/external/backend-locale-en';
@@ -199,7 +198,7 @@ const messages = {
199198
...element_search_en,
200199
...filter_en,
201200
...filter_expert_en,
202-
...messages_plugins_en, // keep it at the end to allow translation overwritting
201+
...messages_plugins.en, // keep it at the end to allow translation overwritting
203202
},
204203
fr: {
205204
...messages_fr,
@@ -219,7 +218,7 @@ const messages = {
219218
...directory_items_input_fr,
220219
...filter_fr,
221220
...filter_expert_fr,
222-
...messages_plugins_fr, // keep it at the end to allow translation overwritting
221+
...messages_plugins.fr, // keep it at the end to allow translation overwritting
223222
},
224223
};
225224

src/plugins/README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,31 @@ const MyPluggableComponent = () => {
4545

4646
# How to overwrite translations
4747

48-
Add your private translations to the following files to complete or overwrite existing translations
48+
Add your private translations to the following directory to complete or overwrite existing translations
4949

50-
* src/plugins/translations/en.json
51-
* src/plugins/translations/fr.json
50+
* src/plugins/translations
51+
52+
import your file and export an object messages_plugins for the translation in french or english
53+
in src/plugins/translations/index.js
54+
55+
```diff
56+
import messages_plugins_fr from '../translations/fr.json';
57+
+import my_plugins_fr from '../translations/my_plugins_fr.json';
58+
59+
import messages_plugins_en from '../translations/en.json';
60+
+import my_plugins_en from '../translations/my_plugins_en.json';
61+
62+
const messages_plugins = {
63+
fr: {
64+
...messages_plugins_fr,
65+
+ ...my_plugins_fr,
66+
},
67+
en: {
68+
...messages_plugins_en,
69+
+ ...my_plugins_en,
70+
},
71+
};
72+
73+
export default messages_plugins;
74+
75+
```

src/plugins/translations/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2024, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
import messages_plugins_fr from '../translations/fr.json';
9+
import messages_plugins_en from '../translations/en.json';
10+
const messages_plugins = {
11+
fr: {
12+
...messages_plugins_fr,
13+
},
14+
en: {
15+
...messages_plugins_en,
16+
},
17+
};
18+
19+
export default messages_plugins;

0 commit comments

Comments
 (0)