Skip to content

Commit 88c9034

Browse files
authored
[battery_manager]Translate Battery Manager Module (#10149)
This is responsible for translating the module battery_manager to different languages. Currently only 'Hindi' language is supported but other languages can be added as required.
1 parent 6dcc7c3 commit 88c9034

File tree

8 files changed

+687
-249
lines changed

8 files changed

+687
-249
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ locales:
8585
msgfmt -o modules/acknowledgements/locale/ja/LC_MESSAGES/acknowledgements.mo modules/acknowledgements/locale/ja/LC_MESSAGES/acknowledgements.po
8686
msgfmt -o modules/api_docs/locale/ja/LC_MESSAGES/api_docs.mo modules/api_docs/locale/ja/LC_MESSAGES/api_docs.po
8787
msgfmt -o modules/battery_manager/locale/ja/LC_MESSAGES/battery_manager.mo modules/battery_manager/locale/ja/LC_MESSAGES/battery_manager.po
88+
msgfmt -o modules/battery_manager/locale/hi/LC_MESSAGES/battery_manager.mo modules/battery_manager/locale/hi/LC_MESSAGES/battery_manager.po
89+
npx i18next-conv -l hi -s modules/battery_manager/locale/hi/LC_MESSAGES/battery_manager.po -t modules/battery_manager/locale/hi/LC_MESSAGES/battery_manager.json --compatibilityJSON v4
8890
msgfmt -o modules/behavioural_qc/locale/ja/LC_MESSAGES/behavioural_qc.mo modules/behavioural_qc/locale/ja/LC_MESSAGES/behavioural_qc.po
8991
msgfmt -o modules/behavioural_qc/locale/hi/LC_MESSAGES/behavioural_qc.mo modules/behavioural_qc/locale/hi/LC_MESSAGES/behavioural_qc.po
9092
npx i18next-conv -l hi -s modules/behavioural_qc/locale/hi/LC_MESSAGES/behavioural_qc.po -t modules/behavioural_qc/locale/hi/LC_MESSAGES/behavioural_qc.json

jsx/Modal.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ButtonElement,
66
FormElement,
77
} from 'jsx/Form';
8+
import {useTranslation} from 'react-i18next';
89

