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

Language picker #12006

Merged
merged 55 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
75731c9
feat: add desktop locale-picker menu
wackerow Jan 15, 2024
027aab4
fix: pass direction to Chakra theme provider
wackerow Jan 15, 2024
a9c9f88
refactor: extract picker, fix display name logic
wackerow Jan 22, 2024
8bc2890
style: update language picker per design
wackerow Jan 22, 2024
800da6e
refactor: extract resuable Item, improve kbd nav
wackerow Jan 23, 2024
c4a43a8
fix: kbd input navigation for desktop lang picker
wackerow Jan 23, 2024
87d9030
feat: initial draft of mobile language picker
wackerow Jan 23, 2024
90e43f9
fix: locale display names
wackerow Jan 23, 2024
b125513
fix: prevent closing with click on input
wackerow Jan 23, 2024
c25761e
style: patch input color and mobile menu sizing
wackerow Jan 23, 2024
7363217
fix: close mobile menu on language selection
wackerow Jan 23, 2024
d38f027
Merge branch 'dev' into language-menu
wackerow Jan 23, 2024
cc8b5cb
feat: add getTranslationProgress github action
wackerow Jan 24, 2024
ac61dfd
feat: implement translation progress and indicator
wackerow Jan 24, 2024
8c71b41
feat: add browser locale highlight
wackerow Jan 24, 2024
47e3d40
fix: nav lang state
wackerow Jan 24, 2024
b8d1cb5
refactor: show en, patch mobile styling, linting
wackerow Jan 24, 2024
9913e0d
refactor: save word/phrase counts with progress
wackerow Jan 24, 2024
e1c2c6f
style: limit desktop menu height to 75vh
wackerow Jan 24, 2024
5aadc07
refactor: improve nomenclature, extract type
wackerow Jan 24, 2024
8eb8e3d
feat: add NoResultsCallout
wackerow Jan 24, 2024
956baf4
refactor: use closeOnSelect to keep menu open
wackerow Jan 24, 2024
e999e4a
feat: kbd shortcut for language menu / color mode
wackerow Jan 24, 2024
966a9ef
Merge branch 'dev' into language-menu
wackerow Jan 25, 2024
ecbcd1e
style: update styling per design
wackerow Jan 25, 2024
43f2f57
feat: add footer callout, sticky positioning
wackerow Jan 25, 2024
622a189
fix: crowdin lang code for urdu and nepali
wackerow Jan 25, 2024
02c42d0
fix: scroll container on kbd list navigation
wackerow Jan 25, 2024
9f82ccf
style: update progress bar and active colors
wackerow Jan 26, 2024
4c0e2d7
feat: enable multiple browser preferences
wackerow Jan 27, 2024
c9e23ee
refactor: menu footer using Button and Grid components
wackerow Jan 31, 2024
b372cb9
refactor: apply suggestions from code review
wackerow Jan 31, 2024
8b01dce
refactor: implement hamburger/close button redesign
wackerow Jan 31, 2024
22d4d6a
fix: update breakpoint
wackerow Jan 31, 2024
db1eb9a
style: current lang colors, add check icon
wackerow Jan 31, 2024
a3a34f0
style: add mobile overlay behind menu
wackerow Jan 31, 2024
1fe9d66
patch: boolean prop optional
wackerow Jan 31, 2024
4b3ccb5
i18n: extract LanguagePicker strings
wackerow Jan 31, 2024
62321eb
refactor: use languages util, rm root access
wackerow Jan 31, 2024
f0bbfe6
refactor: rm useEffect; type check for navigator
wackerow Jan 31, 2024
5795512
refactor: extract useLanguagePicker custom hook
wackerow Jan 31, 2024
95953cd
feat: add Matomo event tracking
wackerow Jan 31, 2024
16612ec
i18n: extract missing LanguagePicker strings
wackerow Jan 31, 2024
f203c26
Merge branch 'dev' into language-menu
wackerow Jan 31, 2024
2d6147b
refactor: reuse existing type, rm redundant entry
wackerow Jan 31, 2024
0b2cf23
feat: update matomo event tracking
wackerow Feb 1, 2024
b96e950
fix: remove initialFocusRef, add string namespace
wackerow Feb 1, 2024
fe1ed8a
feat: browser preference badge
wackerow Feb 5, 2024
23e7fda
chore: deprecate isBrowserPreference
wackerow Feb 5, 2024
c4e3639
chore: add missing hook dependency
wackerow Feb 5, 2024
2137963
chore: clean up unused variables
wackerow Feb 5, 2024
8c3576e
feat: keyboard navigation updates
wackerow Feb 6, 2024
72470f0
fix: mobile picker positioning
wackerow Feb 6, 2024
cb54a46
feat: hide "languages" below lg breakpoint
wackerow Feb 6, 2024
4172a13
fix: menu item styling
wackerow Feb 6, 2024
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
64 changes: 64 additions & 0 deletions .github/workflows/get-translation-progress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Update Crowdin translation progression

