Skip to content

Commit

Permalink
Merge pull request #1 from D3fau4/develop
Browse files Browse the repository at this point in the history
Create highlight and validation for Deltarune
  • Loading branch information
Darkmet98 authored Sep 28, 2021
2 parents ef3a722 + 3aa21e4 commit 1864ef7
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tradusquare_customization/checks/delta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2021 Tradusquare
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Weblate checks for 'Deltarune' game."""

import re

from django.utils.translation import ugettext_lazy as _
from weblate.checks.base import TargetCheck

JSON_MATCH = re.compile(r"(?:\^[0-9])|(?:\/(?:%)+?$)|(?:\\[A-Za-z]{1,2}(?:[0-9]+)?)|(?:\[~[0-9]\])|(?:~[0-9])|(?:\/|%$)|(?:\\cY)|(?:\\cW)|(?:#)")


class DeltaKeywordCheck(TargetCheck):
"""
Custom checks for the Deltarune translation.
Adds a new check for the control codes like "\\E4"
It also adds highlighting.
"""

check_id = "game-Delta"
name = _("Delta keywords")
description = _("Delta keywords are missing")
default_disabled = True

def check_highlight(self, source, unit):
"""Highlight the control codes enclosed by the angles."""
if self.should_skip(unit):
return []
return [
(match.start(), match.end(), match.group())
for match in JSON_MATCH.finditer(source)
]

# Real check code
def check_single(self, source, target, unit):
"""Validate that the text contains the control code."""
src_match = JSON_MATCH.findall(source)
tar_match = JSON_MATCH.findall(target)
if (len(src_match) != len(tar_match)):
return True
return False

0 comments on commit 1864ef7

Please sign in to comment.