Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 56b9f0b

Browse files
committed
Refactor build.py to centralize language mappings and enhance README generation with dynamic language switcher links. Update translations in README files for improved consistency and user experience across multiple languages.
1 parent 0a91262 commit 56b9f0b

File tree

10 files changed

+240
-135
lines changed

10 files changed

+240
-135
lines changed

‎README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
# Basic File and Directory Operations
1+
# Linux Commands Cheat Sheet
2+
3+
*A clean and minimal guide to 491 Linux commands*
4+
5+
[🇩🇪 Deutsch](./de/README.md) | **🇺🇸 English** | [🇪🇸 Español](./es/README.md) | [🇫🇷 Français](./fr/README.md) | [🇯🇵 日本語](./ja/README.md) | [🇰🇷 한국어](./ko/README.md) | [🇵🇹 Português](./pt/README.md) | [🇷🇺 Русский](./ru/README.md) | [🇨🇳 简体中文](./zh/README.md)
6+
7+
---
8+
## Basic File and Directory Operations
29

310
| Command | Description |
411
| --- | --- |
@@ -55,7 +62,7 @@
5562
| [whereis](https://labex.io/tutorials/linux-linux-whereis-command-with-practical-examples-423006) | Explore the Linux whereis command and learn how to locate executable files, source code, and manual pages on your system. Customize the search behavior to suit your needs. |
5663
| [which](https://labex.io/tutorials/linux-linux-which-command-with-practical-examples-423007) | Explore the Linux which command, learn how to locate the path of executable files, and discover advanced usage scenarios with practical examples. |
5764

58-
# Text Processing and Editing
65+
## Text Processing and Editing
5966

6067
| Command | Description |
6168
| --- | --- |
@@ -104,7 +111,7 @@
104111
| [vi](https://labex.io/tutorials/linux-linux-vi-command-with-practical-examples-422996) | Explore the powerful vi text editor in Linux, learn its basic navigation and editing commands, and dive into advanced features for efficient text processing. |
105112
| [wc](https://labex.io/tutorials/linux-linux-wc-command-with-practical-examples-423003) | Explore the Linux wc command and learn how to count words, lines, and characters in files. Discover practical examples of using wc with other Linux commands for efficient text processing. |
106113

107-
# System Monitoring and Management
114+
## System Monitoring and Management
108115

109116
| Command | Description |
110117
| --- | --- |
@@ -158,7 +165,7 @@
158165
| [w](https://labex.io/tutorials/linux-linux-w-command-with-practical-examples-423000) | Explore the w command in Linux, learn how to analyze user login sessions, and monitor system load and resource utilization for effective system management. |
159166
| [watch](https://labex.io/tutorials/linux-linux-watch-command-with-practical-examples-423002) | Explore the powerful Linux watch command and its practical applications, including monitoring system processes and tracking file changes. |
160167

161-
# User and Permission Management
168+
## User and Permission Management
162169

163170
| Command | Description |
164171
| --- | --- |
@@ -193,7 +200,7 @@
193200
| [who](https://labex.io/tutorials/linux-linux-who-command-with-practical-examples-423008) | Explore the Linux who command, learn how to use it, and discover practical examples to understand user sessions and system activity. |
194201
| [whoami](https://labex.io/tutorials/linux-linux-whoami-command-with-practical-examples-423009) | Explore the Linux whoami command and its practical applications. Learn how to use it to determine your current user identity, integrate it into shell scripts, and manage user permissions effectively. |
195202

196-
# Networking and Communication
203+
## Networking and Communication
197204

198205
| Command | Description |
199206
| --- | --- |
@@ -266,7 +273,7 @@
266273
| [write](https://labex.io/tutorials/linux-linux-write-command-with-practical-examples-423011) | Explore the Linux write command and its practical applications, including sending messages to specific users and broadcasting messages to all logged-in users on the same system. |
267274
| [ytalk](https://labex.io/tutorials/linux-linux-ytalk-command-with-practical-examples-423015) | Explore the Linux ytalk command, a tool for real-time text-based communication between users on the same system. Learn how to install, initiate, and utilize advanced features of ytalk for efficient collaboration and remote assistance. |
268275

269-
# Disk and File System Utilities
276+
## Disk and File System Utilities
270277

271278
| Command | Description |
272279
| --- | --- |
@@ -314,7 +321,7 @@
314321
| [tune2fs](https://labex.io/tutorials/linux-linux-tune2fs-command-with-practical-examples-422968) | Explore the tune2fs command, a powerful tool for managing ext2/ext3/ext4 file systems. Learn how to modify filesystem behavior, backup and restore metadata, and optimize disk performance. |
315322
| [umount](https://labex.io/tutorials/linux-linux-umount-command-with-practical-examples-422971) | Explore the Linux umount command, learn how to unmount mounted file systems, and discover practical examples to manage your file system effectively. |
316323

317-
# Compression and Archiving
324+
## Compression and Archiving
318325

319326
| Command | Description |
320327
| --- | --- |
@@ -342,7 +349,7 @@
342349
| [zipinfo](https://labex.io/tutorials/linux-linux-zipinfo-command-with-practical-examples-423022) | Explore the powerful zipinfo command in Linux, learn its options, and analyze the contents of zip files with practical examples. |
343350
| [zless](https://labex.io/tutorials/linux-linux-zless-command-with-practical-examples-423023) | Explore the zless command in Linux, a powerful tool for viewing compressed files. Learn its syntax, options, and practical examples to enhance your compression and archiving skills. |
344351

345-
# Process Management
352+
## Process Management
346353

347354
| Command | Description |
348355
| --- | --- |
@@ -371,7 +378,7 @@
371378
| [strace](https://labex.io/tutorials/linux-linux-strace-command-with-practical-examples-422933) | Explore the powerful strace command in Linux, learn how to trace system calls, and debug processes effectively with practical examples. |
372379
| [tmux](https://labex.io/tutorials/linux-linux-tmux-command-with-practical-examples-422960) | Explore the powerful tmux command-line tool for managing and controlling multiple terminal sessions on a Linux system. Learn how to navigate, manage, and customize tmux for enhanced productivity. |
373380

374-
# System Configuration and Settings
381+
## System Configuration and Settings
375382

376383
| Command | Description |
377384
| --- | --- |
@@ -425,7 +432,7 @@
425432
| [update-rc.d](https://labex.io/tutorials/linux-linux-update-rc-d-command-with-practical-examples-422982) | Learn how to use the update-rc.d command to configure services to start automatically at boot, manage service startup priorities, and gain practical experience with real-world examples. |
426433
| [zdump](https://labex.io/tutorials/linux-linux-zdump-command-with-practical-examples-423019) | Explore the Linux zdump command, which displays time zone information. Learn its syntax, understand timezone data, and see practical examples of its usage. |
427434

428-
# Package Management
435+
## Package Management
429436

430437
| Command | Description |
431438
| --- | --- |
@@ -442,7 +449,7 @@
442449
| [yum](https://labex.io/tutorials/linux-linux-yum-command-with-practical-examples-423016) | Explore the powerful yum package manager in Linux. Learn how to install, update, and remove packages using practical examples. Enhance your system management skills with this comprehensive lab. |
443450
| [zypper](https://labex.io/tutorials/linux-linux-zypper-command-with-practical-examples-423024) | Explore the zypper command, a powerful package management tool for SUSE-based Linux distributions. Learn how to install, update, search, and remove packages using zypper with practical examples. |
444451

445-
# Scripting and Programming
452+
## Scripting and Programming
446453

447454
| Command | Description |
448455
| --- | --- |
@@ -474,7 +481,7 @@
474481
| [strings](https://labex.io/tutorials/linux-linux-strings-command-with-practical-examples-422934) | Explore the Linux strings command and learn how to extract strings from binary, compressed, and encrypted files. Gain practical experience with real-world examples. |
475482
| [svn](https://labex.io/tutorials/linux-linux-svn-command-with-practical-examples-422940) | Explore the power of the SVN command-line tool on Ubuntu 22.04. Learn how to install Subversion, initialize a local repository, and manage changes through commit, update, and revert operations. |
476483

477-
# Backup and Compression
484+
## Backup and Compression
478485

479486
| Command | Description |
480487
| --- | --- |
@@ -488,7 +495,7 @@
488495
| [uudecode](https://labex.io/tutorials/linux-linux-uudecode-command-with-practical-examples-422990) | Learn how to use the uudecode command in Linux to decode uuencoded files. Explore practical examples and understand the purpose of this useful tool for backup and compression tasks. |
489496
| [uuencode](https://labex.io/tutorials/linux-linux-uuencode-command-with-practical-examples-422991) | Explore the uuencode command in Linux, learn how to encode and decode files, and discover practical use cases for this versatile tool in backup and compression workflows. |
490497

491-
# Miscellaneous Utilities
498+
## Miscellaneous Utilities
492499

493500
| Command | Description |
494501
| --- | --- |

‎build.py

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
from datetime import datetime
55

66

7+
LANG_MAP = {
8+
"en": "🇺🇸 English",
9+
"zh": "🇨🇳 简体中文",
10+
"ja": "🇯🇵 日本語",
11+
"ko": "🇰🇷 한국어",
12+
"ru": "🇷🇺 Русский",
13+
"es": "🇪🇸 Español",
14+
"fr": "🇫🇷 Français",
15+
"pt": "🇵🇹 Português",
16+
"de": "🇩🇪 Deutsch",
17+
}
18+
19+
720
TRANSLATIONS = {
821
"en": {
922
"title": "Linux Commands Cheat Sheet PDF - {year} | LabEx",
@@ -210,7 +223,8 @@ def render_html(commands, lang="en", all_langs=None, year=None):
210223
# 计算命令总数
211224
total_commands = len(commands)
212225
# 多语言文本
213-
t = TRANSLATIONS.get(lang, TRANSLATIONS["en"])
226+
t_original = TRANSLATIONS.get(lang, TRANSLATIONS["en"])
227+
t = t_original.copy()
214228
# Format the translated strings
215229
for key, value in t.items():
216230
if isinstance(value, str):
@@ -466,23 +480,12 @@ def render_html(commands, lang="en", all_langs=None, year=None):
466480
)
467481

468482
# Generate language footer links
469-
lang_map = {
470-
"en": "🇺🇸 English",
471-
"zh": "🇨🇳 简体中文",
472-
"ja": "🇯🇵 日本語",
473-
"ko": "🇰🇷 한국어",
474-
"ru": "🇷🇺 Русский",
475-
"es": "🇪🇸 Español",
476-
"fr": "🇫🇷 Français",
477-
"pt": "🇵🇹 Português",
478-
"de": "🇩🇪 Deutsch",
479-
}
480483
language_footer_links = ""
481484
if all_langs and len(all_langs) > 1:
482485
links = []
483486
for l in all_langs:
484487
path = "/" if l == "en" else f"/{l}/"
485-
lang_name = lang_map.get(l, l.upper())
488+
lang_name = LANG_MAP.get(l, l.upper())
486489
if l == lang:
487490
links.append(
488491
f'<span class="text-white font-bold mx-2">{lang_name}</span>'
@@ -516,18 +519,57 @@ def render_html(commands, lang="en", all_langs=None, year=None):
516519
)
517520

518521

519-
def generate_readme(commands, lang="en"):
522+
def generate_readme(commands, lang="en", all_langs=None):
520523
"""Generates README.md content."""
521-
t = TRANSLATIONS.get(lang, TRANSLATIONS["en"])
524+
total_commands = len(commands)
525+
t_original = TRANSLATIONS.get(lang, TRANSLATIONS["en"])
526+
t = t_original.copy()
527+
# Format the translated strings
528+
for key, value in t.items():
529+
if isinstance(value, str):
530+
t[key] = value.format(
531+
year=datetime.now().year, total_commands=total_commands
532+
)
533+
534+
readme_parts = []
535+
536+
# 1. Header
537+
readme_parts.append(f"# {t.get('h1', 'Linux Commands Cheat Sheet')}")
538+
readme_parts.append(f"\n*{t.get('h1_sub', '')}*\n")
539+
540+
# 2. Language Switcher
541+
if all_langs and len(all_langs) > 1:
542+
links = []
543+
for l in sorted(all_langs): # sort for consistent order
544+
lang_name = LANG_MAP.get(l, l.upper())
545+
if l == lang:
546+
links.append(f"**{lang_name}**")
547+
else:
548+
if lang == "en":
549+
# Current file is /README.md
550+
# Link to /zh/README.md
551+
path = f"./{l}/README.md"
552+
else:
553+
# Current file is /zh/README.md
554+
if l == "en":
555+
# Link to /README.md
556+
path = "../README.md"
557+
else:
558+
# Link to /de/README.md
559+
path = f"../{l}/README.md"
560+
links.append(f"[{lang_name}]({path})")
561+
readme_parts.append(" | ".join(links))
562+
readme_parts.append("\n---")
563+
564+
# 3. Command Tables
522565
# Organize commands by category
523566
categories = {}
524567
for command in commands:
525568
categories.setdefault(command["category"], []).append(command)
526569

527-
readme_parts = []
528570
# Preserve category order from API, sort commands alphabetically within each category
529571
for category, cmds in categories.items():
530-
readme_parts.append(f"# {category}\n")
572+
readme_parts.append(f"## {category}\n")
531573
readme_parts.append(
532574
f"| {t.get('readme_command', 'Command')} | {t.get('readme_description', 'Description')} |"
533575
)
@@ -645,7 +687,7 @@ def generate_robots_txt():
645687
print(f"HTML file generated: {output_file}")
646688

647689
# 生成 README.md
648-
readme_content = generate_readme(commands, lang)
690+
readme_content = generate_readme(commands, lang, all_langs=languages)
649691
with open(readme_file, "w", encoding="utf-8") as file:
650692
file.write(readme_content)
651693
print(f"README file generated: {readme_file}")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /