Localize things
This commit is contained in:
parent
de582afe95
commit
d5db054af2
11 changed files with 66 additions and 39 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
frontend/.envrc
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Flex, Heading, Spinner } from '@chakra-ui/react';
|
import { Flex, Heading, Spinner } from '@chakra-ui/react';
|
||||||
|
import { General as i18n } from '../i18n';
|
||||||
|
|
||||||
export default () => (
|
export default () => (
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -13,7 +14,7 @@ export default () => (
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex justifyContent="center" alignItems="center" mt={2}>
|
<Flex justifyContent="center" alignItems="center" mt={2}>
|
||||||
<Heading size="lg"> Loading</Heading>
|
<Heading size="lg">{i18n.loading}</Heading>
|
||||||
</Flex>
|
</Flex>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ export const General = new LocalizedStrings({
|
||||||
login: 'Log In',
|
login: 'Log In',
|
||||||
logout: 'Log Out',
|
logout: 'Log Out',
|
||||||
changeColorMode: 'Toggle Light/Dark Theme',
|
changeColorMode: 'Toggle Light/Dark Theme',
|
||||||
|
loading: 'Loading..',
|
||||||
footer: {
|
footer: {
|
||||||
part1: 'Made with 💙 by',
|
part1: 'Made with 💙 by',
|
||||||
part2: 'using',
|
part2: 'using',
|
||||||
|
|
@ -28,22 +29,38 @@ export const Home = new LocalizedStrings({
|
||||||
|
|
||||||
export const Product = new LocalizedStrings({
|
export const Product = new LocalizedStrings({
|
||||||
en: {
|
en: {
|
||||||
|
soldOut: 'Sold Out',
|
||||||
|
addToCart: 'Add To Cart',
|
||||||
|
description: 'Description',
|
||||||
|
noPhotos: 'No Photos Available',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Manage = new LocalizedStrings({
|
export const Manage = new LocalizedStrings({
|
||||||
en: {
|
en: {
|
||||||
|
title: 'Product Management',
|
||||||
edit: {
|
edit: {
|
||||||
title: (name) => `Editing ${name}`,
|
title: (name) => `Editing ${name}`,
|
||||||
|
alerts: {
|
||||||
|
success: 'Product Updated Successfully!',
|
||||||
|
failure: 'Failed to Edit Product',
|
||||||
|
delete: 'Are you sure you want to delete this product?',
|
||||||
|
deleteImage: 'Do you want to delete this image?',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
|
button: 'Create',
|
||||||
title: 'Create Product',
|
title: 'Create Product',
|
||||||
fileUpload: (count) => `${count || 'No'} ${count === 1 ? 'File' : 'Files'} Selected`,
|
alerts: {
|
||||||
itemCreatedSuccess: (id) => ({
|
success: 'Product Created Successfully!',
|
||||||
header: 'Item Added!',
|
failure: 'Failed to Create Product',
|
||||||
content: `Item created with ID ${id}`,
|
},
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
|
missingInfo: {
|
||||||
|
header: 'Missing Info',
|
||||||
|
content: 'Not all required fields have been filled. Please provide this info to proceed.',
|
||||||
|
},
|
||||||
|
fileUpload: (count) => `${count || 'No'} ${count === 1 ? 'File' : 'Files'} Selected`,
|
||||||
labels: {
|
labels: {
|
||||||
name: 'Name',
|
name: 'Name',
|
||||||
desc: 'Description',
|
desc: 'Description',
|
||||||
|
|
@ -52,15 +69,18 @@ export const Manage = new LocalizedStrings({
|
||||||
rating: 'Rating',
|
rating: 'Rating',
|
||||||
hidden: 'Hidden',
|
hidden: 'Hidden',
|
||||||
required: 'This Field is Required',
|
required: 'This Field is Required',
|
||||||
save: 'Save Product',
|
saveProduct: 'Save Product',
|
||||||
saveChanges: 'Save Changes',
|
saveChanges: 'Save Changes',
|
||||||
delete: 'Delete Product',
|
delete: 'Delete Product',
|
||||||
|
search: 'Search..',
|
||||||
|
noReview: 'No Reviews',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const Login = new LocalizedStrings({
|
export const Login = new LocalizedStrings({
|
||||||
en: {
|
en: {
|
||||||
|
error: 'There was an Error Logging In',
|
||||||
logoutAlert: {
|
logoutAlert: {
|
||||||
header: 'You Have Been Logged Out',
|
header: 'You Have Been Logged Out',
|
||||||
content: 'You\'ve been logged out automatically as it has been more than 1 day since you last logged in. Please log in again.',
|
content: 'You\'ve been logged out automatically as it has been more than 1 day since you last logged in. Please log in again.',
|
||||||
|
|
@ -70,8 +90,6 @@ export const Login = new LocalizedStrings({
|
||||||
email: 'Email Address',
|
email: 'Email Address',
|
||||||
password: 'Password',
|
password: 'Password',
|
||||||
required: 'This Field is Required',
|
required: 'This Field is Required',
|
||||||
},
|
|
||||||
buttons: {
|
|
||||||
submit: 'Log In',
|
submit: 'Log In',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import {
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { BsStarFill, BsStarHalf } from 'react-icons/bs';
|
import { BsStarFill, BsStarHalf } from 'react-icons/bs';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { Product as i18n } from '../../../global/i18n';
|
||||||
|
|
||||||
export default ({ product }) => {
|
export default ({ product }) => {
|
||||||
const filtered = product.images.filter((x) => x !== null);
|
const filtered = product.images.filter((x) => x !== null);
|
||||||
|
|
@ -62,7 +63,7 @@ export default ({ product }) => {
|
||||||
{product.name}
|
{product.name}
|
||||||
</Heading>
|
</Heading>
|
||||||
<Text color="gray.500" fontSize="sm" textTransform="uppercase">
|
<Text color="gray.500" fontSize="sm" textTransform="uppercase">
|
||||||
{product.quantity === 0 ? 'Sold Out' : `$${product.price}`}
|
{product.quantity === 0 ? i18n.soldOut : `$${product.price}`}
|
||||||
</Text>
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ export default () => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Heading textAlign="center">
|
<Heading textAlign="center">
|
||||||
OpenCommerce Store
|
{process.env.REACT_APP_NAME}
|
||||||
</Heading>
|
</Heading>
|
||||||
<Box maxW="400px" m="auto">
|
<Box maxW="400px" m="auto">
|
||||||
<InlineLabelInput
|
<InlineLabelInput
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ export default ({
|
||||||
onClick={() => inputRef.current.click()}
|
onClick={() => inputRef.current.click()}
|
||||||
readOnly
|
readOnly
|
||||||
background="blue.300"
|
background="blue.300"
|
||||||
value={i18n.create.fileUpload(files.length)}
|
value={i18n.fileUpload(files.length)}
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ export default ({ product, closeModal }) => {
|
||||||
const save = async () => {
|
const save = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
if (!state.name.length || !state.quantity || !state.price || !state.description) {
|
if (!state.name.length || !state.quantity || !state.price || !state.description) {
|
||||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Missing Info', content: 'Not all required fields have been filled. Please provide this info to proceed.' } });
|
store.dispatch({ type: 'SET_ALERT', data: i18n.missingInfo });
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -50,13 +50,13 @@ export default ({ product, closeModal }) => {
|
||||||
|
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
setToast('Product Updated Successfully!', '', 'success');
|
setToast(i18n.edit.alerts.success, '', 'success');
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
setToast('Failed to Edit Product', data?.error || '', 'error');
|
setToast(i18n.edit.alerts.failure, data?.error || '', 'error');
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
setToast('Failed to Edit Product', ex || '', 'error');
|
setToast(i18n.edit.alerts.failure, ex || '', 'error');
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -64,7 +64,7 @@ export default ({ product, closeModal }) => {
|
||||||
|
|
||||||
const del = async () => {
|
const del = async () => {
|
||||||
// eslint-disable-next-line no-alert
|
// eslint-disable-next-line no-alert
|
||||||
if (window.confirm('Are you sure you want to delete this Product?')) {
|
if (window.confirm(i18n.edit.alerts.delete)) {
|
||||||
// eslint-disable-next-line no-underscore-dangle
|
// eslint-disable-next-line no-underscore-dangle
|
||||||
const resp = await fetch(`/api/v1/products/${product._id}`, {
|
const resp = await fetch(`/api/v1/products/${product._id}`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
|
|
@ -139,7 +139,7 @@ export default ({ product, closeModal }) => {
|
||||||
>
|
>
|
||||||
<InputGroup style={InputGroupStyle}>
|
<InputGroup style={InputGroupStyle}>
|
||||||
<InputLeftAddon backgroundColor="#8a56c2" color="white">
|
<InputLeftAddon backgroundColor="#8a56c2" color="white">
|
||||||
<IconTextDuo icon={(<AiOutlineNumber />)} text="Qty" />
|
<IconTextDuo icon={(<AiOutlineNumber />)} text={i18n.labels.qty} />
|
||||||
</InputLeftAddon>
|
</InputLeftAddon>
|
||||||
{/* Use currency input to nicely handle whole numerical values */}
|
{/* Use currency input to nicely handle whole numerical values */}
|
||||||
<CurrencyInput
|
<CurrencyInput
|
||||||
|
|
@ -164,7 +164,9 @@ export default ({ product, closeModal }) => {
|
||||||
margin="auto"
|
margin="auto"
|
||||||
>
|
>
|
||||||
<InputGroup style={InputGroupStyle}>
|
<InputGroup style={InputGroupStyle}>
|
||||||
<InputLeftAddon backgroundColor="#fbb355" color="black"><IconTextDuo icon={(<BsCurrencyDollar />)} text="Price" /></InputLeftAddon>
|
<InputLeftAddon backgroundColor="#fbb355" color="black">
|
||||||
|
<IconTextDuo icon={(<BsCurrencyDollar />)} text={i18n.labels.price} />
|
||||||
|
</InputLeftAddon>
|
||||||
<CurrencyInput
|
<CurrencyInput
|
||||||
prefix="$"
|
prefix="$"
|
||||||
decimalsLimit={2}
|
decimalsLimit={2}
|
||||||
|
|
@ -205,7 +207,7 @@ export default ({ product, closeModal }) => {
|
||||||
<DeletableImage
|
<DeletableImage
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
// eslint-disable-next-line no-alert
|
// eslint-disable-next-line no-alert
|
||||||
if (window.confirm('Do you want to delete this image?')) {
|
if (window.confirm(i18n.edit.alerts.deleteImage)) {
|
||||||
setState({
|
setState({
|
||||||
...state,
|
...state,
|
||||||
images: state.images.filter((i) => i !== x),
|
images: state.images.filter((i) => i !== x),
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ export default ({ closeModal }) => {
|
||||||
const save = async () => {
|
const save = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
if (!state.name.length || !state.quantity || !state.price || !state.description) {
|
if (!state.name.length || !state.quantity || !state.price || !state.description) {
|
||||||
store.dispatch({ type: 'SET_ALERT', data: { header: 'Missing Info', content: 'Not all required fields have been filled. Please provide this info to proceed.' } });
|
store.dispatch({ type: 'SET_ALERT', data: i18n.missingInfo });
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -47,13 +47,13 @@ export default ({ closeModal }) => {
|
||||||
|
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
setToast('Added New Product Successfully!', '', 'success');
|
setToast(i18n.create.alerts.success, '', 'success');
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
setToast('Failed to Add Product', data?.error || '', 'error');
|
setToast(i18n.create.alerts.failure, data?.error || '', 'error');
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
setToast('Failed to Add Product', ex || '', 'error');
|
setToast(i18n.create.alerts.failure, ex || '', 'error');
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -122,7 +122,7 @@ export default ({ closeModal }) => {
|
||||||
>
|
>
|
||||||
<InputGroup style={InputGroupStyle}>
|
<InputGroup style={InputGroupStyle}>
|
||||||
<InputLeftAddon backgroundColor="#8a56c2" color="white">
|
<InputLeftAddon backgroundColor="#8a56c2" color="white">
|
||||||
<IconTextDuo icon={(<AiOutlineNumber />)} text="Qty" />
|
<IconTextDuo icon={(<AiOutlineNumber />)} text={i18n.labels.qty} />
|
||||||
</InputLeftAddon>
|
</InputLeftAddon>
|
||||||
{/* Use currency input to nicely handle whole numerical values */}
|
{/* Use currency input to nicely handle whole numerical values */}
|
||||||
<CurrencyInput
|
<CurrencyInput
|
||||||
|
|
@ -146,7 +146,9 @@ export default ({ closeModal }) => {
|
||||||
margin="auto"
|
margin="auto"
|
||||||
>
|
>
|
||||||
<InputGroup style={InputGroupStyle}>
|
<InputGroup style={InputGroupStyle}>
|
||||||
<InputLeftAddon backgroundColor="#fbb355" color="black"><IconTextDuo icon={(<BsCurrencyDollar />)} text="Price" /></InputLeftAddon>
|
<InputLeftAddon backgroundColor="#fbb355" color="black">
|
||||||
|
<IconTextDuo icon={(<BsCurrencyDollar />)} text={i18n.labels.price} />
|
||||||
|
</InputLeftAddon>
|
||||||
<CurrencyInput
|
<CurrencyInput
|
||||||
prefix="$"
|
prefix="$"
|
||||||
decimalsLimit={2}
|
decimalsLimit={2}
|
||||||
|
|
@ -189,7 +191,7 @@ export default ({ closeModal }) => {
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={() => save().then((x) => { if (x) closeModal(); })}
|
onClick={() => save().then((x) => { if (x) closeModal(); })}
|
||||||
>
|
>
|
||||||
{i18n.labels.save}
|
{i18n.labels.saveProduct}
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -47,10 +47,10 @@ export default () => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Heading my={3} textAlign="center">
|
<Heading my={3} textAlign="center">
|
||||||
OpenCommerce Store
|
{process.env.REACT_APP_NAME}
|
||||||
</Heading>
|
</Heading>
|
||||||
<Heading size="md" my={3} textAlign="center">
|
<Heading size="md" my={3} textAlign="center">
|
||||||
Product Management
|
{i18n.title}
|
||||||
</Heading>
|
</Heading>
|
||||||
|
|
||||||
<Flex justifyContent="center" alignItems="center">
|
<Flex justifyContent="center" alignItems="center">
|
||||||
|
|
@ -60,16 +60,16 @@ export default () => {
|
||||||
propKeyPressEvt={() => {}}
|
propKeyPressEvt={() => {}}
|
||||||
propSubmitEvt={() => {}}
|
propSubmitEvt={() => {}}
|
||||||
type="text"
|
type="text"
|
||||||
labelBgColor="green.400"
|
labelBgColor="purple.400"
|
||||||
labelFgColor="white"
|
labelFgColor="white"
|
||||||
labelIcon={(<BiSearchAlt2 />)}
|
labelIcon={(<BiSearchAlt2 />)}
|
||||||
labelText="Search.."
|
labelText={i18n.labels.search}
|
||||||
error={null}
|
error={null}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Button backgroundColor="green.400" onClick={() => setNewModal(true)}>
|
<Button colorScheme="blue" onClick={() => setNewModal(true)}>
|
||||||
<IconTextDuo text="Create" icon={(<BiPlus />)} />
|
<IconTextDuo text={i18n.create.button} icon={(<BiPlus />)} />
|
||||||
</Button>
|
</Button>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
|
|
@ -96,7 +96,7 @@ export default () => {
|
||||||
<Td>{x.name}</Td>
|
<Td>{x.name}</Td>
|
||||||
<Td>{`$${x.price}`}</Td>
|
<Td>{`$${x.price}`}</Td>
|
||||||
<Td>{x.quantity}</Td>
|
<Td>{x.quantity}</Td>
|
||||||
<Td>{x.overallRating || 'No Reviews'}</Td>
|
<Td>{x.overallRating || i18n.labels.noReview}</Td>
|
||||||
</Tr>
|
</Tr>
|
||||||
))}
|
))}
|
||||||
</Tbody>
|
</Tbody>
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,9 @@ export default () => {
|
||||||
<Carousel photos={product.images} />
|
<Carousel photos={product.images} />
|
||||||
) : (
|
) : (
|
||||||
<Heading textAlign="center" size="md">
|
<Heading textAlign="center" size="md">
|
||||||
(No Photos Available)
|
(
|
||||||
|
{i18n.noPhotos}
|
||||||
|
)
|
||||||
</Heading>
|
</Heading>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -71,14 +73,14 @@ export default () => {
|
||||||
</Heading>
|
</Heading>
|
||||||
|
|
||||||
<Button colorScheme="green">
|
<Button colorScheme="green">
|
||||||
Add to Cart
|
{i18n.addToCart}
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<hr style={{ margin: '2rem auto' }} />
|
<hr style={{ margin: '2rem auto' }} />
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Heading my={3}>Description</Heading>
|
<Heading my={3}>{i18n.description}</Heading>
|
||||||
<Heading my={3} size="md">{product.name}</Heading>
|
<Heading my={3} size="md">{product.name}</Heading>
|
||||||
<ReactMarkdown
|
<ReactMarkdown
|
||||||
components={{ code: Code }}
|
components={{ code: Code }}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ export default () => {
|
||||||
} else {
|
} else {
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: 'SET_ALERT',
|
type: 'SET_ALERT',
|
||||||
data: { header: 'There was an Error Logging In', content: data.error },
|
data: { header: i18n.error, content: data.error },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ export default () => {
|
||||||
type="submit"
|
type="submit"
|
||||||
onClick={login}
|
onClick={login}
|
||||||
>
|
>
|
||||||
<IconTextDuo iconOnRight icon={(<MdLogin />)} text={i18n.buttons.submit} />
|
<IconTextDuo iconOnRight icon={(<MdLogin />)} text={i18n.labels.submit} />
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue