-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@automattic/interpolate-components check #13634
Comments
The check for "@automattic/interpolate-components" is not part of Weblate, have you ever considered contributing it? In case it would implement placeholders highlighting, it would also make it correctly work with DeepL and no fixes would be needed. |
Here is the content of the custom from weblate.checks.base import TargetCheck
import re
import logging
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class AutomatticInterpolateComponentsCheck(TargetCheck):
check_id = 'automatic_interpolate_components'
name = '@automattic/interpolate-components mismatch'
description = 'Interpolation placeholders are inconsistent between source and translation.'
def check_single(self, source, target, unit):
source_tags = self.get_tags(source)
target_tags = self.get_tags(target)
# Log the tags
#logger.info("Source Tags: %s", source_tags)
#logger.info("Target Tags: %s", target_tags)
return source_tags != target_tags
@staticmethod
def get_tags(s):
# Use a simple regex to extract all tags
# This is a simple version and might need more robust handling for edge cases
matches = re.findall(r'{{(/?[a-zA-Z0-9_]+/?)}}', s)
sorted_matches = sorted(matches)
return ', '.join(sorted_matches) |
Thanks, let's focus here on improving this check work and integrating it with machine translations. I've created #13639 to track AI usage for fixing failing checks. |
Test cases of Regular expression playground: https://regex101.com/r/l5hbjW/1 Is this helpful for you? Unfortunately, I do not have real experience with Python and just found format.py where all those checks are placed, but I do not understand how to combine this with machine translation. |
Describe the problem
We are using
POST /api/translations/(string: project)/(string: component)/(string: language)/autotranslate/
withauto_source=mt
andengines=deepl
. This works great, but when it comes to texts with variables this could run into check errors.In our case, we use
@automattic/interpolate-components
which allows interpolating React components in the frontend.Example: Source string:
which gets translated to Slovak via DeepL in:
In this case,
{{languages/}}
should not be translated.We already "work around" this by running into an error with a custom implemented check:
Describe the solution you would like
When using e.g. OpenAI
gpt-4o-mini
I can successfully fix the translation: https://chatgpt.com/share/67920307-bbe0-8002-a653-4a6db846c721Prompt:
The feature request
It would be great to define beside "Checks" so-called "Automatic Fixer". This allows to configure on rule-level a LLM and prompt, and when the check error occurs, automatically try to fix the issue. In our case, I can imagine the following flow:
@automattic/interpolate-components
as check which should be fixedgpt-4o-mini
Describe alternatives you have considered
No response
Screenshots
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: