Skip to content

Commit ea5f7ad

Browse files
authored
[module_manager] Translate Module Manager Module (#10138)
This PR is responsible for translating the module module_manager to different languages. Currently only 'Hindi' language is supported, but other languages can be added as required.
1 parent bfd0d7c commit ea5f7ad

File tree

4 files changed

+128
-31
lines changed

4 files changed

+128
-31
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ locales:
153153
msgfmt -o modules/login/locale/ja/LC_MESSAGES/login.mo modules/login/locale/ja/LC_MESSAGES/login.po
154154
msgfmt -o modules/media/locale/ja/LC_MESSAGES/media.mo modules/media/locale/ja/LC_MESSAGES/media.po
155155
msgfmt -o modules/module_manager/locale/ja/LC_MESSAGES/module_manager.mo modules/module_manager/locale/ja/LC_MESSAGES/module_manager.po
156+
msgfmt -o modules/module_manager/locale/hi/LC_MESSAGES/module_manager.mo modules/module_manager/locale/hi/LC_MESSAGES/module_manager.po
157+
npx i18next-conv -l hi -s modules/module_manager/locale/hi/LC_MESSAGES/module_manager.po -t modules/module_manager/locale/hi/LC_MESSAGES/module_manager.json
156158
msgfmt -o modules/mri_violations/locale/ja/LC_MESSAGES/mri_violations.mo modules/mri_violations/locale/ja/LC_MESSAGES/mri_violations.po
157159
msgfmt -o modules/my_preferences/locale/hi/LC_MESSAGES/my_preferences.mo modules/my_preferences/locale/hi/LC_MESSAGES/my_preferences.po
158160
npx i18next-conv -l ja -s modules/my_preferences/locale/ja/LC_MESSAGES/my_preferences.po -t modules/my_preferences/locale/ja/LC_MESSAGES/my_preferences.json --compatibilityJSON v4
@@ -198,7 +200,7 @@ dataquery: modules/dataquery/locale/ja/LC_MESSAGES/dataquery.mo
198200
login: modules/login/locale/ja/LC_MESSAGES/login.mo
199201
target=login npm run compile
200202

201-
module_manager: modules/module_manager/locale/ja/LC_MESSAGES/module_manager.mo
203+
module_manager: modules/module_manager/locale/ja/LC_MESSAGES/module_manager.mo modules/module_manager/locale/hi/LC_MESSAGES/module_manager.mo
202204
target=module_manager npm run compile
203205

204206
mri_violations: modules/mri_violations/locale/ja/LC_MESSAGES/mri_violations.mo

modules/module_manager/jsx/modulemanager.js

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import Loader from 'Loader';
55
import FilterableDataTable from 'FilterableDataTable';
66
import swal from 'sweetalert2';
77
import {SelectElement} from 'jsx/Form';
8+
import {withTranslation} from 'react-i18next';
9+
import i18n from 'I18nSetup';
10+
import hiStrings from '../locale/hi/LC_MESSAGES/module_manager.json';
811

912
/**
1013
* Module Manager React Component
@@ -63,18 +66,13 @@ class ModuleManagerIndex extends Component {
6366
* @return {string} a mapped value for the table cell at a given column
6467
*/
6568
mapColumn(column, cell) {
66-
switch (column) {
67-
case 'Active':
68-
if (cell === 'Y') {
69-
return 'Yes';
70-
} else if (cell === 'N') {
71-
return 'No';
72-
}
73-
// This shouldn't happen, it's a non-nullable
74-
// enum in the backend.
75-
return '?';
76-
default: return cell;
69+
const {t} = this.props;
70+
if (cell === 'Y') {
71+
return t('Yes', {ns: 'loris'});
72+
} else if (cell === 'N') {
73+
return t('No', {ns: 'loris'});
7774
}
75+
return cell;
7876
}
7977

8078
/**
@@ -85,6 +83,7 @@ class ModuleManagerIndex extends Component {
8583
* @param {number} id
8684
*/
8785
toggleActive(name, value, id) {
86+
const {t} = this.props;
8887
fetch(
8988
this.props.BaseURL + '/module_manager/modules/' + name,
9089
{
@@ -98,18 +97,24 @@ class ModuleManagerIndex extends Component {
9897
}
9998
).then((response) => {
10099
if (response.status != 205) {
101-
swal.fire('Error!', 'Could not update ' + name + '.', 'error');
100+
swal.fire(
101+
t('Error!', {ns: 'loris'}),
102+
t('Could not update', {ns: 'module_manager'}) + ' ' + name + '.',
103+
'error'
104+
);
102105
} else {
103106
const success = this.setModuleDisplayStatus(name, value);
104107
if (success === true) {
105108
swal.fire({
106-
title: 'Success!',
107-
text: 'Updated ' + name + ' status! ' +
108-
'To apply changes the interface must be reloaded. Proceed?',
109+
title: t('Success!', {ns: 'loris'}),
110+
text: t('Updated', {ns: 'loris'}) + ' ' + name + ' ' +
111+
t('status!', {ns: 'module_manager'}) + ' ' +
112+
t('To apply changes the interface must be reloaded. Proceed?',
113+
{ns: 'module_manager'}),
109114
type: 'success',
110115
showCancelButton: true,
111-
confirmButtonText: 'Reload the page',
112-
cancelButtonText: 'Continue',
116+
confirmButtonText: t('Reload the page', {ns: 'module_manager'}),
117+
cancelButtonText: t('Continue', {ns: 'module_manager'}),
113118
}).then((status) => {
114119
if (status.value) {
115120
window.location.href = this.props.BaseURL
@@ -120,8 +125,8 @@ class ModuleManagerIndex extends Component {
120125
// If we get here something went very wrong, because somehow
121126
// a module was toggled that isn't in the table.
122127
swal.fire(
123-
'Error!',
124-
'Could not find module ' + id + '.',
128+
t('Error!', {ns: 'loris'}),
129+
t('Could not find module', {ns: 'module_manager'}) + ' ' + id + '.',
125130
'error'
126131
);
127132
}
@@ -160,13 +165,22 @@ class ModuleManagerIndex extends Component {
160165
* @return {*} a formated table cell for a given column
161166
*/
162167
formatColumn(column, cell, row) {
163-
if (column == 'Active' && this.props.hasEditPermission) {
168+
const {t} = this.props;
169+
const labelActive = t('Active', {ns: 'loris'});
170+
const labelName = t('Name', {ns: 'module_manager'});
171+
if ((column === 'Active' || column === labelActive) &&
172+
this.props.hasEditPermission) {
173+
const moduleName = row[labelName] || row['Name'];
164174
return <td><SelectElement
165-
name={row.Name}
166-
id={row.Name}
175+
name={moduleName}
176+
id={moduleName}
167177
label=''
168178
emptyOption={false}
169-
options={{'Y': 'Yes', 'N': 'No'}}
179+
sortByValue={false}
180+
options={{
181+
'Y': t('Yes', {ns: 'loris'}),
182+
'N': t('No', {ns: 'loris'}),
183+
}}
170184
value={cell}
171185
onUserInput={this.toggleActive}
172186
noMargins={true}
@@ -185,29 +199,33 @@ class ModuleManagerIndex extends Component {
185199
// If error occurs, return a message.
186200
// XXX: Replace this with a UI component for 500 errors.
187201
if (this.state.error) {
188-
return <h3>An error occured while loading the page.</h3>;
202+
const {t} = this.props;
203+
return (
204+
<h3>{t('An error occured while loading the page.', {ns: 'loris'})}</h3>
205+
);
189206
}
190207

191208
// Waiting for async data to load
192209
if (!this.state.isLoaded) {
193210
return <Loader/>;
194211
}
195212

213+
const {t} = this.props;
196214
const fields = [
197-
{label: 'Name', show: true, filter: {
215+
{label: t('Name', {ns: 'module_manager'}), show: true, filter: {
198216
name: 'Name',
199217
type: 'text',
200218
}},
201-
{label: 'Full Name', show: true, filter: {
219+
{label: t('Full Name', {ns: 'module_manager'}), show: true, filter: {
202220
name: 'Full Name',
203221
type: 'text',
204222
}},
205-
{label: 'Active', show: true, filter: {
223+
{label: t('Active', {ns: 'loris'}), show: true, filter: {
206224
name: 'Active',
207225
type: 'select',
208226
options: {
209-
'Y': 'Yes',
210-
'N': 'No',
227+
'Y': t('Yes', {ns: 'loris'}),
228+
'N': t('No', {ns: 'loris'}),
211229
},
212230
}},
213231
];
@@ -226,13 +244,19 @@ ModuleManagerIndex.propTypes = {
226244
dataURL: PropTypes.string.isRequired,
227245
BaseURL: PropTypes.string,
228246
hasEditPermission: PropTypes.bool,
247+
t: PropTypes.func,
229248
};
230249

250+
const TranslatedModuleManagerIndex = withTranslation(
251+
['module_manager', 'loris']
252+
)(ModuleManagerIndex);
253+
231254
window.addEventListener('load', () => {
255+
i18n.addResourceBundle('hi', 'module_manager', hiStrings);
232256
createRoot(
233257
document.getElementById('lorisworkspace')
234258
).render(
235-
<ModuleManagerIndex
259+
<TranslatedModuleManagerIndex
236260
dataURL={`${loris.BaseURL}/module_manager/?format=json`}
237261
BaseURL={loris.BaseURL}
238262
hasEditPermission={loris.userHasPermission('module_manager_edit')}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Default LORIS strings to be translated (English).
2+
# Copy this to a language specific file and add translations to the
3+
# new file.
4+
# Copyright (C) 2025
5+
# This file is distributed under the same license as the LORIS package.
6+
# Dave MacFarlane <[email protected]>, 2025.
7+
#
8+
msgid ""
9+
msgstr ""
10+
"Project-Id-Version: LORIS 27\n"
11+
"Report-Msgid-Bugs-To: https://github.com/aces/Loris/issues\n"
12+
"POT-Creation-Date: 2025-04-08 14:37-0400\n"
13+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
15+
"Language-Team: LANGUAGE <[email protected]>\n"
16+
"Language: hi\n"
17+
"MIME-Version: 1.0\n"
18+
"Content-Type: text/plain; charset=UTF-8\n"
19+
"Content-Transfer-Encoding: 8bit\n"
20+
21+
msgid "Module Manager"
22+
msgstr "मॉड्यूल प्रबंधक"
23+
24+
msgid "Name"
25+
msgstr "नाम"
26+
27+
msgid "Full Name"
28+
msgstr "पूरा नाम"
29+
30+
msgid "Could not update"
31+
msgstr "अपडेट नहीं कर सका"
32+
33+
msgid "status!"
34+
msgstr "स्थिति!"
35+
36+
msgid "To apply changes the interface must be reloaded. Proceed?"
37+
msgstr "परिवर्तन लागू करने के लिए इंटरफ़ेस को पुनः लोड करना होगा। आगे बढ़ें?"
38+
39+
msgid "Reload the page"
40+
msgstr "पृष्ठ पुनः लोड करें"
41+
42+
msgid "Continue"
43+
msgstr "जारी रखें"
44+
45+
msgid "Could not find module"
46+
msgstr "मॉड्यूल नहीं मिला"
47+

modules/module_manager/locale/module_manager.pot

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,27 @@ msgstr ""
2121
msgid "Module Manager"
2222
msgstr ""
2323

24+
msgid "Name"
25+
msgstr ""
26+
27+
msgid "Full Name"
28+
msgstr ""
29+
30+
msgid "Could not update"
31+
msgstr ""
32+
33+
msgid "status!"
34+
msgstr ""
35+
36+
msgid "To apply changes the interface must be reloaded. Proceed?"
37+
msgstr ""
38+
39+
msgid "Reload the page"
40+
msgstr ""
41+
42+
msgid "Continue"
43+
msgstr ""
44+
45+
msgid "Could not find module"
46+
msgstr ""
47+

0 commit comments

Comments
 (0)