我正在尝试将基本检查添加为模块(不是包),但weblate_celery
无法加载。该文件被命名并保存在与主文件ApostropheCheck.py
相同的目录中。settings.py
我将它包括在内:
import ApostropheCheck
并将其添加到活动检查列表中:
CHECK_LIST += (
"ApostropheCheck.ApostropheCheck",
)
检查的代码是:
"""Check for consistent apostrophe usage."""
from django.utils.translation import gettext_lazy as _
from weblate.checks.base import TargetCheck
class ApostropheCheck(TargetCheck):
# Used as identifier for check, should be unique
# Has to be shorter than 50 characters
check_id = "apos"
# Short name used to display failing check
name = _("Apostrophe check")
# Description for failing check
description = _("Apostophe counts not consistent with source")
# Real check code
def check_single(self, source, target, unit):
if source.count('`') != target.count('`'): return True
if source.count('"') != target.count('"'): return True
if source.count("'") != target.count("'"): return True
return False