Skip to content

Commit ab518d2

Browse files
authored
Merge pull request #1192 from openmsupply/1164-tetum-language
Tetum language support part II
2 parents 2e954f8 + 8f6e24a commit ab518d2

File tree

11 files changed

+106
-12
lines changed

11 files changed

+106
-12
lines changed

client/packages/common/src/intl/locales/en/app.json

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"searching": "Searching...",
8181
"select-report": "Select Template",
8282
"select-store": "Select store",
83+
"select-language": "Select language",
8384
"stock": "View Stock",
8485
"stocktakes": "Stocktakes",
8586
"store-details": "Store code: {{code}}",

client/packages/common/src/intl/utils/IntlUtils.ts

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import { LanguageType } from '../../types/schema';
55

66
export { useTranslationNext };
77

8+
const languageOptions = [
9+
{ label: 'عربي', value: 'ar' },
10+
{ label: 'Français', value: 'fr' },
11+
{ label: 'English', value: 'en' },
12+
{ label: 'Española', value: 'es' },
13+
{ label: 'Tetum', value: 'tet' },
14+
];
15+
816
const locales = [
917
'ar' as const,
1018
'en' as const,
@@ -53,6 +61,9 @@ export const IntlUtils = {
5361
}
5462
return 'en';
5563
},
64+
languageOptions,
65+
getLanguageName: (language: string) =>
66+
languageOptions.find(option => option.value === language)?.label,
5667
};
5768

