generated from foreign-thon/language-template
Compare commits
9 Commits
dd7f76a033
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fe67854cd | |||
| ccee29236e | |||
| 922a2c7b30 | |||
| b5ecb796da | |||
| ab58b4a830 | |||
| 0b86507244 | |||
| 935418ef58 | |||
| 9a1510c467 | |||
| a91846e44a |
118
README.md
118
README.md
@@ -0,0 +1,118 @@
|
||||
# foreignthon-zh
|
||||
|
||||
Chinese language pack for [ForeignThon](https://foreignthon.keshavanand.net/) — write Python in 中文.
|
||||
|
||||
---
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
pip install foreignthon foreignthon-zh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Example
|
||||
|
||||
**`fizzbuzz.zh.py`**
|
||||
|
||||
```python
|
||||
定义 fizzbuzz(n):
|
||||
对于 i 在 范围(1, n + 1):
|
||||
如果 i % 15 == 0:
|
||||
打印("FizzBuzz")
|
||||
不然 i % 3 == 0:
|
||||
打印("Fizz")
|
||||
不然 i % 5 == 0:
|
||||
打印("Buzz")
|
||||
否则:
|
||||
打印(i)
|
||||
|
||||
fizzbuzz(20)
|
||||
```
|
||||
|
||||
Compiles to standard Python:
|
||||
|
||||
```python
|
||||
def fizzbuzz(n):
|
||||
for i in range(1, n + 1):
|
||||
if i % 15 == 0:
|
||||
print("FizzBuzz")
|
||||
elif i % 3 == 0:
|
||||
print("Fizz")
|
||||
elif i % 5 == 0:
|
||||
print("Buzz")
|
||||
else:
|
||||
print(i)
|
||||
|
||||
fizzbuzz(20)
|
||||
```
|
||||
|
||||
Run it directly:
|
||||
|
||||
```bash
|
||||
fpy run fizzbuzz.zh.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Keyword reference
|
||||
|
||||
| Python | 中文 |
|
||||
|---|---|
|
||||
| `if` | `如果` |
|
||||
| `else` | `否则` |
|
||||
| `elif` | `不然` |
|
||||
| `for` | `对于` |
|
||||
| `while` | `只要` |
|
||||
| `def` | `函数` / `定义` |
|
||||
| `class` | `类` / `类别` |
|
||||
| `return` | `返回` |
|
||||
| `import` | `导入` |
|
||||
| `from` | `从` |
|
||||
| `as` | `名` |
|
||||
| `in` | `在` |
|
||||
| `and` | `和` |
|
||||
| `or` | `或` |
|
||||
| `not` | `不` |
|
||||
| `True` | `真` |
|
||||
| `False` | `假` |
|
||||
| `None` | `空` |
|
||||
| `print` | `打印` / `写` |
|
||||
| `input` | `扫描` |
|
||||
| `len` | `长度` |
|
||||
| `range` | `范围` |
|
||||
| `lambda` | `匿名` / `λ` |
|
||||
| `yield` | `产生` |
|
||||
| `async` | `非同步` |
|
||||
| `await` | `等` |
|
||||
|
||||
Full mapping: [`zh.json`](https://git.keshavanand.net/foreign-thon/foreignthon-zh/raw/branch/main/src/foreignthon_zh/zh.json)
|
||||
|
||||
---
|
||||
|
||||
## Start a project
|
||||
|
||||
```bash
|
||||
fpy new myproject --lang zh
|
||||
cd myproject
|
||||
fpy run src/main.zh.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Documentation
|
||||
|
||||
→ [foreignthon.keshavanand.net](https://foreignthon.keshavanand.net/)
|
||||
|
||||
---
|
||||
|
||||
## Contributing
|
||||
|
||||
Found a missing translation or a better keyword choice? Open an issue or PR — no access to the core repo needed.
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
GPL v3
|
||||
|
||||
@@ -3,16 +3,17 @@ requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "foreignthon-template" # TODO: Modify to language code
|
||||
version = "0.0.0"
|
||||
description = "[Template] language pack for ForeignThon." # TODO: Replace [Template]
|
||||
name = "foreignthon-zh"
|
||||
version = "0.2.0"
|
||||
description = "Chinese language pack for ForeignThon."
|
||||
license = { text = "GPL v3" }
|
||||
requires-python = ">=3.9"
|
||||
authors = [
|
||||
{ name = "John Doe", email = "loremipsum@example.com" } # TODO: Swap with real information
|
||||
{ name = "Cody Trainer" },
|
||||
]
|
||||
keywords = ["foreignthon", "template", "template"] # TODO: Swap with real information
|
||||
dependencies = ["foreignthon>=0.5.3"] # TODO: Update Version to Latest
|
||||
keywords = ["foreignthon", "chinese", "中文", "mandarin"]
|
||||
|
||||
dependencies = ["foreignthon>=0.5.3"]
|
||||
|
||||
classifiers = [
|
||||
"Programming Language :: Python :: 3",
|
||||
@@ -21,10 +22,10 @@ classifiers = [
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://git.keshavanand.net/foreign-thon/foreignthon-template" # TODO: Update URL
|
||||
Homepage = "https://git.keshavanand.net/foreign-thon/foreignthon-zh"
|
||||
|
||||
[project.entry-points."foreignthon.langs"]
|
||||
template = "foreignthon_template" # TODO: Swap in format "code = foreignthon_code"
|
||||
zh = "foreignthon_zh"
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["src/foreignthon_template"] # TODO: Change to src/foreignthon_code
|
||||
packages = ["src/foreignthon_zh"]
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
{
|
||||
"meta": {
|
||||
"name": "Template",
|
||||
"native_name": "Template",
|
||||
"code": "template"
|
||||
},
|
||||
"keywords": {
|
||||
"if": "if",
|
||||
"else": "else",
|
||||
"elif": "elif",
|
||||
"for": "for",
|
||||
"while": "while",
|
||||
"def": "def",
|
||||
"class": "class",
|
||||
"return": "return",
|
||||
"break": "break",
|
||||
"continue": "continue",
|
||||
"pass": "pass",
|
||||
"try": "try",
|
||||
"except": "except",
|
||||
"finally": "finally",
|
||||
"raise": "raise",
|
||||
"with": "with",
|
||||
"import": "import",
|
||||
"from": "from",
|
||||
"as": "as",
|
||||
"in": "in",
|
||||
"is": "is",
|
||||
"and": "and",
|
||||
"or": "or",
|
||||
"not": "not",
|
||||
"del": "del",
|
||||
"global": "global",
|
||||
"nonlocal": "nonlocal",
|
||||
"assert": "assert",
|
||||
"yield": "yield",
|
||||
"await": "await",
|
||||
"async": "async",
|
||||
"lambda": "lambda",
|
||||
"True": "True",
|
||||
"False": "False",
|
||||
"None": "None"
|
||||
},
|
||||
"builtins": {
|
||||
"print": "print",
|
||||
"input": "input",
|
||||
"len": "len",
|
||||
"range": "range",
|
||||
"type": "type",
|
||||
"int": "int",
|
||||
"float": "float",
|
||||
"str": "str",
|
||||
"list": "list",
|
||||
"dict": "dict",
|
||||
"set": "set",
|
||||
"tuple": "tuple",
|
||||
"bool": "bool",
|
||||
"open": "open",
|
||||
"enumerate": "enumerate",
|
||||
"map": "map",
|
||||
"filter": "filter",
|
||||
"sorted": "sorted",
|
||||
"sum": "sum",
|
||||
"min": "min",
|
||||
"max": "max",
|
||||
"abs": "abs",
|
||||
"round": "round",
|
||||
"all": "all",
|
||||
"any": "any",
|
||||
"next": "next",
|
||||
"id": "id",
|
||||
"chr": "chr",
|
||||
"reversed": "reversed"
|
||||
},
|
||||
"exceptions": {
|
||||
"Exception": "Exception",
|
||||
"BaseException": "BaseException",
|
||||
"ValueError": "ValueError",
|
||||
"TypeError": "TypeError",
|
||||
"KeyError": "KeyError",
|
||||
"IndexError": "IndexError",
|
||||
"AttributeError": "AttributeError",
|
||||
"NameError": "NameError",
|
||||
"ImportError": "ImportError",
|
||||
"FileNotFoundError": "FileNotFoundError",
|
||||
"RuntimeError": "RuntimeError",
|
||||
"ZeroDivisionError": "ZeroDivisionError",
|
||||
"SyntaxError": "SyntaxError",
|
||||
"AssertionError": "AssertionError",
|
||||
"MemoryError": "MemoryError",
|
||||
"OverflowError": "OverflowError",
|
||||
"RecursionError": "RecursionError",
|
||||
"PermissionError": "PermissionError",
|
||||
"TimeoutError": "TimeoutError",
|
||||
"SystemExit": "SystemExit",
|
||||
"KeyboardInterrupt": "KeyboardInterrupt"
|
||||
},
|
||||
"error_messages": {
|
||||
"SyntaxError": "SyntaxError",
|
||||
"ValueError": "ValueError",
|
||||
"TypeError": "TypeError",
|
||||
"KeyError": "KeyError",
|
||||
"IndexError": "IndexError",
|
||||
"AttributeError": "AttributeError",
|
||||
"NameError": "NameError",
|
||||
"ImportError": "ImportError",
|
||||
"FileNotFoundError": "FileNotFoundError",
|
||||
"ZeroDivisionError": "ZeroDivisionError",
|
||||
"RecursionError": "RecursionError",
|
||||
"RuntimeError": "RuntimeError",
|
||||
"MemoryError": "MemoryError",
|
||||
"OverflowError": "OverflowError",
|
||||
"AssertionError": "AssertionError",
|
||||
"PermissionError": "PermissionError",
|
||||
"TimeoutError": "TimeoutError",
|
||||
"KeyboardInterrupt": "KeyboardInterrupt"
|
||||
},
|
||||
"stdlib": {
|
||||
"math": "math",
|
||||
"sys": "sys",
|
||||
"datetime": "datetime",
|
||||
"time": "time",
|
||||
"random": "random",
|
||||
"collections": "collections",
|
||||
"pathlib": "pathlib",
|
||||
"re": "re"
|
||||
},
|
||||
|
||||
"postfix_keywords": [
|
||||
|
||||
]
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
from importlib.metadata import PackageNotFoundError, metadata, version
|
||||
from importlib.resources import files
|
||||
from importlib.metadata import version, metadata, PackageNotFoundError
|
||||
|
||||
try:
|
||||
package_name = (__package__ or "").replace("_", "-")
|
||||
@@ -13,7 +13,7 @@ try:
|
||||
|
||||
# 2. Combine them into one single, clean list of unique names
|
||||
combined = []
|
||||
for item in (raw_authors + raw_emails):
|
||||
for item in raw_authors + raw_emails:
|
||||
clean_name = item.split("<")[0].strip()
|
||||
if clean_name and clean_name not in combined:
|
||||
combined.append(clean_name)
|
||||
@@ -24,6 +24,6 @@ except PackageNotFoundError:
|
||||
__version__ = "0.0.0"
|
||||
__authors__ = []
|
||||
|
||||
|
||||
def get_pack_path():
|
||||
# TODO: Modify this path
|
||||
return files(__name__) / "template.json"
|
||||
return files(__name__) / "zh.json"
|
||||
143
src/foreignthon_zh/zh.json
Normal file
143
src/foreignthon_zh/zh.json
Normal file
@@ -0,0 +1,143 @@
|
||||
{
|
||||
"meta": {
|
||||
"name": "Chinese",
|
||||
"native_name": "中文",
|
||||
"code": "zh"
|
||||
},
|
||||
"keywords": {
|
||||
"如果": "if",
|
||||
"否则": "else",
|
||||
"不然": "elif",
|
||||
"对于": "for",
|
||||
"只要": "while",
|
||||
"函数": "def",
|
||||
"定义": "def",
|
||||
"类": "class",
|
||||
"类别": "class",
|
||||
"导入": "import",
|
||||
"从": "from",
|
||||
"名": "as",
|
||||
"返回": "return",
|
||||
"打断": "break",
|
||||
"继续": "continue",
|
||||
"忽略": "pass",
|
||||
"试": "try",
|
||||
"失败": "except",
|
||||
"然后": "finally",
|
||||
"提出": "raise",
|
||||
"同": "with",
|
||||
"在": "in",
|
||||
"是": "is",
|
||||
"和": "and",
|
||||
"或": "or",
|
||||
"不": "not",
|
||||
"删除": "del",
|
||||
"共用": "global",
|
||||
"非本地": "nonlocal",
|
||||
"断言": "assert",
|
||||
"产生": "yield",
|
||||
"等": "await",
|
||||
"非同步": "async",
|
||||
"匿名": "lambda",
|
||||
"λ": "lambda",
|
||||
"真": "True",
|
||||
"假": "False",
|
||||
"空": "None"
|
||||
},
|
||||
"builtins": {
|
||||
"写": "print",
|
||||
"打印": "print",
|
||||
"扫描": "input",
|
||||
"长度": "len",
|
||||
"范围": "range",
|
||||
"类型": "type",
|
||||
"数字": "int",
|
||||
"浮点数": "float",
|
||||
"字符串": "str",
|
||||
"列表": "list",
|
||||
"字典": "dict",
|
||||
"序列": "set",
|
||||
"元組": "tuple",
|
||||
"布尔": "bool",
|
||||
"打开": "open",
|
||||
"枚举": "enumerate",
|
||||
"图": "map",
|
||||
"滤": "filter",
|
||||
"已排序": "sorted",
|
||||
"已反向": "reversed",
|
||||
"总和": "sum",
|
||||
"最小": "min",
|
||||
"最大": "max",
|
||||
"绝对值": "abs",
|
||||
"舍去": "round",
|
||||
"都": "all",
|
||||
"任何": "any",
|
||||
"是实例": "isinstance",
|
||||
"有属性": "hasattr",
|
||||
"取属性": "getattr",
|
||||
"设属性": "setattr",
|
||||
"以文字表示": "repr",
|
||||
"格式化": "format",
|
||||
"变量": "vars",
|
||||
"下": "next",
|
||||
"鉴别": "id",
|
||||
"字碼": "chr",
|
||||
"十六进制": "hex",
|
||||
"二进制": "bin",
|
||||
"八进制": "oct"
|
||||
},
|
||||
"exceptions": {
|
||||
"異常": "Exception",
|
||||
"基异常": "BaseException",
|
||||
"值异常": "ValueError",
|
||||
"类型异常": "TypeError",
|
||||
"键值异常": "KeyError",
|
||||
"索引异常": "IndexError",
|
||||
"属性异常": "AttributeError",
|
||||
"名称异常": "NameError",
|
||||
"载入异常": "ImportError",
|
||||
"档案未找到异常": "FileNotFoundError",
|
||||
"运行时异常": "RuntimeError",
|
||||
"除零异常": "ZeroDivisionError",
|
||||
"句法异常": "SyntaxError",
|
||||
"断言异常": "AssertionError",
|
||||
"记忆体异常": "MemoryError",
|
||||
"溢值异常": "OverflowError",
|
||||
"递归异常": "RecursionError",
|
||||
"权限异常": "PermissionError",
|
||||
"超时异常": "TimeoutError",
|
||||
"退出系统": "SystemExit",
|
||||
"键盘中断": "KeyboardInterrupt"
|
||||
},
|
||||
"error_messages": {
|
||||
"SyntaxError": "句法异常",
|
||||
"ValueError": "值异常",
|
||||
"TypeError": "类型异常",
|
||||
"KeyError": "键值异常",
|
||||
"IndexError": "索引异常",
|
||||
"AttributeError": "属性异常",
|
||||
"NameError": "名称异常",
|
||||
"ImportError": "载入异常",
|
||||
"FileNotFoundError": "档案未找到异常",
|
||||
"ZeroDivisionError": "除零异常",
|
||||
"RecursionError": "递归异常",
|
||||
"RuntimeError": "运行时异常",
|
||||
"MemoryError": "属性异常",
|
||||
"OverflowError": "属性异常",
|
||||
"AssertionError": "属性异常",
|
||||
"PermissionError": "权限异常",
|
||||
"TimeoutError": "超时异常",
|
||||
"KeyboardInterrupt": "键盘中断"
|
||||
},
|
||||
"stdlib": {
|
||||
"数学": "math",
|
||||
"系统": "sys",
|
||||
"日期时间": "datetime",
|
||||
"时间": "time",
|
||||
"随机": "random",
|
||||
"收藏": "collections",
|
||||
"路径库": "pathlib",
|
||||
"正则表达式": "re"
|
||||
},
|
||||
"postfix_keywords": []
|
||||
}
|
||||
Reference in New Issue
Block a user