Skip to content

Commit 8447ab5

Browse files
authored
fix: design article page (#488)
1 parent c91c46b commit 8447ab5

File tree

8 files changed

+122
-26
lines changed

8 files changed

+122
-26
lines changed

.github/workflows/update-packages-readme.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ jobs:
3636
MODIFIED_README_FILES=$(git diff --name-only | grep -E 'src/content/local-docs/libs/.*/README\.md$' || echo "")
3737
echo "modified_readme_files=$(echo "$MODIFIED_README_FILES" | tr '\n' ',' | sed 's/,$//')" >> $GITHUB_OUTPUT
3838
39+
if [ -z "$MODIFIED_README_FILES" ]; then
40+
echo "No README files changed — skipping commit and PR creation."
41+
exit 0
42+
fi
43+
3944
git config user.email ""
4045
git config user.name "Update packages readme action"
4146
git checkout -b update-packages-readme
@@ -52,6 +57,7 @@ jobs:
5257
prepare-inputs:
5358
needs: update-packages-readme
5459
runs-on: ubuntu-latest
60+
if: ${{ needs.update-packages-readme.outputs.pr_number != '' && needs.update-packages-readme.outputs.pr_number != null }}
5561
outputs:
5662
modified_library_readmes: ${{ steps.get-modified-files.outputs.modified_library_readmes }}
5763
steps:
@@ -80,6 +86,7 @@ jobs:
8086
- update-packages-readme
8187
- prepare-inputs
8288
runs-on: ubuntu-latest
89+
if: ${{ needs.update-packages-readme.outputs.pr_number != '' && needs.update-packages-readme.outputs.pr_number != null }}
8390
strategy:
8491
max-parallel: 1
8592
matrix:
@@ -123,7 +130,6 @@ jobs:
123130
prompt: |
124131
Please translate the README source file to {targetLanguage}. \
125132
Make the translation sound as natural as possible. \
126-
Keep the HTML snippet with the language options in the same place as in the source file. \
127133
Do not translate the first line in the source file if it looks like the name of the library. \
128134
For example, don't translate @gravity/uikit or Axios Wrapper - they need to be left in place. \
129135
Don't add html snippet with language options to the output. \
@@ -134,6 +140,7 @@ jobs:
134140
- update-packages-readme
135141
- translations
136142
runs-on: ubuntu-latest
143+
if: ${{ needs.update-packages-readme.outputs.pr_number != '' && needs.update-packages-readme.outputs.pr_number != null }}
137144
steps:
138145
- uses: actions/checkout@v4
139146
with:

.github/workflows/update-translations.yml

Lines changed: 92 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Update translations
22

33
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'public/locales/en/**'
48
workflow_dispatch:
59

610
permissions: write-all
@@ -16,23 +20,76 @@ jobs:
1620
steps:
1721
- uses: actions/checkout@v4
1822
with:
19-
fetch-depth: 0
23+
fetch-depth: 2
2024
- name: Extract namespaces
2125
id: extract-namespaces
26+
env:
27+
EVENT_NAME: ${{ github.event_name }}
2228
run: |
23-
FILES=$(ls public/locales/en/ | sed 's/\.json$//')
24-
NAMESPACES_ARRAY=$(echo "$FILES" | jq -R -s -c 'split("\n") | map(select(length > 0))')
29+
if [[ "$EVENT_NAME" == "push" ]]; then
30+
MODIFIED_FILES=$(git diff --name-only HEAD^ HEAD | grep -E 'public/locales/en/.+\.json$' || echo "")
31+
NAMESPACES_ARRAY=$(echo "$MODIFIED_FILES" | awk 'NF' | jq -R -c -s '
32+
split("\n") |
33+
map(select(length > 0)) |
34+
map(capture("public/locales/en/(?<namespace>[^/]+)\\.json").namespace)
35+
')
36+
else
37+
FILES=$(ls public/locales/en/ | sed 's/\.json$//')
38+
NAMESPACES_ARRAY=$(echo "$FILES" | jq -R -s -c 'split("\n") | map(select(length > 0))')
39+
fi
40+
2541
echo "namespaces=$NAMESPACES_ARRAY" >> $GITHUB_OUTPUT
2642
27-
translations:
43+
create-pr:
44+
permissions:
45+
pull-requests: write
46+
contents: write
47+
runs-on: ubuntu-latest
2848
needs: prepare-inputs
49+
if: ${{ fromJson(needs.prepare-inputs.outputs.namespaces)[0] != null }}
50+
outputs:
51+
pr_number: ${{ steps.create-pr.outputs.pr_number }}
52+
steps:
53+
- uses: actions/checkout@v4
54+
with:
55+
fetch-depth: 0
56+
- uses: actions/setup-node@v3
57+
with:
58+
node-version: 20
59+
- name: Create pull request
60+
id: create-pr
61+
env:
62+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63+
run: |
64+
echo "temporary file" > temporary-file.txt
65+
66+
git config user.email ""
67+
git config user.name "Update translations action"
68+
git checkout -b update-translations
69+
git add temporary-file.txt
70+
71+
export COMMIT_MESSAGE="initial commit"
72+
git commit -m "$COMMIT_MESSAGE"
73+
git push --set-upstream origin update-translations --force
74+
gh pr create --title "i18n: update translations" --body "" -a "dgaponov" -a "imsitnikov" -a "vvtimofeev" 2>/dev/null || true
75+
PR_NUMBER=$(gh pr view --json number -q ".number")
76+
77+
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
78+
79+
translations:
80+
needs:
81+
- prepare-inputs
82+
- create-pr
2983
runs-on: ubuntu-latest
84+
if: ${{ fromJson(needs.prepare-inputs.outputs.namespaces)[0] != null }}
3085
strategy:
86+
max-parallel: 1
3187
matrix:
3288
namespace: ${{ fromJson(needs.prepare-inputs.outputs.namespaces) }}
3389
steps:
3490
- uses: actions/checkout@v4
3591
with:
92+
ref: refs/pull/${{ needs.create-pr.outputs.pr_number }}/head
3693
fetch-depth: 0
3794
- name: Prepare inputs for ${{ matrix.namespace }}
3895
id: prepare-inputs
@@ -64,7 +121,7 @@ jobs:
64121
outputFiles: ${{ steps.prepare-inputs.outputs.output_files }}
65122
languages: ${{ env.LANGUAGES }}
66123
commitMessage: 'i18n: translations for namespace ${{ matrix.namespace }}'
67-
pullRequestTitle: 'i18n: translations for namespace ${{ matrix.namespace }}'
124+
pullRequestNumber: ${{ needs.create-pr.outputs.pr_number }}
68125
prompt: |
69126
Please translate the json source file to {targetLanguage}. \
70127
Make the translation sound as natural as possible. \
@@ -75,6 +132,35 @@ jobs:
75132
"actions_openInFigma": "Open in Figma",
76133
"title": "Components",
77134
} \
78-
Return only the json, no other text. Remove formatting like markdown ```json```. \
135+
Return only the json, no other text. \
136+
Remove formatting like markdown ```json```. \
137+
Do NOT add ``` tags to the result json. \
79138
Do not translate the library name in the source file if it looks like the name of the library (the exception is Themer, it can be translated). \
80139
For example, don't translate @gravity/uikit or Axios Wrapper - they need to be left in place.
140+
141+
merge-pr:
142+
needs:
143+
- create-pr
144+
- translations
145+
runs-on: ubuntu-latest
146+
if: ${{ needs.create-pr.outputs.pr_number != '' && needs.create-pr.outputs.pr_number != null }}
147+
steps:
148+
- uses: actions/checkout@v4
149+
with:
150+
ref: refs/pull/${{ needs.create-pr.outputs.pr_number }}/head
151+
fetch-depth: 2
152+
- name: Merge PR
153+
env:
154+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155+
run: |
156+
git checkout update-translations
157+
git config user.email ""
158+
git config user.name "Update translations action"
159+
git checkout -b update-translations
160+
rm -rf temporary-file.txt
161+
git add .
162+
163+
export COMMIT_MESSAGE="remove temporary file"
164+
git commit -m "$COMMIT_MESSAGE"
165+
git push --set-upstream origin update-translations --force
166+
gh pr merge ${{ needs.create-pr.outputs.pr_number }} --auto --squash

next-i18next.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module.exports = {
55
defaultNS: 'common',
66
ignoreJSONStructure: false,
77
},
8-
aiTranslatedLocales: [],
98
routesWithoutRedirect: [
109
'/sandbox',
1110
'/rtl',

src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export type LibData = {
3434
ru: string;
3535
es: string;
3636
zh: string;
37+
fr: string;
38+
de: string;
39+
ko: string;
3740
};
3841
changelog: string;
3942
contributors: Contributor[];

src/components/DesignArticle/DesignArticle.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {useTranslation} from 'next-i18next';
22
import React from 'react';
33

4-
import {Article} from '../../content/design/types';
4+
import {Article, ArticleSupportedLocale} from '../../content/design/types';
55
import {useLocale} from '../../hooks/useLocale';
66
import {block} from '../../utils';
77
import {ArticleNavigation} from '../ArticleNavigation/ArticleNavigation';
@@ -74,14 +74,19 @@ export const DesignArticle: React.FC<DesignArticleProps> = ({article, sectionId,
7474
return prevSubSection.isComingSoon ? null : prevSubSection;
7575
}, [currentIndex, currentSection]);
7676

77+
const articleContent =
78+
locale in article.content
79+
? article.content[locale as ArticleSupportedLocale]
80+
: article.content.en;
81+
7782
return (
7883
<div className={b()}>
7984
<h1 className={b('title')}>
8085
{t(`design-articles-info:section_${sectionId}_article_${article.id}_title`)}
8186
</h1>
8287
<MDXRenderer
8388
key={`${sectionId}-${article.id}-${locale}-article`}
84-
text={article.content[locale]}
89+
text={articleContent}
8590
/>
8691
<div className={b('navigation')}>
8792
<ArticleNavigation prevSection={prevSection} nextSection={nextSection} />

src/components/Menu/LocalePicker/LocalePicker.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import React from 'react';
44

55
import i18nextConfig from '../../../../next-i18next.config';
66
import {NEXT_LOCALE_COOKIE} from '../../../constants';
7-
import {useLocale} from '../../../hooks/useLocale';
7+
import {Locale, useLocale} from '../../../hooks/useLocale';
88
import {block, setCookie} from '../../../utils';
99

1010
import './LocalePicker.scss';
1111

1212
const b = block('menu-local-picker');
1313

14-
const FLAGS: Record<string, string> = {
14+
const FLAGS: Record<Locale, string> = {
1515
en: 'us',
1616
ru: 'ru',
1717
es: 'es',
@@ -31,14 +31,10 @@ export const LocalePicker: React.FC = () => {
3131
const localeUpperCase = option.value.toUpperCase();
3232
return (
3333
<div className={b('locale-item')}>
34-
{FLAGS[locale] ? <span className={`fi fi-${FLAGS[locale]}`}></span> : null}
35-
<span className={b('locale-code')}>{localeUpperCase}</span>
36-
{i18nextConfig.aiTranslatedLocales.includes(locale) ? (
37-
<React.Fragment>
38-
<span className={b('locale-ai-icon')}></span>
39-
<span className={b('locale-ai-label')}>AI</span>
40-
</React.Fragment>
34+
{FLAGS[locale as Locale] ? (
35+
<span className={`fi fi-${FLAGS[locale as Locale]}`}></span>
4136
) : null}
37+
<span className={b('locale-code')}>{localeUpperCase}</span>
4238
</div>
4339
);
4440
}, []);

src/content/design/types.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
export const ARTICLE_SUPPORTED_LOCALES = ['en', 'ru', 'es', 'zh'] as const;
2+
export type ArticleSupportedLocale = (typeof ARTICLE_SUPPORTED_LOCALES)[number];
3+
14
export type Article = {
25
id: string;
3-
content: {
4-
en: string;
5-
ru: string;
6-
es: string;
7-
zh: string;
8-
};
6+
content: Record<ArticleSupportedLocale, string>;
97
};
108

119
export type Section = {

src/hooks/useLocale.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import {useRouter} from 'next/router';
22

33
import nextI18nextConfig from '../../next-i18next.config';
44

5+
export type Locale = 'en' | 'ru' | 'es' | 'zh' | 'ko' | 'fr' | 'de';
6+
57
export const useLocale = () => {
68
const {locale} = useRouter();
79

8-
return (locale ?? nextI18nextConfig.i18n.defaultLocale) as 'en' | 'ru' | 'es' | 'zh';
10+
return (locale ?? nextI18nextConfig.i18n.defaultLocale) as Locale;
911
};

0 commit comments

Comments
 (0)