From 14e59690bcb3087c649e07614c8ddacea1bf8625 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 28 Dec 2023 03:30:09 +0300 Subject: [PATCH] translate-fixes --- public/locales/ru/translation.json | 1 + src/components/Article/Comment/Comment.tsx | 2 +- .../Author/AuthorBadge/AuthorBadge.tsx | 17 ++++++++++--- .../Author/AuthorCard/AuthorCard.tsx | 3 ++- .../AhtorLink.module.scss | 0 .../{AhtorLink => AuthorLink}/AuthorLink.tsx | 5 ++-- .../Author/{AhtorLink => AuthorLink}/index.ts | 0 .../Feed/ArticleCard/ArticleCard.tsx | 2 +- src/components/Views/AllAuthors.tsx | 25 ++++++++++++------- src/components/Views/Author/Author.tsx | 2 +- src/components/Views/Feed/Feed.tsx | 2 +- 11 files changed, 40 insertions(+), 19 deletions(-) rename src/components/Author/{AhtorLink => AuthorLink}/AhtorLink.module.scss (100%) rename src/components/Author/{AhtorLink => AuthorLink}/AuthorLink.tsx (84%) rename src/components/Author/{AhtorLink => AuthorLink}/index.ts (100%) diff --git a/public/locales/ru/translation.json b/public/locales/ru/translation.json index aa5e635c..1248ac72 100644 --- a/public/locales/ru/translation.json +++ b/public/locales/ru/translation.json @@ -30,6 +30,7 @@ "All articles": "Все материалы", "All authors": "Все авторы", "All posts": "Все публикации", + "All posts rating": "Рейтинг всех постов", "All topics": "Все темы", "Almost done! Check your email.": "Почти готово! Осталось подтвердить вашу почту.", "Are you sure you want to delete this comment?": "Уверены, что хотите удалить этот комментарий?", diff --git a/src/components/Article/Comment/Comment.tsx b/src/components/Article/Comment/Comment.tsx index bb2c2cad..edd2a4fd 100644 --- a/src/components/Article/Comment/Comment.tsx +++ b/src/components/Article/Comment/Comment.tsx @@ -11,7 +11,7 @@ import { Author, Reaction, ReactionKind } from '../../../graphql/schema/core.gen import { router } from '../../../stores/router' import { Icon } from '../../_shared/Icon' import { ShowIfAuthenticated } from '../../_shared/ShowIfAuthenticated' -import { AuthorLink } from '../../Author/AhtorLink' +import { AuthorLink } from '../../Author/AuthorLink' import { Userpic } from '../../Author/Userpic' import { CommentDate } from '../CommentDate' import { CommentRatingControl } from '../CommentRatingControl' diff --git a/src/components/Author/AuthorBadge/AuthorBadge.tsx b/src/components/Author/AuthorBadge/AuthorBadge.tsx index 5986e07e..8f6a928c 100644 --- a/src/components/Author/AuthorBadge/AuthorBadge.tsx +++ b/src/components/Author/AuthorBadge/AuthorBadge.tsx @@ -11,9 +11,12 @@ import { Button } from '../../_shared/Button' import { CheckButton } from '../../_shared/CheckButton' import { Icon } from '../../_shared/Icon' import { Userpic } from '../Userpic' +import { translit } from '../../../utils/ru2en' import styles from './AuthorBadge.module.scss' import stylesButton from '../../_shared/Button/Button.module.scss' +import { capitalize } from '../../../utils/capitalize' +import { isCyrillic } from '../../../utils/cyrillic' type Props = { author: Author @@ -30,7 +33,7 @@ export const AuthorBadge = (props: Props) => { actions: { loadSubscriptions, requireAuthentication }, } = useSession() const { changeSearchParams } = useRouter() - const { t, formatDate } = useLocalize() + const { t, formatDate, lang } = useLocalize() const subscribed = createMemo(() => subscriptions().authors.some((a: Author) => a.slug === props.author.slug), ) @@ -60,19 +63,27 @@ export const AuthorBadge = (props: Props) => { }, 'discussions') } + const name = createMemo(() => + capitalize( + lang() === 'en' && isCyrillic(props.author.name) + ? translit(props.author.name) + : props.author.name || '', + ), + ) + return (
- {props.author.name} + {name()}
{ const isProfileOwner = createMemo(() => author()?.slug === props.author.slug) const name = createMemo(() => { - if (lang() !== 'ru') { + if (lang() !== 'ru' && isCyrillic(props.author.name)) { if (props.author.name === 'Дискурс') { return 'Discours' } diff --git a/src/components/Author/AhtorLink/AhtorLink.module.scss b/src/components/Author/AuthorLink/AhtorLink.module.scss similarity index 100% rename from src/components/Author/AhtorLink/AhtorLink.module.scss rename to src/components/Author/AuthorLink/AhtorLink.module.scss diff --git a/src/components/Author/AhtorLink/AuthorLink.tsx b/src/components/Author/AuthorLink/AuthorLink.tsx similarity index 84% rename from src/components/Author/AhtorLink/AuthorLink.tsx rename to src/components/Author/AuthorLink/AuthorLink.tsx index 262e36ab..bd3a8880 100644 --- a/src/components/Author/AhtorLink/AuthorLink.tsx +++ b/src/components/Author/AuthorLink/AuthorLink.tsx @@ -8,6 +8,7 @@ import { isCyrillic } from '../../../utils/cyrillic' import { Userpic } from '../Userpic' import styles from './AhtorLink.module.scss' +import { translit } from '../../../utils/ru2en' type Props = { author: Author @@ -20,7 +21,7 @@ export const AuthorLink = (props: Props) => { const { lang } = useLocalize() const name = createMemo(() => { return lang() === 'en' && isCyrillic(props.author.name) - ? capitalize(props.author.slug.replace(/-/, ' ')) + ? translit(capitalize(props.author.name)) : props.author.name }) return ( @@ -30,7 +31,7 @@ export const AuthorLink = (props: Props) => { })} >
- +
{name()}
diff --git a/src/components/Author/AhtorLink/index.ts b/src/components/Author/AuthorLink/index.ts similarity index 100% rename from src/components/Author/AhtorLink/index.ts rename to src/components/Author/AuthorLink/index.ts diff --git a/src/components/Feed/ArticleCard/ArticleCard.tsx b/src/components/Feed/ArticleCard/ArticleCard.tsx index ccc5503a..3d452ffa 100644 --- a/src/components/Feed/ArticleCard/ArticleCard.tsx +++ b/src/components/Feed/ArticleCard/ArticleCard.tsx @@ -15,7 +15,7 @@ import { Popover } from '../../_shared/Popover' import { CoverImage } from '../../Article/CoverImage' import { getShareUrl, SharePopup } from '../../Article/SharePopup' import { ShoutRatingControl } from '../../Article/ShoutRatingControl' -import { AuthorLink } from '../../Author/AhtorLink' +import { AuthorLink } from '../../Author/AuthorLink' import { CardTopic } from '../CardTopic' import { FeedArticlePopup } from '../FeedArticlePopup' diff --git a/src/components/Views/AllAuthors.tsx b/src/components/Views/AllAuthors.tsx index 1390f47a..e59e8360 100644 --- a/src/components/Views/AllAuthors.tsx +++ b/src/components/Views/AllAuthors.tsx @@ -15,6 +15,8 @@ import { SearchField } from '../_shared/SearchField' import { AuthorBadge } from '../Author/AuthorBadge' import styles from './AllAuthors.module.scss' +import { isCyrillic } from '../../utils/cyrillic' +import { capitalize } from '../../utils/capitalize' type AllAuthorsPageSearchParams = { by: '' | 'name' | 'shouts' | 'followers' @@ -26,10 +28,11 @@ type Props = { } const PAGE_SIZE = 20 -const ALPHABET = [...'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ@'] export const AllAuthorsView = (props: Props) => { const { t, lang } = useLocalize() + const ALPHABET = + lang() === 'ru' ? [...'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ@'] : [...'ABCDEFGHIJKLMNOPQRSTUVWXYZ@'] const [offsetByShouts, setOffsetByShouts] = createSignal(0) const [offsetByFollowers, setOffsetByFollowers] = createSignal(0) const { searchParams, changeSearchParams } = useRouter() @@ -73,20 +76,24 @@ export const AllAuthorsView = (props: Props) => { shouts: loadMoreByShouts, followers: loadMoreByFollowers, }[searchParams().by]() - + const translate = (author: Author) => + lang() === 'en' && isCyrillic(author.name) + ? capitalize(author.slug.replace(/-/, ' '), true) + : author.name const byLetter = createMemo<{ [letter: string]: Author[] }>(() => { return sortedAuthors().reduce( (acc, author) => { let letter = '' - if (author && author.name) { - const nameParts = author.name.trim().split(' ') - const lastName = nameParts.pop() - if (lastName && lastName.length > 0) { - letter = lastName[0].toUpperCase() + if (!letter && author && author.name) { + const name = translate(author) + const nameParts = name.trim().split(' ') + const found = nameParts.filter(Boolean).pop() + if (found && found.length > 0) { + letter = found[0].toUpperCase() } } - if (/[^ËА-яё]/.test(letter) && lang() === 'ru') letter = '@' + if (/[^A-z]/.test(letter) && lang() === 'en') letter = '@' if (!acc[letter]) acc[letter] = [] @@ -193,7 +200,7 @@ export const AllAuthorsView = (props: Props) => { {(author) => (
- {author.name} + {translate(author)} {author.stat.shouts} diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index cd81ff8d..637115ce 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -189,7 +189,7 @@ export const AuthorView = (props: Props) => {
- {t('Karma')} + {t('All posts rating')}
diff --git a/src/components/Views/Feed/Feed.tsx b/src/components/Views/Feed/Feed.tsx index 93577c99..ebfa89a3 100644 --- a/src/components/Views/Feed/Feed.tsx +++ b/src/components/Views/Feed/Feed.tsx @@ -18,7 +18,7 @@ import { DropDown } from '../../_shared/DropDown' import { Icon } from '../../_shared/Icon' import { Loading } from '../../_shared/Loading' import { CommentDate } from '../../Article/CommentDate' -import { AuthorLink } from '../../Author/AhtorLink' +import { AuthorLink } from '../../Author/AuthorLink' import { AuthorBadge } from '../../Author/AuthorBadge' import { ArticleCard } from '../../Feed/ArticleCard' import { Sidebar } from '../../Feed/Sidebar'