on:
schedule:
- cron: "20 16 * * FRI"
workflow_dispatch:

jobs:
create_pr:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
run: yarn install

- name: Install ts-node
run: yarn global add ts-node

- name: Set up git
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"

- name: Generate timestamp and readable date
id: date
run: |
echo "TIMESTAMP=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
echo "READABLE_DATE=$(date +'%B %-d')" >> $GITHUB_ENV

- name: Fetch latest dev and create new branch
run: |
git fetch origin dev
git checkout -b "automated-update-${{ env.TIMESTAMP }}" origin/dev

- name: Run script
run: npx ts-node -O '{"module":"commonjs"}' ./src/scripts/crowdin/getTranslationProgress.ts
env:
CROWDIN_API_KEY: ${{ secrets.CROWDIN_API_KEY }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}

- name: Commit and push
run: |
git add -A
git commit -m "Update Crowdin translation progress"
git push origin "automated-update-${{ env.TIMESTAMP }}"

- name: Create PR body
run: |
echo "This PR was automatically created to update Crowdin translation progress." > pr_body.txt
echo "This workflows runs every Friday at 16:20 (UTC)." >> pr_body.txt
echo "" >> pr_body.txt
echo "Thank you to everyone contributing to translate ethereum.org ❤️" >> pr_body.txt

