Skip to content

Commit 5d63157

Browse files
committed
i18n: Add Chinese (zh_CN) translations for sqlmap
- Add gettext-based i18n infrastructure (lib/core/i18n.py) - Add Chinese .po/.mo translation files (1589 strings, fully translated) - Add Chinese README (zh_README.md) Translator: Liang Xiangan
1 parent e659543 commit 5d63157

4 files changed

Lines changed: 5311 additions & 0 deletions

File tree

lib/core/i18n.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org)
5+
See the file 'LICENSE' for copying permission
6+
7+
Internationalization (i18n) support using GNU gettext.
8+
"""
9+
10+
import gettext
11+
import os
12+
import sys
13+
14+
_LOCALE_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), "locales")
15+
16+
_DOMAIN = "sqlmap"
17+
18+
_translation = None
19+
20+
def init(language=None):
21+
"""
22+
Initialize gettext translation.
23+
24+
If no language is specified, try to detect from system locale.
25+
"""
26+
global _translation
27+
28+
if language is None:
29+
import locale
30+
try:
31+
language, _ = locale.getdefaultlocale()
32+
except Exception:
33+
language = os.environ.get("LANG", "en_US.UTF-8")
34+
35+
if language:
36+
language = language.split(".")[0] # e.g., "zh_CN.UTF-8" -> "zh_CN"
37+
38+
try:
39+
if language and language != "en_US":
40+
_translation = gettext.translation(
41+
_DOMAIN,
42+
localedir=_LOCALE_DIR,
43+
languages=[language],
44+
fallback=True
45+
)
46+
else:
47+
_translation = gettext.NullTranslations()
48+
except Exception:
49+
_translation = gettext.NullTranslations()
50+
51+
# Install the _() function into builtins so it's available everywhere
52+
if isinstance(_translation, gettext.NullTranslations):
53+
import builtins
54+
builtins.__dict__["_"] = lambda msg: msg
55+
else:
56+
_translation.install()
57+
58+
59+
def _(message):
60+
"""
61+
Translate a message.
62+
"""
63+
global _translation
64+
if _translation is None:
65+
init()
66+
return _translation.gettext(message) if _translation else message
197 KB
Binary file not shown.

0 commit comments

Comments
 (0)