-
Notifications
You must be signed in to change notification settings - Fork 7
Add natural translation for DSL #574
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
base: master
Are you sure you want to change the base?
Conversation
Maybe we could support translations of a testplan (and rollout of templates?) as
with an extra option (or argument) to pass the natural language for the translation. |
This should work. |
@pdawyndt in #559 it also says that translations for files should be provided. In what sense? - files: !natural_language
en:
- name: "file.txt"
url: "media/workdir/file.txt"
nl:
- name: "fileNL.txt"
url: "media/workdir/fileNL.txt" This seems pointless since I could also just do: - files:
- name: "file.txt"
url: "media/workdir/file.txt"
- name: "fileNL.txt"
url: "media/workdir/fileNL.txt" |
Not really pointless as TESTed will show all "linked files" to the students. For each file, TESTed will try to find its name in the expression/statement and then turn that into a hyperlink. If it doesn't find the filename, it will add it to a list of files that is displayed for the testcase. |
@pdawyndt , I started looking for adding a translation table like translation:
animal:
en: "animal"
nl: "dier"
result:
en: "result"
nl: "resultaat" Is it even usefull to then also add support in a statement like the following: - statement: !natural_language
en: 'result = Trying(10, "{animal}")'
nl: 'resultaat = Proberen(10, "{animal}")' I would suggest not even searching lookingany deeper when a natural_language map is already found and only using translation map when the expected (like a string) is given. |
I definitely have many exercises where this (the combination of translation and template strings) is useful. So I would say yes. If we use Python format strings, then we could even write your example as - statement: !natural_language
en: 'result = Trying(10, {animal!r})'
nl: 'resultaat = Proberen(10, {animal!r})' And not even bother about using single or double quotes or escaping any quotes in the thing you put in the placeholders (which otherwise adds a lot of complication on the side of the DSL-author). If you have a variable statement = statement.format(**translation, **data) If we also allow data to be an YAML-array instead of a YAML map (positional instead of named placeholders), then formatting is done by statement = statement.format(*data, **translation) For example, if '{} + {} = {}' or with explicit positions (which would also allow reodering and reusing the array values) '{0} + {1} = {2}' |
Currently I've implemented support for The
|
I checked Jinja and still haven't found a way to keep the whitespace between the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not yetr looked at everything, but already some feedback.
Will look into it further next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're getting there :)
Code looks good! I am a bit disappointment that we didn't find a simpler way to write the schema, but that seems to be a json schema issue, if I understood you correctly.
I have only on remaining comment, but maybe discuss with @pdawyndt if he wants that schema also in this pr, or wants you to focus on different things. Because it doesn't really impact any of the code or workings of TESTed. So this seems good to go.
@@ -0,0 +1,2073 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This schema is written for validation by tested, after our own custom parser (Which is good, we need this)
Could you also provide one that is usable by editors, such as vs code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is addressed in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to test this a bit more with the new changes but the script i wrote should take care of our problem.
You can run the pre-processor by using
python -m tested.nat_translation ./exercise/simple-example/program_language_map/suite.yaml en # English translation
You can run the pre-processor followed by TESTed using the option
-t
:python -m tested -c exercise/simple-example/config.json -t en # English translation