From d5db054af229d0889d285a5b1cf98deb43298273 Mon Sep 17 00:00:00 2001 From: oitsjustjose Date: Wed, 27 Apr 2022 09:15:34 -0500 Subject: [PATCH] Localize things --- .gitignore | 1 + frontend/src/global/components/Loading.jsx | 3 +- frontend/src/global/i18n.js | 34 ++++++++++++++----- frontend/src/pages/Home/components/Card.jsx | 3 +- frontend/src/pages/Home/index.jsx | 2 +- .../pages/Manage/components/FileUpload.jsx | 2 +- .../pages/Manage/components/modal/Edit.jsx | 18 +++++----- .../src/pages/Manage/components/modal/New.jsx | 16 +++++---- frontend/src/pages/Manage/index.jsx | 14 ++++---- frontend/src/pages/Product/index.jsx | 8 +++-- frontend/src/pages/User/Login.jsx | 4 +-- 11 files changed, 66 insertions(+), 39 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b7a038 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +frontend/.envrc diff --git a/frontend/src/global/components/Loading.jsx b/frontend/src/global/components/Loading.jsx index fa7225a..ffd7799 100644 --- a/frontend/src/global/components/Loading.jsx +++ b/frontend/src/global/components/Loading.jsx @@ -1,5 +1,6 @@ import React from 'react'; import { Flex, Heading, Spinner } from '@chakra-ui/react'; +import { General as i18n } from '../i18n'; export default () => (
@@ -13,7 +14,7 @@ export default () => ( /> - Loading + {i18n.loading}
); diff --git a/frontend/src/global/i18n.js b/frontend/src/global/i18n.js index 0c8ce9e..14d6fbe 100644 --- a/frontend/src/global/i18n.js +++ b/frontend/src/global/i18n.js @@ -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', }, }, diff --git a/frontend/src/pages/Home/components/Card.jsx b/frontend/src/pages/Home/components/Card.jsx index dcef8f6..35ddaf9 100644 --- a/frontend/src/pages/Home/components/Card.jsx +++ b/frontend/src/pages/Home/components/Card.jsx @@ -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} - {product.quantity === 0 ? 'Sold Out' : `$${product.price}`} + {product.quantity === 0 ? i18n.soldOut : `$${product.price}`} diff --git a/frontend/src/pages/Home/index.jsx b/frontend/src/pages/Home/index.jsx index 247d24d..4023fd6 100644 --- a/frontend/src/pages/Home/index.jsx +++ b/frontend/src/pages/Home/index.jsx @@ -42,7 +42,7 @@ export default () => { return (
- OpenCommerce Store + {process.env.REACT_APP_NAME} inputRef.current.click()} readOnly background="blue.300" - value={i18n.create.fileUpload(files.length)} + value={i18n.fileUpload(files.length)} /> ); diff --git a/frontend/src/pages/Manage/components/modal/Edit.jsx b/frontend/src/pages/Manage/components/modal/Edit.jsx index ff78e66..50f7062 100644 --- a/frontend/src/pages/Manage/components/modal/Edit.jsx +++ b/frontend/src/pages/Manage/components/modal/Edit.jsx @@ -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 }) => { > - )} text="Qty" /> + )} text={i18n.labels.qty} /> {/* Use currency input to nicely handle whole numerical values */} { margin="auto" > - )} text="Price" /> + + )} text={i18n.labels.price} /> + { { // 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), diff --git a/frontend/src/pages/Manage/components/modal/New.jsx b/frontend/src/pages/Manage/components/modal/New.jsx index 62ea95f..d51eae0 100644 --- a/frontend/src/pages/Manage/components/modal/New.jsx +++ b/frontend/src/pages/Manage/components/modal/New.jsx @@ -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 }) => { > - )} text="Qty" /> + )} text={i18n.labels.qty} /> {/* Use currency input to nicely handle whole numerical values */} { margin="auto" > - )} text="Price" /> + + )} text={i18n.labels.price} /> + { type="submit" onClick={() => save().then((x) => { if (x) closeModal(); })} > - {i18n.labels.save} + {i18n.labels.saveProduct}
diff --git a/frontend/src/pages/Manage/index.jsx b/frontend/src/pages/Manage/index.jsx index 2bf3af8..7e56f40 100644 --- a/frontend/src/pages/Manage/index.jsx +++ b/frontend/src/pages/Manage/index.jsx @@ -47,10 +47,10 @@ export default () => { return (
- OpenCommerce Store + {process.env.REACT_APP_NAME} - Product Management + {i18n.title} @@ -60,16 +60,16 @@ export default () => { propKeyPressEvt={() => {}} propSubmitEvt={() => {}} type="text" - labelBgColor="green.400" + labelBgColor="purple.400" labelFgColor="white" labelIcon={()} - labelText="Search.." + labelText={i18n.labels.search} error={null} /> - @@ -96,7 +96,7 @@ export default () => { {x.name} {`$${x.price}`} {x.quantity} - {x.overallRating || 'No Reviews'} + {x.overallRating || i18n.labels.noReview} ))} diff --git a/frontend/src/pages/Product/index.jsx b/frontend/src/pages/Product/index.jsx index 60baa1f..9da3f3a 100644 --- a/frontend/src/pages/Product/index.jsx +++ b/frontend/src/pages/Product/index.jsx @@ -57,7 +57,9 @@ export default () => { ) : ( - (No Photos Available) + ( + {i18n.noPhotos} + ) )} @@ -71,14 +73,14 @@ export default () => {
- Description + {i18n.description} {product.name} { } 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} > - )} text={i18n.buttons.submit} /> + )} text={i18n.labels.submit} />