Skip to content

Commit

Permalink
Upgrade next-18next and try to make it work
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-macpherson committed Sep 19, 2024
1 parent 232fb63 commit bd3399a
Show file tree
Hide file tree
Showing 85 changed files with 230 additions and 390 deletions.
4 changes: 2 additions & 2 deletions docs/1-internationalization.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ When using translations in a React component, default to using the [useTranslati

```jsx
import React from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

export function MyComponent() {
const { t } = useTranslation()
Expand All @@ -32,7 +32,7 @@ For simple interpolation, follow this pattern:

```jsx
import React from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

export function MyComponent() {
const { t } = useTranslation()
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import { UserBadgeFragmentFragment as Badge, BadgeType } from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import theme from '@/theme'

type Props = {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Filters/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import LanguageSelect from './LanguageSelect'
import TopicSelect from './TopicSelect'
import useToggle from '@/hooks/useToggle'
import useUILanguage from '@/hooks/useUILanguage'
import { Router, useTranslation } from '@/config/i18n'
import { Router, useTranslation } from 'next-i18next'
import PremiumFeatureModal from '@/components/Modals/PremiumFeatureModal'

export type PostQueryVarsType = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import MultiSelect from '@/components/MultiSelect'
import { LanguagesQuery } from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

type Props = {
languagesData: LanguagesQuery | undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Filters/SearchInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useState } from 'react'
import _ from 'lodash'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

type Props = {
defaultValue: string
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Filters/TopicSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import MultiSelect from '@/components/MultiSelect'
import { Topic } from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

type Props = {
topics: Topic[] | undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/MyFeed/MyFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRouter } from 'next/router'
import { toast } from 'react-toastify'
import _ from 'lodash'

import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import { gtag } from '@/components/GoogleAnalytics'
import Pagination from '@/components/Pagination'
import LoadingWrapper from '@/components/LoadingWrapper'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/MyPosts/MyPosts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
User as UserType,
usePostsQuery,
} from '@/generated/graphql'
import { useTranslation, Trans } from '@/config/i18n'
import { useTranslation, Trans } from 'next-i18next'
import TranslationLink from '@/components/TranslationLink'
import LoadingSpinner from '@/components/Icons/LoadingSpinner'
import PostCard from '../PostCard'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useState, useEffect, useRef } from 'react'
import Link from 'next/link'
import classNames from 'classnames'

import { Router, useTranslation } from '@/config/i18n'
import { Router, useTranslation } from 'next-i18next'
import { navConstants } from './nav-constants'
import theme from '@/theme'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Post/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Button, { ButtonVariant } from '@/components/Button'
import theme from '@/theme'
import PostBodyStyles from '@/components/PostBodyStyles'
import InlineFeedbackPopover, { PendingThreadData } from '@/components/InlineFeedbackPopover'
import { Router, useTranslation } from '@/config/i18n'
import { Router, useTranslation } from 'next-i18next'
import PostHeader from '@/components/PostHeader'
import ConfirmationModal from '@/components/Modals/ConfirmationModal'
import PremiumFeatureModal from '@/components/Modals/PremiumFeatureModal'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Post/PostAuthorCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useUnfollowUserMutation,
useFollowingUsersQuery,
} from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import { languageNameWithDialect } from '@/utils/languages'
import Button, { ButtonVariant } from '@/components/Button'
import LevelGauge from '@/components/LevelGauge'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Post/PostComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useDeletePostCommentMutation,
PostCommentFragmentFragment as PostCommentType,
} from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

import EditableMarkdown from '@/components/EditableMarkdown'
import Button, { ButtonSize, ButtonVariant } from '@/components/Button'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Post/PostComments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
PostPageQueryVariables,
LanguageLevel,
} from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

import theme from '@/theme'
import PostComment from './PostComment'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Post/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PostClapFragmentFragment as PostClapType } from '@/generated/graphql'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import { isChildOf } from '@/utils'

