Skip to content

Commit 5a5a83f

Browse files
authored
feat: Added script auto generate translation readme (#113)
* feat: Added script auto generate translation readme * docs(translation): added translation available readme * docs(readme): added see more locale available page link
1 parent 8ba7e94 commit 5a5a83f

8 files changed

+981
-7
lines changed
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Generate Translation Readme
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- "src/translations.ts"
9+
10+
permissions:
11+
actions: read
12+
checks: read
13+
contents: write
14+
deployments: read
15+
issues: read
16+
discussions: read
17+
packages: read
18+
pages: read
19+
pull-requests: read
20+
repository-projects: read
21+
security-events: read
22+
statuses: read
23+
24+
jobs:
25+
generateThemeDoc:
26+
runs-on: ubuntu-latest
27+
name: Generate theme doc
28+
strategy:
29+
matrix:
30+
node-version: [18.x]
31+
32+
steps:
33+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
34+
35+
- name: Setup Node
36+
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
37+
with:
38+
node-version: ${{ matrix.node-version }}
39+
cache: npm
40+
41+
# Fix the unsafe repo error which was introduced by the CVE-2022-24765 git patches.
42+
- name: Fix unsafe repo error
43+
run: git config --global --add safe.directory ${{ github.workspace }}
44+
45+
- name: npm install, generate readme
46+
run: |
47+
npm ci
48+
npm run locale-readme-gen
49+
env:
50+
CI: true
51+
52+
- name: Run Script
53+
uses: skx/github-action-tester@e29768ff4ff67be9d1fdbccd8836ab83233bebb1 # v0.10.0
54+
with:
55+
script: ./scripts/push-locale-readme.sh
56+
env:
57+
CI: true
58+
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
59+
GH_REPO: ${{ secrets.GH_REPO }}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ You can pass a query parameter `&show=` to show any specific additional stats wi
200200
</tr>
201201
</table>
202202

203-
The locale code added to file should be a 2-letter abbreviation from [ISO 639-1](https://www.andiamo.co.uk/resources/iso-language-codes/) or a 4-letter code with a language and country code (eg. `id` or `pt-BR`). Anything appearing in [the list](https://gist.github.com/FajarKim/91516c2aecbfc8bf65f584d528d5f2b1) should be fine.
203+
See [more](/docs/translations.md) available locale. The locale code added to file should be a 2-letter abbreviation from [ISO 639-1](https://www.andiamo.co.uk/resources/iso-language-codes/) or a 4-letter code with a language and country code (eg. `id` or `pt-BR`). Anything appearing in [the list](https://gist.github.com/FajarKim/91516c2aecbfc8bf65f584d528d5f2b1) should be fine. You can also contribute new translations if you like, contributing guidelines can be found [here](/CONTRIBUTING.md#%EF%B8%8F-translations-contribution).
204204

205205
```markdown
206206
![GitHub Stats](https://gh-readme-profile.vercel.app/api?username=FajarKim&locale=id)

docs/translations.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!-- DO NOT EDIT THIS FILE DIRECTLY -->
2+
## Available Locales
3+
Use `?locale=LOCALE_NAME` parameter like so :-
4+
5+
```markdown
6+
![GitHub Stats](https://gh-readme-profile.vercel.app/api?username=FajarKim&locale=id)
7+
```
8+
9+
## Locales List
10+
11+
<table>
12+
<tr>
13+
<td><p align="center"><b>Code</b></p></td>
14+
<td><p align="center"><b>Locale</b></p></td>
15+
<td><p align="center"><b>Progress</b></p></td>
16+
</tr>
17+
<tr>
18+
<td><p align="center"><code>en</code></p></td>
19+
<td><p align="left">English</p></td>
20+
<td><p align="center">100%</p></td>
21+
</tr> <tr>
22+
<td><p align="center"><code>id</code></p></td>
23+
<td><p align="left">Indonesian</p></td>
24+
<td><p align="center">100%</p></td>
25+
</tr> <tr>
26+
<td><p align="center"><code>ko</code></p></td>
27+
<td><p align="left">Korean</p></td>
28+
<td><p align="center">100%</p></td>
29+
</tr> <tr>
30+
<td><p align="center"><code>ar</code></p></td>
31+
<td><p align="left">Arabic</p></td>
32+
<td><p align="center">75%</p></td>
33+
</tr> <tr>
34+
<td><p align="center"><code>ja</code></p></td>
35+
<td><p align="left">Japanese</p></td>
36+
<td><p align="center">100%</p></td>
37+
</tr> <tr>
38+
<td><p align="center"><code>fr</code></p></td>
39+
<td><p align="left">French</p></td>
40+
<td><p align="center">75%</p></td>
41+
</tr>
42+
</table>
43+
44+
Want to add a new translations? Consider reading the [contribution guidelines](https://github.com/FajarKim/github-readme-profile/blob/master/CONTRIBUTING.md#%EF%B8%8F-translations-contribution) :D

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"dev": "nodemon ./withexpress.ts",
1818
"build": "tsc",
1919
"theme-readme-gen": "ts-node scripts/generate-theme-doc.ts",
20+
"locale-readme-gen": "ts-node scripts/generate-translation-doc.ts",
2021
"start": "node ./public/withexpress.js"
2122
},
2223
"author": "Rangga Fajar Oktariansyah",

scripts/generate-theme-doc.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import fs from "fs";
2-
import { themes } from '../themes/index';
2+
import { themes } from "../themes/index";
33

44
const TARGET_FILE = "./themes/README.md";
55

6-
// Function to generate the markdown for themes
76
function generateThemeMarkdown(theme: string): string {
87
return `\`${theme}\` ![${theme}][${theme}]`;
98
}
109

11-
// Function to generate themes preview link
1210
function generateThemeLink(username: string, theme: string): string {
1311
return `[${theme}]: https://github-readme-profile-alpha.vercel.app/api?username=${username}&theme=${theme}`
1412
}
1513

16-
// Function to generate README.md content
1714
function generateReadme(username: string): string {
1815
const availableThemes = Object.keys(themes);
1916
const itemsPerRow = 3;
@@ -56,7 +53,6 @@ ${themesPreviewLink}`;
5653
return readmeContent;
5754
}
5855

59-
// Example usage
60-
const username = 'FajarKim';
56+
const username = "FajarKim";
6157
const generatedReadme = generateReadme(username);
6258
fs.writeFileSync(TARGET_FILE, generatedReadme);

scripts/generate-translation-doc.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import fs from "fs";
2+
import { locales } from '../src/translations';
3+
import { languageNames } from './languageNames';
4+
5+
const TARGET_FILE = "./docs/translations.md";
6+
7+
function generateTranslationsMarkdown(locale: string): string {
8+
return `${locale}`;
9+
}
10+
11+
function generateReadme(): string {
12+
const availableLocales = Object.keys(locales);
13+
14+
let localesListTable = "";
15+
for (let i = 0; i < availableLocales.length; i += 1) {
16+
const localesSlice = availableLocales.slice(i, i + 1);
17+
const row = localesSlice.map(locale => generateTranslationsMarkdown(locale)).join('');
18+
localesListTable += ` <tr>
19+
<td><p align="center"><code>${row}</code></p></td>
20+
<td><p align="left">${languageNames[row]}</p></td>
21+
<td><p align="center">${Object.keys(locales[row]).length / 16 * 100}%</p></td>
22+
</tr>`;
23+
}
24+
25+
const readmeContent = `<!-- DO NOT EDIT THIS FILE DIRECTLY -->
26+
## Available Locales
27+
Use \`?locale=LOCALE_NAME\` parameter like so :-
28+
29+
\`\`\`markdown
30+
![GitHub Stats](https://gh-readme-profile.vercel.app/api?username=FajarKim&locale=id)
31+
\`\`\`
32+
33+
## Locales List
34+
35+
<table>
36+
<tr>
37+
<td><p align="center"><b>Code</b></p></td>
38+
<td><p align="center"><b>Locale</b></p></td>
39+
<td><p align="center"><b>Progress</b></p></td>
40+
</tr>
41+
${localesListTable}
42+
</table>
43+
44+
Want to add a new translations? Consider reading the [contribution guidelines](https://github.com/FajarKim/github-readme-profile/blob/master/CONTRIBUTING.md#%EF%B8%8F-translations-contribution) :D
45+
`;
46+
47+
return readmeContent;
48+
}
49+
50+
const generatedReadme = generateReadme();
51+
fs.writeFileSync(TARGET_FILE, generatedReadme);

0 commit comments

Comments
 (0)