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