// Elements whose boundaries a comment can cross
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/PostCard/PostCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import Link from 'next/link'
import classNames from 'classnames'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import { formatShortDate } from '@/utils/date'
import {
PostStatus as PostStatusType,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Profile/PostList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { useTranslation, Trans } from '@/config/i18n'
import { useTranslation, Trans } from 'next-i18next'
import {
PostCardFragmentFragment as PostType,
UserWithLanguagesFragmentFragment as UserType,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react'

import theme from '@/theme'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import {
ProfileUserFragmentFragment as UserType,
PostCardFragmentFragment as PostCardType,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Profile/ProfileCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo, useState } from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import FacebookIcon from '@/components/Icons/FacebookIcon'
import InstagramIcon from '@/components/Icons/InstagramIcon'
import YoutubeIcon from '@/components/Icons/YoutubeIcon'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Profile/ProfileStats.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useMemo, useCallback } from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import chroma from 'chroma-js'

import differenceInCalendarWeeks from 'date-fns/differenceInCalendarWeeks'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Settings/BioForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { useForm } from 'react-hook-form'
import { toast } from 'react-toastify'
import { sanitize } from '@/utils'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import FormError from '@/components/FormError'
import SettingsForm from '@/components/Dashboard/Settings/SettingsForm'
import SettingsFieldset from '@/components/Dashboard/Settings/SettingsFieldset'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Settings/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { useRouter } from 'next/router'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import theme from '@/theme'

const Breadcrumbs: React.FC = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Settings/DetailsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useRef, useCallback } from 'react'
import { useForm } from 'react-hook-form'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import FormError from '@/components/FormError'
import SettingsForm from '@/components/Dashboard/Settings/SettingsForm'
import SettingsFieldset from '@/components/Dashboard/Settings/SettingsFieldset'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import {
TopicFragmentFragment as TopicType,
UserInterestFragmentFragment as UserInterestType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import {
LanguageFragmentFragment as LanguageType,
LanguageRelation as LanguageRelationType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import {
DigestEmailConfiguration as DigestEmailConfigurationType,
useUpdateUserConfigurationMutation,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Settings/SettingsNav.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import NavLink from '@/components/NavLink'
import theme from '@/theme'

Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/Dashboard/Settings/SocialForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import { useForm } from 'react-hook-form'
import { toast } from 'react-toastify'
import { ApolloError } from '@apollo/client'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import SettingsForm from '@/components/Dashboard/Settings/SettingsForm'
import SettingsFieldset from '@/components/Dashboard/Settings/SettingsFieldset'
import Button, { ButtonVariant } from '@/components/Button'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { FieldError, ValidationOptions } from 'react-hook-form'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import FacebookIcon from '@/components/Icons/FacebookIcon'
import GlobeIcon from '@/components/Icons/GlobeIcon'
import InstagramIcon from '@/components/Icons/InstagramIcon'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from 'react'
import theme from '@/theme'
import Button, { ButtonSize, ButtonVariant } from '@/components/Button'

import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import UpdateCardFormModal from './UpdateCardFormModal'

type CardOnFileProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@/generated/graphql'
import Button from '@/components/Button'
import SubscriptionPlanSelect from './SubscriptionPlanSelect'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import theme from '@/theme'

type PaymentFormProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import Modal from '@/components/Modal'
import PaymentForm from './PaymentForm'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

type PaymentFormModalProps = {
onClose: () => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { toast } from 'react-toastify'

import Button, { ButtonVariant } from '@/components/Button'
import { useConfirmationModal } from '@/components/Modals/ConfirmationModal'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import {
MembershipSubscriptionPeriod,
UserWithSubscriptionFragmentFragment as UserType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from 'react'
import { MembershipSubscriptionPeriod } from '@/generated/graphql'
import Select from '@/components/Select'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

type SubscriptionPlanSelectProps = {
selectedOption: MembershipSubscriptionPeriod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
useUpdateSubscriptionPaymentMethodMutation,
} from '@/generated/graphql'
import Button from '@/components/Button'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import theme from '@/theme'

type UpdateCardFormProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import Modal from '@/components/Modal'
import UpdateCardForm from './UpdateCardForm'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

type UpdateCardFormModalProps = {
onClose: () => void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'

import SettingsForm from '@/components/Dashboard/Settings/SettingsForm'
import SettingsFieldset from '@/components/Dashboard/Settings/SettingsFieldset'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { useForm } from 'react-hook-form'
import { toast } from 'react-toastify'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import FormError from '@/components/FormError'
import SettingsForm from '@/components/Dashboard/Settings/SettingsForm'
import SettingsFieldset from '@/components/Dashboard/Settings/SettingsFieldset'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import theme from '@/theme'
import React from 'react'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import CheckmarkCircleIcon from '../Icons/CheckmarkCircleIcon'

type FeatureProps = {
Expand Down
6 changes: 4 additions & 2 deletions packages/web/components/InlineFeedbackPopover/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useApplySuggestionMutation,
} from '@/generated/graphql'
import theme from '@/theme'
import { Router, useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import EditableMarkdown from '@/components/EditableMarkdown'
import Button, { ButtonSize, ButtonVariant } from '@/components/Button'
import { useConfirmationModal } from '@/components/Modals/ConfirmationModal'
Expand All @@ -28,6 +28,7 @@ import LevelGauge from '../LevelGauge'
import UserAvatar from '../UserAvatar'
import PremiumFeatureModal from '../Modals/PremiumFeatureModal'
import { JOURNALY_PREMIUM_URL } from '@/constants'
import { useRouter } from 'next/router'

type CommentProps = {
comment: CommentType
Expand All @@ -52,6 +53,7 @@ const Comment = ({
currentContentInPost,
postAuthorId,
}: CommentProps) => {
const router = useRouter()
const { t } = useTranslation('comment')
const [isEditMode, setIsEditMode] = useState(false)
const [updatingCommentBody, setUpdatingCommentBody] = useState(comment.body)
Expand Down Expand Up @@ -310,7 +312,7 @@ const Comment = ({
featureExplanation={t('acceptSuggestionPremiumFeatureExplanation')}
onAcknowledge={() => setDisplayPremiumFeatureModal(false)}
onGoToPremium={() => {
Router.push(JOURNALY_PREMIUM_URL)
router.push(JOURNALY_PREMIUM_URL)
setDisplayPremiumFeatureModal(false)
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/InlineFeedbackPopover/Thread.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useRef } from 'react'

import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import {
useCreateCommentMutation,
useCreateThreadMutation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@/generated/graphql'
import Button, { ButtonVariant } from '@/components/Button'
import { OptionPills } from '@/components/MultiSelect'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import Select from '../Select'

type Props = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback } from 'react'
import { useSlate } from 'slate-react'

import { useTranslation, Router } from '@/config/i18n'
import { useTranslation, Router } from 'next-i18next'
import BaseToolbarButton from './BaseToolbarButton'
import { insertImage } from '../helpers'
import PremiumFeatureModal from '@/components/Modals/PremiumFeatureModal'
Expand Down
2 changes: 1 addition & 1 deletion packages/web/components/JournalyEditor/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import ToolbarButton from './ToolbarButton'
import InsertImageButton from './InsertImageButton'
import { isTableActive } from '../helpers'
import SwitchToggle from '@/components/SwitchToggle'
import { useTranslation } from '@/config/i18n'
import { useTranslation } from 'next-i18next'
import useIntersectionObserver from '@/hooks/userIntersectionObserver'

type ToolbarProps = {
Expand Down
Loading

0 comments on commit bd3399a

Please sign in to comment.