Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React-intl: Add i18n to SpeedRunEthereum #187

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
02a6cc1
Re-do commit 583ef70 on current master
dgrcode Mar 31, 2023
562f81a
Add missing script
dgrcode Mar 31, 2023
e1dde36
Add extracting and compiling scripts
dgrcode Apr 3, 2023
5e6f1fa
Add a couple of examples and extract them
dgrcode Apr 3, 2023
a2e1b05
Add i18n to HomeView
dgrcode Apr 16, 2023
3cc4540
Add i18n to ChallengeExpandedCard
dgrcode Apr 16, 2023
3f3abca
Add key to remove warning
dgrcode Apr 17, 2023
84b3ef5
Add i18n to JoinBG
dgrcode Apr 17, 2023
351aed5
Add i18n to BuilderChallenges
dgrcode Apr 17, 2023
6e8fe9c
Add i18n to BuilderProfileCard
dgrcode Apr 17, 2023
884ffc5
Add i18n to JoinedBuidlGuidlBanner
dgrcode Apr 19, 2023
f8196ea
Add i18n to BuilderProfileHeader
dgrcode Apr 19, 2023
71a9fdf
Add i18n to BuilderChallenges
dgrcode Apr 19, 2023
3667738
Add i18n to ChallengeStatusTag
dgrcode Apr 19, 2023
a47ebb3
Add i18n to ChallengeDetailView
dgrcode Apr 24, 2023
92e2bfd
Add i18n to ChallengeSubmission
dgrcode Apr 24, 2023
1369ad9
Use 'general' to group generic messages
dgrcode Apr 24, 2023
01548a1
Fix typo
dgrcode Apr 24, 2023
e48bef5
Add i18n to challenges.js
dgrcode Apr 28, 2023
441875b
Remove lang switch example button
dgrcode Apr 28, 2023
15fbb31
Remove unused import
dgrcode May 3, 2023
146cf9c
Fix div as child of p
dgrcode May 3, 2023
fa28e0f
Add intl dependency to useEffect
dgrcode May 3, 2023
36b459d
Merge branch 'master' into react-intl
carletex May 8, 2023
6a85ac3
Removed unused prop setLocale
dgrcode May 11, 2023
8b8f395
Add i18n to navlinks and footer
dgrcode May 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,11 @@ Then re-run:
```bash
yarn backend
```

## Translations

Extract and compile strings ([docs](https://formatjs.io/docs/tooling/cli/#extraction-and-compilation-with-a-single-script)) (run in react-app folder):

```
yarn translations-extract
```
5 changes: 4 additions & 1 deletion packages/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"react": "^16.14.0",
"react-blockies": "^1.4.1",
"react-dom": "^16.14.0",
"react-intl": "^6.3.2",
"react-markdown": "^7.1.0",
"react-qr-reader": "^2.2.1",
"react-router-dom": "^5.2.0",
Expand All @@ -63,6 +64,7 @@
"web3modal": "^1.9.1"
},
"devDependencies": {
"@formatjs/cli": "^6.0.4",
"@testing-library/dom": "^6.12.2",
"@types/react": "^16.9.19",
"autoprefixer": "^10.2.4",
Expand Down Expand Up @@ -101,6 +103,7 @@
"s3": "node ./scripts/s3.js",
"ship": "yarn surge",
"theme": "npx gulp less",
"watch": "node ./scripts/watch.js"
"watch": "node ./scripts/watch.js",
"translations-extract": "formatjs extract 'src/**/*.js*' --ignore='**/*.json' --out-file src/lang/extractions.json --flatten --id-interpolation-pattern '[sha512:contenthash:base64:6]' && formatjs compile 'src/lang/extractions.json' --out-file src/lang/en.json && rm src/lang/extractions.json"
}
}
3 changes: 2 additions & 1 deletion packages/react-app/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const web3Modal = new Web3Modal({
},
});

