Skip to content

Commit

Permalink
feat: implement catch system for translation service (#616)
Browse files Browse the repository at this point in the history
* feat: add new translate catch template

* fix: wrap id with lang function
  • Loading branch information
bc-marco authored and CarlLiu2023 committed Sep 8, 2023
1 parent a004685 commit c5272b3
Show file tree
Hide file tree
Showing 100 changed files with 1,369 additions and 867 deletions.
3 changes: 3 additions & 0 deletions apps/storefront/src/components/HeadlessController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Dispatch, SetStateAction, useContext, useEffect, useRef } from 'react'
import { useDispatch } from 'react-redux'
import globalB3 from '@b3/global-b3'
import type { OpenPageState } from '@b3/hooks'
import { useB3Lang } from '@b3/lang'

import { HeadlessRoutes } from '@/constants'
import { addProductFromPage as addProductFromPageToShoppingList } from '@/hooks/dom/useOpenPDP'
Expand Down Expand Up @@ -116,6 +117,7 @@ export default function HeadlessController({
setOpenPage,
}: HeadlessControllerProps) {
const storeDispatch = useDispatch()
const b3Lang = useB3Lang()

const {
dispatch,
Expand Down Expand Up @@ -260,6 +262,7 @@ export default function HeadlessController({
isB2BUser: isB2BUserRef.current,
customerGroupId: customerRef.current.customerGroupId,
gotoShoppingDetail,
b3Lang,
}),
createNewShoppingList: async (name, description) => {
const { shoppingListsCreate } = await createShoppingList({
Expand Down
10 changes: 6 additions & 4 deletions apps/storefront/src/components/filter/B3FilterMore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useState,
} from 'react'
import { useForm } from 'react-hook-form'
import { useB3Lang } from '@b3/lang'
import FilterListIcon from '@mui/icons-material/FilterList'
import { Badge, Box, IconButton, useTheme } from '@mui/material'

Expand Down Expand Up @@ -82,6 +83,7 @@ function B3FilterMore<T, Y>({
})

const [isMobile] = useMobile()
const b3Lang = useB3Lang()

const theme = useTheme()
const primaryColor = theme.palette.primary.main
Expand Down Expand Up @@ -206,9 +208,9 @@ function B3FilterMore<T, Y>({

<B3Dialog
isOpen={open}
leftSizeBtn="Cancel"
rightSizeBtn="Apply"
title="Filters"
leftSizeBtn={b3Lang('global.filter.cancel')}
rightSizeBtn={b3Lang('global.filter.apply')}
title={b3Lang('global.filter.title')}
handleLeftClick={handleClose}
handRightClick={handleSaveFilters}
>
Expand Down Expand Up @@ -237,7 +239,7 @@ function B3FilterMore<T, Y>({
onClick={handleClearFilters}
size="small"
>
clear filters
{b3Lang('global.filter.clearFilters')}
</CustomButton>
</B3Dialog>
</Box>
Expand Down
5 changes: 4 additions & 1 deletion apps/storefront/src/components/filter/B3FilterSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChangeEvent, useEffect, useState } from 'react'
import { useB3Lang } from '@b3/lang'
import SearchIcon from '@mui/icons-material/Search'
import { InputBase, Paper } from '@mui/material'

Expand All @@ -18,11 +19,13 @@ function B3FilterSearch({
w = '100%',
h,
searchBGColor = '#efeae7',
placeholder = 'Search',
searchValue = '',
...restProps
}: B3FilterSearchProps) {
const [search, setSearch] = useState<string>('')
const b3Lang = useB3Lang()
const debouncedValue = useDebounce<string>(search, 500)
const { placeholder = b3Lang('global.filter.search') } = restProps

const handleOnChange = (e: ChangeEvent<HTMLInputElement>) => {
setSearch(e.target.value)
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/components/form/B3ControlCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function B3ControlCheckbox({
rules: {
required:
required &&
b3Lang('intl.global.validate.required', {
b3Lang('global.validate.required', {
label,
}),
validate: validate && ((v: string) => validate(v, b3Lang)),
Expand Down
8 changes: 4 additions & 4 deletions apps/storefront/src/components/form/B3ControlFileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function B3ControlFileUpload(props: FileUploadProps) {
acceptedFiles = FILE_UPLOAD_ACCEPT_TYPE,
filesLimit = 3,
maxFileSize = 2097152, // 2M
dropzoneText = b3Lang('intl.global.fileUpload.defaultText'),
dropzoneText = b3Lang('global.fileUpload.defaultText'),
previewText = ' ',
fieldType,
default: defaultValue = [],
Expand All @@ -86,13 +86,13 @@ export default function B3ControlFileUpload(props: FileUploadProps) {
})

if (!isAcceptFileType) {
return b3Lang('intl.global.fileUpload.typeNotSupport', {
return b3Lang('global.fileUpload.typeNotSupport', {
name,
})
}

if (size > maxFileSize) {
return b3Lang('intl.global.fileUpload.fileSizeExceedsLimit', {
return b3Lang('global.fileUpload.namedFileSizeExceedsLimit', {
name,
maxSize: getMaxFileSizeLabel(maxFileSize),
})
Expand All @@ -102,7 +102,7 @@ export default function B3ControlFileUpload(props: FileUploadProps) {
}

const getFileLimitExceedMessage = () =>
b3Lang('intl.global.fileUpload.fileNumberExceedsLimit', {
b3Lang('global.fileUpload.fileNumberExceedsLimit', {
limit: filesLimit,
})

Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/components/form/B3ControlPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function B3ControlPicker({
rules: {
required:
required &&
b3Lang('intl.global.validate.required', {
b3Lang('global.validate.required', {
label,
}),
validate: validate && ((v: string) => validate(v, b3Lang)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function B3ControlRadioGroup({
rules: {
required:
required &&
b3Lang('intl.global.validate.required', {
b3Lang('global.validate.required', {
label,
}),
validate: validate && ((v: string) => validate(v, b3Lang)),
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/components/form/B3ControlRectangle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function B3ControlRectangle({
rules: {
required:
required &&
b3Lang('intl.global.validate.required', {
b3Lang('global.validate.required', {
label,
}),
validate: validate && ((v: string) => validate(v, b3Lang)),
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/components/form/B3ControlSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function B3ControlSelect({
rules: {
required:
required &&
b3Lang('intl.global.validate.required', {
b3Lang('global.validate.required', {
label,
}),
validate: validate && ((v: string) => validate(v, b3Lang)),
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/components/form/B3ControlTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ export default function B3ControlTextField({

let requiredText = ''
if (fieldType === 'password') {
requiredText = b3Lang('intl.global.validate.password.required')
requiredText = b3Lang('global.validate.password.required')
} else {
requiredText = b3Lang('intl.global.validate.required', {
requiredText = b3Lang('global.validate.required', {
label: labelName || label,
})
}
Expand Down
6 changes: 5 additions & 1 deletion apps/storefront/src/components/table/B3NoData.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useB3Lang } from '@b3/lang'
import styled from '@emotion/styled'
import { DataUsageRounded } from '@mui/icons-material'

Expand Down Expand Up @@ -31,10 +32,13 @@ export default function B3NoData({
minHeight,
isLoading = false,
}: B3NoDataProps) {
const b3Lang = useB3Lang()
return (
<NoDataContainer backgroundColor={backgroundColor} minHeight={minHeight}>
{!isLoading && <DataUsageRounded fontSize="large" />}
<NoDataText>{isLoading ? '' : text || 'No data'}</NoDataText>
<NoDataText>
{isLoading ? '' : text || b3Lang('global.table.noData')}
</NoDataText>
</NoDataContainer>
)
}
15 changes: 12 additions & 3 deletions apps/storefront/src/components/table/B3Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
useContext,
useState,
} from 'react'
import { useB3Lang } from '@b3/lang'
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight'
import {
Expand Down Expand Up @@ -263,6 +264,8 @@ export function B3Table<T>({

const [isMobile] = useMobile()

const b3Lang = useB3Lang()

const { offset, count, first } = pagination
const clickableRowStyles =
typeof onClickRow === 'function' ? MOUSE_POINTER_STYLE : undefined
Expand Down Expand Up @@ -344,7 +347,9 @@ export function B3Table<T>({
rowsPerPageOptions={
showRowsPerPageOptions ? rowsPerPageOptions : []
}
labelRowsPerPage={labelRowsPerPage || 'per page:'}
labelRowsPerPage={
labelRowsPerPage || b3Lang('global.pagination.perPage')
}
component="div"
sx={{
color: isMobile
Expand Down Expand Up @@ -390,7 +395,9 @@ export function B3Table<T>({
rowsPerPageOptions={
showRowsPerPageOptions ? rowsPerPageOptions : []
}
labelRowsPerPage={labelRowsPerPage || 'Cards per page:'}
labelRowsPerPage={
labelRowsPerPage || b3Lang('global.pagination.cardsPerPage')
}
component="div"
sx={{
color: customColor,
Expand Down Expand Up @@ -517,7 +524,9 @@ export function B3Table<T>({
rowsPerPageOptions={
showRowsPerPageOptions ? rowsPerPageOptions : []
}
labelRowsPerPage={labelRowsPerPage || 'Rows per page:'}
labelRowsPerPage={
labelRowsPerPage || b3Lang('global.pagination.rowsPerPage')
}
component="div"
sx={{
marginTop: '1.5rem',
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/hooks/dom/useRegisteredbctob2b.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const useRegisteredbctob2b = (
convertB2BNavNode.className = 'navUser-item navUser-convert-b2b'
convertB2BNavNode.innerHTML = `
<a class="navUser-action" href="javascript:;" aria-label="Gift Certificates">
${b3Lang('intl.global.nav.registerB2B.linkText')}
${b3Lang('global.registerB2B.linkText')}
</a>
`
return convertB2BNavNode
Expand Down
21 changes: 0 additions & 21 deletions apps/storefront/src/locales/en-US/global.ts

This file was deleted.

8 changes: 0 additions & 8 deletions apps/storefront/src/locales/en-US/index.ts

This file was deleted.

Loading

0 comments on commit c5272b3

Please sign in to comment.