Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Jinx是一个Django项目国际化的一站式辅助工具
Django国际化常常包含以下流程
可以看到国际化不是一蹴而就的, 而且每个项目的国际化流程都不尽相同
那么jinx可以帮助你完成以下工作
因为暂时未提供pip的方式, 可以使用git clone的方式安装, 推荐使用poetry安装依赖
git clone https://github.com/kiritoscs/jinx
cd jinx
poetry install
如果你不想使用poetry, 可以使用pip安装依赖
参考pyproject.toml里的[tool.poetry.dependencies]
mv jinx.template.toml jinx.toml
python jinx.py marker -d ${YOUR_DJANGO_PROJECT_DIR}
详细配置参考配置说明
标记之后, 需要检查一下标记是否正确, 有时候会出现标记错误的情况, 具体参考Marker
PlanA: 利用extractor提取词条, 本质是基于marker的结果进行提取, 所以需要先检查标记结果
python jinx.py extractor -t ${YOUR_DJANGO_PROJECT_DIR} -l ${YOUR_PO_FILE}
PlanB: Django自带的makemessages命令(推荐)
python manage.py makemessages -l ${YOUR_LANGUAGE}
或者
djano-admin makemessages -l ${YOUR_LANGUAGE}
python jinx.py translator -p ${YOUR_PO_FILE} -o {YOUR_OFFICIAL_DICT_DIR}
默认白嫖使用GoogleAPI翻译, 略慢
目前内置了以下翻译来源
详细配置参考配置说明
导出词条
python jinx.py exporter -p ${YOUR_PO_FILE} -e ${YOUR_OUTPUT_DIR}
python jinx.py translator -p ${YOUR_PO_FILE} -o ${YOUR_FINAL_JSON_FILE} -m overwrite
PlanA: 利用compiler编译
python jinx.py compiler -l ${YOUR_PO_FILE}
PlanB: 利用Django compilemessages编译
python manage.py compilemessages
或者
djano-admin compilemessages
[language]
# 当前项目语言, 枚举参考 common/constants.py/LanguageEnum
current = "zh-CN"
# 翻译目标语言, 枚举参考 common/constants.py/LanguageEnum
dest = "en"
[marker]
# 标记器
## 严格模式, 存在f-string格式化的需要国际化的字符串时, 会跳过该文件的标记
strict_mode = false
[marker.filter]
# 过滤器, 不想翻译的文件或者目录
## 过滤目录
exclude_paths = [
"web",
"scripts",
"migrations",
"tests"
]
## 过滤文件
exclude_files = [
"manage.py",
"urls.py",
"wsgi.py",
"tests.py"
]
[marker.translation_func]
# 默认的翻译函数配置
## 默认的翻译函数
default = "ugettext_lazy"
## 翻译函数别名
alias = "_"
[marker.str_conditions.token]
# token(单词)的字符串条件配置
## 包含
contains = []
## 不包含
not_contains = []
## 以...开头
startswith = []
## 不以...开头
not_startswith = []
## 以...结尾
endswith = []
## 不以...结尾
not_endswith = ["\"\"\"", "'''"]
[marker.str_conditions.source_line]
# source_line(源码)的字符串条件配置
## 包含
contains = []
## 不包含
not_contains = ["logger", "__name__"]
## 以...开头
startswith = []
## 不以...开头
not_startswith = []
## 以...结尾
endswith = []
## 不以...结尾
not_endswith = ["\"\"\"", "'''"]
[translator]
# 翻译器
provider = "google_api"
mode = "update"
[youdao_client]
# 有道翻译客户端配置
url = "https://openapi.youdao.com/api"
app_key = ""
app_secret = ""
# domain是有道翻译的一个参数, 用于区分不同的翻译场景, 一般不需要修改
# 支持的领域参考: common/constants.py/YouDaoSupportDomainEnum
domain = "general"
FAQs
A full-stack i18n solution for Django
We found that django-jinx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.