function App() {
function App({ setLocale }) {
dgrcode marked this conversation as resolved.
Show resolved Hide resolved
const [providers, setProviders] = useState({
mainnet: { provider: null, isReady: false },
local: { provider: null, isReady: false },
Expand Down Expand Up @@ -166,6 +166,7 @@ function App() {
}
}, [address, fetchUserData]);


return (
<BlockchainProvidersContext.Provider value={providers}>
<div className="App">
Expand Down
4 changes: 2 additions & 2 deletions packages/react-app/src/components/Account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
LinkBox,
LinkOverlay,
} from "@chakra-ui/react";
import { FormattedMessage } from "react-intl";
import QRPunkBlockie from "./QrPunkBlockie";
import useDisplayAddress from "../hooks/useDisplayAddress";
import useCustomColorModes from "../hooks/useCustomColorModes";
Expand Down Expand Up @@ -63,7 +64,6 @@ import SignatureSignUp from "./SignatureSignUp";

export default function Account({
address,
connectText,
ensProvider,
isWalletConnected,
loadWeb3Modal,
Expand Down Expand Up @@ -92,7 +92,7 @@ export default function Account({

const connectWallet = (
<Button colorScheme="green" key="loginbutton" onClick={loadWeb3Modal}>
{connectText || "connect"}
<FormattedMessage id="account.connect-wallet" defaultMessage="Connect Wallet" />
</Button>
);

Expand Down
23 changes: 17 additions & 6 deletions packages/react-app/src/components/AnnouncementBanner.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import React from "react";
import { chakra, useColorModeValue, Link } from "@chakra-ui/react";
import { FormattedMessage } from "react-intl";

export default function AnnouncementBanner() {
const bannerBg = useColorModeValue("#fbf7f6", "whiteAlpha.300");

return (
<chakra.div textAlign="center" padding="20px" bgColor={bannerBg}>
Hey builder!! The BuidlGuidl is hosting a{" "}
<Link href="https://hackathon.buidlguidl.com/" fontWeight="700" color="teal.500" isExternal>
🏗 Scaffold-Eth 2 hackathon
</Link>
. We are giving 10 ETH away to the best projects.
<br /> Come join the fun and learn the latest scaffold-eth techniques! Let's build a bunch of apps!
<FormattedMessage
id="announcementBanner"
defaultMessage={`Hey builder!! The BuidlGuidl is hosting a
<Link>🏗 Scaffold-Eth 2 hackathon</Link>.
We are giving 10 ETH away to the best projects.
{br}Come join the fun and learn the latest scaffold-eth techniques!
Let's build a bunch of apps!`}
values={{
Link: chunks => (
<Link href="https://hackathon.buidlguidl.com/" fontWeight="700" color="teal.500" isExternal>
{chunks}
</Link>
),
br: <br />,
}}
/>
</chakra.div>
);
}
11 changes: 6 additions & 5 deletions packages/react-app/src/components/ChallengeExpandedCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useColorModeValue,
VStack,
} from "@chakra-ui/react";
import { FormattedMessage } from "react-intl";

import useCustomColorModes from "../hooks/useCustomColorModes";
import { CHALLENGE_SUBMISSION_STATUS } from "../helpers/constants";
Expand Down Expand Up @@ -137,15 +138,15 @@ const ChallengeExpandedCard = ({
fontSize={{ base: "xl", lg: "lg" }}
border="2px"
backgroundColor="sreDark.default"
disabled={true}
disabled
borderColor="sre.default"
py="1rem"
px={4}
>
<Flex justifyContent="center" alignItems="center">
<PadLockIcon w={6} h={6} />
<chakra.span color="sre.text" ml={2} textTransform="uppercase" fontWeight="medium">
Locked
<FormattedMessage id="general.locked" defaultMessage="Locked" />
</chakra.span>
</Flex>
</Button>
Expand Down Expand Up @@ -285,7 +286,7 @@ const ChallengeExpandedCard = ({
<Flex justifyContent="center">
<PadLockIcon w={6} h={6} />
<chakra.span color={primaryFontColor} ml={2} textTransform="uppercase">
Locked
<FormattedMessage id="general.locked" defaultMessage="Locked" />
</chakra.span>
</Flex>
)}
Expand Down Expand Up @@ -316,14 +317,14 @@ const ChallengeExpandedCard = ({
<Flex justifyContent="center" alignItems="center">
<CrossedSwordsIcon w={6} h={6} />
<chakra.span color={primaryFontColor} ml={2} textTransform="uppercase" fontWeight="medium">
Quest
<FormattedMessage id="general.quest" defaultMessage="Quest" />
</chakra.span>
</Flex>
) : (
<Flex justifyContent="center">
<PadLockIcon w={6} h={6} />
<chakra.span color={primaryFontColor} ml={2} textTransform="uppercase" fontWeight="medium">
Locked
<FormattedMessage id="general.locked" defaultMessage="Locked" />
</chakra.span>
</Flex>
)}
Expand Down
6 changes: 5 additions & 1 deletion packages/react-app/src/components/ChallengeReviewRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ import {
import { useUserAddress } from "eth-hooks";
import ReactMarkdown from "react-markdown";
import ChakraUIRenderer from "chakra-ui-markdown-renderer";
import { useIntl } from "react-intl";
import Address from "./Address";
import DateWithTooltip from "./DateWithTooltip";
import { challengeInfo } from "../data/challenges";
import { getChallengeInfo } from "../data/challenges";
import { chakraMarkdownComponents } from "../helpers/chakraMarkdownTheme";
import { runAutograderTest } from "../data/api";
import { isBoolean } from "../helpers/strings";
Expand All @@ -52,6 +53,9 @@ export default function ChallengeReviewRow({ challenge, isLoading, approveClick,
const address = useUserAddress(userProvider);
const { linkColor } = useCustomColorModes();

const intl = useIntl();
const challengeInfo = getChallengeInfo(intl);

if (!challengeInfo[challenge.id]) {
return null;
}
Expand Down
22 changes: 17 additions & 5 deletions packages/react-app/src/components/ChallengeStatusTag.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,33 @@ import { QuestionOutlineIcon } from "@chakra-ui/icons";
import ReactMarkdown from "react-markdown";
import remarkBreaks from "remark-breaks";
import ChakraUIRenderer from "chakra-ui-markdown-renderer";
import { FormattedMessage, useIntl } from "react-intl";
import { CHALLENGE_SUBMISSION_STATUS } from "../helpers/constants";
import { chakraMarkdownComponents } from "../helpers/chakraMarkdownTheme";

const ChallengeStatusTag = ({ status, comment, autograding }) => {
const { isOpen, onOpen, onClose } = useDisclosure();
const intl = useIntl();

let colorScheme;
let label;

switch (status) {
case CHALLENGE_SUBMISSION_STATUS.ACCEPTED: {
colorScheme = "green";
label = "Accepted";
label = intl.formatMessage({
id: "general.accepted",
defaultMessage: "Accepted",
});
break;
}
case CHALLENGE_SUBMISSION_STATUS.REJECTED: {
colorScheme = "red";
label = "Rejected";
label = intl.formatMessage({ id: "general.rejected", defaultMessage: "Rejected" });
break;
}
case CHALLENGE_SUBMISSION_STATUS.SUBMITTED: {
label = "Submitted";
label = intl.formatMessage({ id: "general.submitted", defaultMessage: "Submitted" });
break;
}
default:
Expand All @@ -56,7 +61,12 @@ const ChallengeStatusTag = ({ status, comment, autograding }) => {
</Box>
<Spacer />
{status !== CHALLENGE_SUBMISSION_STATUS.SUBMITTED && comment && (
<Tooltip label="See comment">
<Tooltip
label={intl.formatMessage({
id: "challengeStatusTag.see-comments",
defaultMessage: "See comments",
})}
>
<Button variant="ghost" onClick={onOpen} p={0} ml={1}>
<QuestionOutlineIcon ml="2px" />
</Button>
Expand All @@ -66,7 +76,9 @@ const ChallengeStatusTag = ({ status, comment, autograding }) => {
<Modal isOpen={isOpen} onClose={onClose} size="xl">
<ModalOverlay />
<ModalContent maxW="56rem">
<ModalHeader>Review feedback</ModalHeader>
<ModalHeader>
<FormattedMessage id="challengeStatusTag.modal.header" defaultMessage="Review feedback" />
</ModalHeader>
<ModalCloseButton />
<ModalBody p={6} overflowX="auto">
{autograding ? (
Expand Down
Loading