- name: Create Pull Request
run: |
gh auth login --with-token <<< ${{ secrets.GITHUB_TOKEN }}
gh pr create --base dev --head "automated-update-${{ env.TIMESTAMP }}" --title "Update translation progress from Crowdin - ${{ env.READABLE_DATE }}" --body-file pr_body.txt
4 changes: 2 additions & 2 deletions i18n.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
},
{
"code": "ne-np",
"crowdinCode": "ne-np",
"crowdinCode": "ne-NP",
"name": "Nepali",
"localName": "नेपाली",
"langDir": "ltr",
Expand Down Expand Up @@ -457,7 +457,7 @@
},
{
"code": "ur",
"crowdinCode": "ur",
"crowdinCode": "ur-IN",
"name": "Urdu",
"localName": "اردو",
"langDir": "rtl",
Expand Down
127 changes: 127 additions & 0 deletions src/components/LanguagePicker/MenuItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { useRouter } from "next/router"
import { useTranslation } from "next-i18next"
import { BsCheck } from "react-icons/bs"
import {
Badge,
Box,
Flex,
forwardRef,
Icon,
MenuItem as ChakraMenuItem,
type MenuItemProps as ChakraMenuItemProps,
Text,
} from "@chakra-ui/react"

import type { LocaleDisplayInfo } from "@/lib/types"

import { BaseLink } from "@/components/Link"

import ProgressBar from "./ProgressBar"

type ItemProps = ChakraMenuItemProps & {
displayInfo: LocaleDisplayInfo
}

const MenuItem = forwardRef(({ displayInfo, ...props }: ItemProps, ref) => {
const {
localeOption,
sourceName,
targetName,
approvalProgress,
wordsApproved,
isBrowserDefault,
} = displayInfo
const { t } = useTranslation("page-languages")
const { asPath, locale } = useRouter()
const isCurrent = localeOption === locale

const getProgressInfo = (approvalProgress: number, wordsApproved: number) => {
const percentage = new Intl.NumberFormat(locale!, {
style: "percent",
}).format(approvalProgress / 100)
const progress =
approvalProgress === 0 ? "<" + percentage.replace("0", "1") : percentage
const words = new Intl.NumberFormat(locale!).format(wordsApproved)
return { progress, words }
}

const { progress, words } = getProgressInfo(approvalProgress, wordsApproved)

return (
<ChakraMenuItem
as={BaseLink}
ref={ref}
flexDir="column"
w="full"
mb="1"
display="block"
pt="2 !important"
alignItems="start"
borderRadius="base"
bg={isCurrent ? "background.base" : "transparent"}
color="body.base"
textDecoration="none"
data-group
onFocus={(e) => {
e.target.scrollIntoView({ block: "nearest" })
}}
scrollMarginY="8"
_hover={{ bg: "primary.lowContrast", textDecoration: "none" }}
_focus={{ bg: "primary.lowContrast" }}
sx={{
p: {
textDecoration: "none",
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
},
}}
href={asPath}
locale={localeOption}
{...props}
>
<Flex alignItems="center" w="full">
<Box flex={1}>
<Flex alignItems="center" gap={2}>
<Text
fontSize="lg"
color={isCurrent ? "primary.highContrast" : "primary.base"}
>
{targetName}
</Text>
{isBrowserDefault && (
<Badge
border="1px"
borderColor="body.medium"
color="body.medium"
lineHeight="none"
fontSize="2xs"
p="1"
h="fit-content"
bg="none"
>
{t("page-languages-browser-default")}
</Badge>
)}
</Flex>
<Text textTransform="uppercase" fontSize="xs" color="body.base">
{sourceName}
</Text>
</Box>
{isCurrent && <Icon as={BsCheck} fontSize="2xl" color="primary.highContrast" />}
</Flex>
<Text
textTransform="lowercase"
fontSize="xs"
color="body.medium"
maxW="full"
>
{progress} {t("page-languages-translated")} • {words}{" "}
{t("page-languages-words")}
</Text>
<ProgressBar value={approvalProgress} />
</ChakraMenuItem>
)
})

export default MenuItem
33 changes: 33 additions & 0 deletions src/components/LanguagePicker/NoResultsCallout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useTranslation } from "next-i18next"
import { FormHelperText, forwardRef, Text } from "@chakra-ui/react"

import { BaseLink } from "@/components/Link"

import MenuItem from "./MenuItem"

type NoResultsCalloutProps = { onClose: () => void }

const NoResultsCallout = forwardRef(
({ onClose }: NoResultsCalloutProps, ref) => {
const { t } = useTranslation("page-languages")
return (
<FormHelperText color="body.medium" lineHeight="base" fontSize="md">
<Text fontWeight="bold" mb="2" color="body.base">
{t("page-languages-want-more-header")}
</Text>
{t("page-languages-want-more-paragraph")}{" "}
<BaseLink
ref={ref}
as={MenuItem}
key="item-no-results"
href="contributing/translation-program"
onClick={onClose}
>
{t("page-languages-want-more-link")}
</BaseLink>
</FormHelperText>
)
}
)

export default NoResultsCallout
19 changes: 19 additions & 0 deletions src/components/LanguagePicker/ProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Progress, ProgressProps } from "@chakra-ui/react"

type ProgressBarProps = Pick<ProgressProps, "value">

const ProgressBar = ({ value }: ProgressBarProps) => (
<Progress
value={value}
h="0.5"
w="full"
bg="body.light"
sx={{
"[role=progressbar]": {
backgroundColor: "disabled",
},
}}
/>
)

export default ProgressBar
Loading
Loading