910
export type ModalProps = PropsWithChildren<{
1011
throwWarning?: boolean;
@@ -38,20 +39,22 @@ const Modal = ({
3839
}: ModalProps) => {
3940
const [loading, setLoading] = useState(false); // Tracks loading during submit
4041
const [success, setSuccess] = useState(false); // Tracks success after submit
42+
const {t} = useTranslation('loris'); // Initialize translation
4143

4244
/**
4345
* Handles modal close event. Shows a confirmation if `throwWarning` is true.
4446
*/
4547
const handleClose = () => {
4648
if (throwWarning) { // Display warning if enabled
4749
Swal.fire({
48-
title: 'Are You Sure?',
49-
text: 'Leaving the form will result in the loss of any information ' +
50-
'entered.',
50+
title: t('Are You Sure?'),
51+
text:
52+
t('Leaving the form will result in the'
53+
+' loss of any information entered.'),
5154
type: 'warning',
5255
showCancelButton: true,
53-
confirmButtonText: 'Proceed',
54-
cancelButtonText: 'Cancel',
56+
confirmButtonText: t('Proceed'),
57+
cancelButtonText: t('Cancel'),
5558
}).then((result) => result.value && onClose());
5659
} else {
5760
onClose(); // Close immediately if no warning
@@ -89,7 +92,7 @@ const Modal = ({
8992
*/
9093
const submitButton = () => {
9194
if (onSubmit && !(loading || success)) { // Show button if conditions met
92-
return <div style={submitStyle}><ButtonElement/></div>;
95+
return <div style={submitStyle}><ButtonElement label={t('Save')}/></div>;
9396
}
9497
};
9598

@@ -175,7 +178,7 @@ const Modal = ({
175178
const loader = loading && (
176179
<div style={processStyle}>
177180
<Loader size={20}/>
178-
<h5 className='animate-flicker'>Saving</h5>
181+
<h5 className='animate-flicker'>{t('Saving')}</h5>
179182
</div>
180183
);
181184

@@ -188,7 +191,7 @@ const Modal = ({
188191
style={{color: 'green', marginBottom: '2px'}}
189192
className='glyphicon glyphicon-ok-circle'
190193
/>
191-
<h5>Success!</h5>
194+
<h5>{t('Success!')}</h5>
192195
</div>
193196
);
194197

locale/hi/LC_MESSAGES/loris.po

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ msgstr "सहेजें"
141141
msgid "Reset"
142142
msgstr "रीसेट करें"
143143

144+
msgid "Note"
145+
msgstr "नोट"
146+
144147
msgid "Back"
145148
msgstr "वापस"
146149

@@ -500,3 +503,15 @@ msgstr "लोड हो रहा है..."
500503

501504
msgid "Permission denied"
502505
msgstr "अनुमति अस्वीकृत"
506+
507+
msgid "Are You Sure?"
508+
msgstr "क्या आप सुनिश्चित हैं?"
509+
510+
msgid "Leaving the form will result in the loss of any information entered."
511+
msgstr "फ़ॉर्म छोड़ने से दर्ज की गई सभी जानकारी खो जाएगी।"
512+
513+
msgid "Proceed"
514+
msgstr "आगे बढ़ें"
515+
516+
msgid "Saving"
517+
msgstr "सहेजा जा रहा है"

locale/loris.pot

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,15 @@ msgstr ""
297297
msgid "Ethnicity"
298298
msgstr ""
299299

300+
msgid "Are You Sure?"
301+
msgstr ""
302+
303+
msgid "Leaving the form will result in the loss of any information entered."
304+
msgstr ""
305+
306+
msgid "Proceed"
307+
msgstr ""
308+
300309
msgid "Previous"
301310
msgstr ""
302311

@@ -306,9 +315,15 @@ msgstr ""
306315
msgid "Save"
307316
msgstr ""
308317

318+
msgid "Saving"
319+
msgstr ""
320+
309321
msgid "Reset"
310322
msgstr ""
311323

324+
msgid "Note"
325+
msgstr ""
326+
312327
msgid "View details"
313328
msgstr ""
314329

modules/battery_manager/jsx/batteryManagerForm.js

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
SelectElement,
88
NumericElement,
99
} from 'jsx/Form';
10+
import {withTranslation} from 'react-i18next';
1011

1112
/**
1213
* Battery Manager Form
@@ -22,26 +23,42 @@ class BatteryManagerForm extends Component {
2223
* @return {*}
2324
*/
2425
render() {
25-
const {test, options, setTest, add, errors, handleSubmit} = this.props;
26+
const {test, options, setTest, add, errors, handleSubmit, t} = this.props;
2627

28+
// Inform users about duplicate entries
2729
const renderHelpText = () => {
2830
if (add) {
2931
return (
3032
<span>
31-
You cannot add an entry if it has a duplicate entry in the test
32-
battery.<br/>
33-
If the duplicate entry is inactive, you will be given the option
34-
to activate it.
33+
{t(
34+
'You cannot add an entry if it has a duplicate entry in the ' +
35+
'test battery.',
36+
{ns: 'battery_manager'}
37+
)}<br/>
38+
{t(
39+
'If the duplicate entry is inactive, you will be given the ' +
40+
'option to activate it.',
41+
{ns: 'battery_manager'}
42+
)}
3543
</span>
3644
);
3745
} else {
3846
return (
3947
<span>
40-
Editing an entry will alter the current entry.<br/>
41-
You cannot edit an entry to have the same values as another active
42-
entry.<br/>
43-
If the duplicate entry is inactive, you will be given the option
44-
to activate it.
48+
{t(
49+
'Editing an entry will alter the current entry.',
50+
{ns: 'battery_manager'}
51+
)}<br/>
52+
{t(
53+
'You cannot edit an entry to have the same values as another ' +
54+
'active entry.',
55+
{ns: 'battery_manager'}
56+
)}<br/>
57+
{t(
58+
'If the duplicate entry is inactive, you will be given the ' +
59+
'option to activate it.',
60+
{ns: 'battery_manager'}
61+
)}
4562
<br/>
4663
<br/>
4764
</span>
@@ -55,22 +72,22 @@ class BatteryManagerForm extends Component {
5572
onSubmit={handleSubmit}
5673
>
5774
<StaticElement
58-
label="Note"
75+
label={t('Note', {ns: 'loris'})}
5976
text={renderHelpText()}
6077
/>
6178
<SelectElement
6279
name="testName"
63-
label="Instrument"
64-
placeHolder="Search for instrument"
80+
label={t('Instrument', {ns: 'battery_manager'})}
81+
placeHolder={t('Search for instrument', {ns: 'battery_manager'})}
6582
options={options.instruments}
6683
onUserInput={setTest}
6784
required={true}
68-
value={test.testName ?? ''}
85+
value={test.testName}
6986
errorMessage={errors.testName}
7087
/>
7188
<NumericElement
7289
name="ageMinDays"
73-
label="Minimum age (days)"
90+
label={t('Minimum Age (days)', {ns: 'battery_manager'})}
7491
onUserInput={setTest}
7592
min={0}
7693
max={99999}
@@ -80,7 +97,7 @@ class BatteryManagerForm extends Component {
8097
/>
8198
<NumericElement
8299
name="ageMaxDays"
83-
label="Maximum age (days)"
100+
label={t('Maximum Age (days)', {ns: 'battery_manager'})}
84101
onUserInput={setTest}
85102
min={0}
86103
max={99999}
@@ -90,68 +107,74 @@ class BatteryManagerForm extends Component {
90107
/>
91108
<SelectElement
92109
name="stage"
93-
label="Stage"
110+
label={t('Stage', {ns: 'battery_manager'})}
94111
options={options.stages}
95112
onUserInput={setTest}
96113
required={true}
97-
value={test.stage ?? ''}
114+
value={test.stage}
98115
errorMessage={errors.stage}
99116
/>
100117
<SelectElement
101118
name="cohort"
102-
label="Cohort"
119+
label={t('Cohort', {ns: 'loris', count: 1})}
103120
options={options.cohorts}
104121
onUserInput={setTest}
105122
required={false}
106-
value={test.cohort ?? ''}
123+
value={test.cohort}
107124
/>
108125
<SelectElement
109126
name="visitLabel"
110-
label="Visit Label"
127+
label={t('Visit Label', {ns: 'loris'})}
111128
options={options.visits}
112129
onUserInput={setTest}
113130
required={false}
114-
value={test.visitLabel ?? ''}
131+
value={test.visitLabel}
115132
/>
116133
<SelectElement
117134
name="centerId"
118-
label="Site"
119-
placeHolder="Search for site"
135+
label={t('Site', {ns: 'loris', count: 1})}
136+
placeHolder={t('Search for site', {ns: 'battery_manager'})}
120137
options={options.sites}
121138
strictSearch={true}
122139
onUserInput={setTest}
123140
required={false}
124-
value={test.centerId ?? ''}
141+
value={test.centerId}
125142
/>
126143
<SelectElement
127144
name="firstVisit"
128-
label="First Visit"
129-
options={options.firstVisit}
145+
label={t('First Visit', {ns: 'battery_manager'})}
146+
options={{
147+
'Y': t('Yes', {ns: 'loris'}),
148+
'N': t('No', {ns: 'loris'}),
149+
}}
130150
onUserInput={setTest}
131151
required={false}
132-
value={test.firstVisit ?? ''}
152+
value={test.firstVisit}
133153
/>
134154
<NumericElement
135155
name="instrumentOrder"
136-
label="Instrument Order"
156+
label={t('Instrument Order', {ns: 'battery_manager'})}
137157
onUserInput={setTest}
138158
required={false}
139159
min={0}
140-
max={127}
141-
value={test.instrumentOrder != null ?
142-
String(test.instrumentOrder) : ''}
160+
max={127} // max value allowed by default column type of instr_order
161+
value={test.instrumentOrder}
143162
/>
144163
<SelectElement
145164
name="DoubleDataEntryEnabled"
146-
label="Enable Double Data Entry"
147-
options={options.DoubleDataEntryEnabled}
165+
label={t('Enable Double Data Entry', {ns: 'battery_manager'})}
166+
options={{
167+
'Y': t('Yes', {ns: 'loris'}),
168+
'N': t('No', {ns: 'loris'}),
169+
}}
148170
onUserInput={setTest}
149171
required={true}
150-
value={test.DoubleDataEntryEnabled ?? ''}
172+
value={test.DoubleDataEntryEnabled}
173+
errorMessage={errors.DoubleDataEntryEnabled}
151174
emptyOption={false}
152175
/>
153176
<ButtonElement
154-
label="Submit"
177+
label={t('Submit', {ns: 'battery_manager'})}
155178
/>
156179
</FormElement>
157180
);
@@ -165,7 +188,8 @@ BatteryManagerForm.propTypes = {
165188
add: PropTypes.bool,
166189
errors: PropTypes.object,
167190
handleSubmit: PropTypes.func.isRequired,
191+
t: PropTypes.func,
168192
};
169193

170-
export default BatteryManagerForm;
171-
194+
export default withTranslation(
195+
['battery_manager', 'loris'])(BatteryManagerForm);

0 commit comments

Comments
 (0)