5869
const parseLanguage = (language?: LanguageType) => {
@@ -71,6 +82,8 @@ const parseLanguage = (language?: LanguageType) => {
7182
return 'ru';
7283
case LanguageType.Spanish:
7384
return 'es';
85+
case LanguageType.Tetum:
86+
return 'tet';
7487
default:
7588
return undefined;
7689
}

client/packages/common/src/types/schema.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,8 @@ export enum LanguageType {
14661466
Laos = 'LAOS',
14671467
Portuguese = 'PORTUGUESE',
14681468
Russian = 'RUSSIAN',
1469-
Spanish = 'SPANISH'
1469+
Spanish = 'SPANISH',
1470+
Tetum = 'TETUM'
14701471
}
14711472

14721473
export type LocationConnector = {

client/packages/host/src/components/Footer/Footer.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@ import React from 'react';
22
import {
33
Box,
44
HomeIcon,
5+
IntlUtils,
56
styled,
67
Tooltip,
8+
TranslateIcon,
79
Typography,
810
useAuthContext,
911
UserIcon,
1012
useTranslation,
1113
} from '@openmsupply-client/common';
1214
import { StoreSelector } from './StoreSelector';
15+
import { LanguageSelector } from './LanguageSelector';
1316

1417
export const Footer: React.FC = () => {
1518
const { user, store } = useAuthContext();
1619
const t = useTranslation('app');
20+
const i18n = IntlUtils.useI18N();
1721
const PaddedCell = styled(Box)({ display: 'flex' });
1822
const iconStyles = { color: 'gray.main', height: '16px', width: '16px' };
1923
const textStyles = {
@@ -38,6 +42,16 @@ export const Footer: React.FC = () => {
3842
<Typography sx={textStyles}>{user.name}</Typography>
3943
</PaddedCell>
4044
) : null}
45+
<LanguageSelector>
46+
<PaddedCell>
47+
<TranslateIcon sx={iconStyles} />
48+
<Tooltip title={t('select-language', { ...store })}>
49+
<Typography sx={textStyles}>
50+
{IntlUtils.getLanguageName(i18n.language)}
51+
</Typography>
52+
</Tooltip>
53+
</PaddedCell>
54+
</LanguageSelector>
4155
</Box>
4256
);
4357
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React, { FC } from 'react';
2+
import {
3+
Box,
4+
FlatButton,
5+
PaperPopoverSection,
6+
usePaperClickPopover,
7+
useTranslation,
8+
IntlUtils,
9+
useNavigate,
10+
} from '@openmsupply-client/common';
11+
12+
import { PropsWithChildrenOnly } from '@common/types';
13+
14+
export const LanguageSelector: FC<PropsWithChildrenOnly> = ({ children }) => {
15+
const navigate = useNavigate();
16+
const { hide, PaperClickPopover } = usePaperClickPopover();
17+
const t = useTranslation('app');
18+
19+
const i18n = IntlUtils.useI18N();
20+
21+
const languageButtons = IntlUtils.languageOptions.map(l => (
22+
<FlatButton
23+
label={l.label}
24+
disabled={l.value === i18n.language}
25+
onClick={() => {
26+
i18n.changeLanguage(l.value);
27+
hide();
28+
navigate(0);
29+
}}
30+
key={l.value}
31+
sx={{
32+
whiteSpace: 'nowrap',
33+
overflowX: 'hidden',
34+
overflowY: 'visible',
35+
textOverflow: 'ellipsis',
36+
display: 'block',
37+
textAlign: 'left',
38+
}}
39+
/>
40+
));
41+
return (
42+
<PaperClickPopover
43+
placement="top"
44+
width={300}
45+
Content={
46+
<PaperPopoverSection label={t('select-language')}>
47+
<Box
48+
style={{
49+
overflowY: 'auto',
50+
maxHeight: 300,
51+
}}
52+
>
53+
{languageButtons}
54+
</Box>
55+
</PaperPopoverSection>
56+
}
57+
>
58+
{children}
59+
</PaperClickPopover>
60+
);
61+
};

client/packages/host/src/components/LanguageMenu.tsx

+1-9
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ export const LanguageMenu: React.FC = () => {
1616
navigate(0);
1717
};
1818

19-
const options = [
20-
{ label: 'عربي', value: 'ar' },
21-
{ label: 'Français', value: 'fr' },
22-
{ label: 'English', value: 'en' },
23-
{ label: 'Española', value: 'es' },
24-
{ label: 'Tetum', value: 'tet' },
25-
];
26-
2719
const renderOption = (option: Option) => (
2820
<MenuItem
2921
key={option.value}
@@ -37,7 +29,7 @@ export const LanguageMenu: React.FC = () => {
3729
return (
3830
<Select
3931
onChange={handleChange}
40-
options={options}
32+
options={IntlUtils.languageOptions}
4133
value={i18n.language}
4234
renderOption={renderOption}
4335
/>

server/graphql/types/src/types/user.rs

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub enum LanguageType {
5050
Khmer,
5151
Portuguese,
5252
Russian,
53+
Tetum,
5354
}
5455

5556
#[derive(SimpleObject)]
@@ -133,6 +134,7 @@ impl LanguageType {
133134
Language::Khmer => Self::Khmer,
134135
Language::Portuguese => Self::Portuguese,
135136
Language::Russian => Self::Russian,
137+
Language::Tetum => Self::Tetum,
136138
}
137139
}
138140
}

server/repository/migrations/postgres/2022-10-27T09-15_v103/up.sql

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
CREATE TYPE language_type AS ENUM (
1+
CREATE TYPE language_type AS ENUM
2+
(
23
'ENGLISH',
34
'FRENCH',
45
'SPANISH',
56
'LAOS',
67
'KHMER',
78
'PORTUGUESE',
8-
'RUSSIAN'
9+
'RUSSIAN',
10+
'TETUM'
911
);
1012

1113
ALTER TABLE user_account

server/repository/src/db_diesel/user_row.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub enum Language {
2626
Khmer,
2727
Portuguese,
2828
Russian,
29+
Tetum,
2930
}
3031

3132
impl Default for Language {

server/repository/src/migrations/v1_01_03/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ impl Migration for V1_01_03 {
4141
);"#
4242
)?;
4343

44+
#[cfg(feature = "postgres")]
45+
sql!(
46+
connection,
47+
r#"ALTER TYPE language_type ADD VALUE IF NOT EXISTS 'TETUM';"#
48+
)?;
49+
4450
Ok(())
4551
}
4652
}

server/service/src/login.rs

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ impl LoginService {
237237
4 => Language::Khmer,
238238
5 => Language::Portuguese,
239239
6 => Language::Russian,
240+
7 => Language::Tetum,
240241
_ => Language::English,
241242
},
242243
};

0 commit comments

Comments
 (0)