summaryrefslogtreecommitdiff
path: root/tools/fix_transifex_output.sh
blob: 0e1e9148f79d1fa0903b9f09011dd2d547b8667d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash

# What we get from Transifex is unusable and needs some fixing before we're able to use
# the translations.

FILE=$1

# Fix xliff tags
perl -i -pe 's/&lt;xliff:g id=\\?"(.*?)?\\?"&gt;/<xliff:g id="\1">/g' $FILE
perl -i -pe 's/&lt;\/xliff:g&gt;/<\/xliff:g>/g' $FILE

# Escape single and double quotes before and after xliff tags
perl -i -pe 's/([^\\])(["'\''])<xliff/\1\\\2<xliff/g' $FILE
perl -i -pe 's/xliff:g>(["'\''])/xliff:g>\\\1/g' $FILE

# Restore "&lt;" and "&gt;"
perl -i -pe 's/&amp;(lt|gt);/&\1;/g' $FILE

# <string ...></string> -> <string ... />
perl -i -pe 's/"><\/string>/"\/>/g' $FILE

# Escape single and double quotes (but not in comments or the xml tag)
perl -i -pe 's/([^\\])'\''/\1\\'\''/g unless /(<!--|xml)/' $FILE

# Use double quotes for 'message_view_recipient_prefix' value to retain trailing space
perl -i -pe 's/<string name="message_view_recipient_prefix">(.* )<\/string>/<string name="message_view_recipient_prefix">"\1"<\/string>/' $FILE