If you want to make your xml dialog language-independent or customize it for various purposes you can use following scripts which allow you to use the same dialog structure for different languages or customers. Use them directly before dialog_xml2json.py
or update_all.py
in the pipeline.
You can replace all language-dependent fields with replacement codes using the script dialog_text2code
. Following command replaces all values of <values>
tags and all values of text
tags which has no values
subtags in the input file chitchat.xml
with replacement codes and creates a chitchat-resource-en.json
file with translations.
python scripts/dialog_text2code.py "example/en_app/dialogs/chitchat.xml" "chitchat-resource-en.json" -o "chitchat-encoded.xml" -v
chitchat.xml
file
...
<output>
<textValues>
<values>My name is $botName. What is your name?</values>
</textValues>
</output>
...
chitchat-encoded.xml
file
...
<output>
<textValues>
<values>%%TXT17</values>
</textValues>
</output>
...
chitchat-resource-en.json
file
{
...
"TXT17": "My name is $botName. What is your name?",
...
}
You can set different prefix of replacement codes using the -p CHITCHAT_
switch and it is also possible to add more tags to be replaced by specifying the -t
tag. Next command will replace all text
tags which has no values
subtags, all values
tags and all condition
tags with replacement codes prefixed by "CHITCHAT_".
python scripts/dialog_text2code.py "example/en_app/dialogs/chitchat.xml" "chitchat-resource-en.json" -o "chitchat-encoded.xml" -p "CHITCHAT_" -t "//text[not(values)]" "//values" "//condition" -v
chitchat.xml
file
...
<condition>#ALL_ABOUT_ME_WHAT_IS_YOUR_NAME or input.text.contains('name')</condition>
...
chitchat-encoded.xml
file
...
<condition>%%CHITCHAT_7</condition>
...
chitchat-resource-en.json
file
{
...
"CHITCHAT_7": "#ALL_ABOUT_ME_WHAT_IS_YOUR_NAME or input.text.contains('name')",
...
}
For more information on this script please type
python scripts/dialog_text2code.py --help
Having chitchat-encoded.xml
file and chitchat-resource-cz.json
file with czech translations, you can create czech version of source dialog in the following way:
python scripts/dialog_code2text.py "chitchat-encoded.xml" "chitchat-resource-cz.json" -o "chitchat-cz.xml" -t "//text[not(values)]" "//values" "//condition" -v
chitchat-encoded.xml
file
...
<condition>%%CHITCHAT_7</condition>
...
<output>
<textValues>
<values>%%CHITCHAT_17</values>
</textValues>
</output>
...
chitchat-resource-cz.json
file
{
...
"CHITCHAT_7": "#ALL_ABOUT_ME_WHAT_IS_YOUR_NAME or input.text.contains('jméno')",
...
"CHITCHAT_17": "Jmenuji se $botName. Jak se jmenuješ ty?",
...
}
chitchat-cz.xml
file
...
<condition>#ALL_ABOUT_ME_WHAT_IS_YOUR_NAME or input.text.contains('jméno')</condition>
...
<output>
<textValues>
<values>Jmenuji se $botName. Jak se jmenuješ ty?</values>
</textValues>
</output>
...
For more information on this script please type
python scripts/dialog_code2text.py --help