feat: 初始化仓库
This commit is contained in:
87
models/i18n.py
Normal file
87
models/i18n.py
Normal file
@@ -0,0 +1,87 @@
|
||||
# _*_ coding : UTF-8 _*_
|
||||
# @Time : 2025/02/04 15:43
|
||||
# @UpdateTime : 2025/02/04 15:43
|
||||
# @Author : sonder
|
||||
# @File : i18n.py
|
||||
# @Software : PyCharm
|
||||
# @Comment : 本程序
|
||||
|
||||
from tortoise import fields
|
||||
|
||||
from models.common import BaseModel
|
||||
|
||||
|
||||
class Locale(BaseModel):
|
||||
"""
|
||||
语言模型.
|
||||
"""
|
||||
code = fields.CharField(
|
||||
max_length=10,
|
||||
description="语言代码",
|
||||
source_field="code",
|
||||
unique=True
|
||||
)
|
||||
"""
|
||||
语言代码。
|
||||
- 例如:en(英语)、zh(中文)、fr(法语)。
|
||||
- 最大长度为10个字符。
|
||||
- 映射到数据库字段 code
|
||||
"""
|
||||
|
||||
name = fields.CharField(
|
||||
max_length=50,
|
||||
description="语言名称",
|
||||
source_field="name",
|
||||
unique=True
|
||||
)
|
||||
"""
|
||||
语言名称。
|
||||
- 最大长度为50个字符。
|
||||
- 映射到数据库字段 name
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
table = "locale"
|
||||
table_description = "语言表"
|
||||
|
||||
|
||||
class I18n(BaseModel):
|
||||
"""
|
||||
国际化模型.
|
||||
"""
|
||||
key = fields.CharField(
|
||||
max_length=255,
|
||||
description="国际化key",
|
||||
source_field="key"
|
||||
)
|
||||
"""
|
||||
国际化key。
|
||||
- 最大长度为255个字符。
|
||||
- 映射到数据库字段 key
|
||||
"""
|
||||
|
||||
locale = fields.ForeignKeyField(
|
||||
"models.Locale",
|
||||
related_name="i18n",
|
||||
description="语言",
|
||||
source_field="locale_id"
|
||||
)
|
||||
"""
|
||||
语言。
|
||||
- 关联到 Locale 模型。
|
||||
- 映射到数据库字段 locale_id
|
||||
"""
|
||||
|
||||
translation = fields.TextField(
|
||||
description="翻译内容",
|
||||
source_field="translation"
|
||||
)
|
||||
"""
|
||||
翻译内容。
|
||||
- 存储具体的翻译文本。
|
||||
- 映射到数据库字段 translation
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
table = "i18n"
|
||||
table_description = "国际化表"
|
||||
Reference in New Issue
Block a user