Fix for extra space on google translate calls
Opened this issue · 1 comments
Hi @pragmatrix,
Minor thing to add that could be quite useful - I just noticed that Google Translate has a tendency to add extra spaces on interpolated strings, so that {0:n3}
becomes {0: n3}
. Could you maybe add a simple Regex to fix that?
Something like this should do the job:
var RE_FixExtraSpace = new Regex("{([^{]*?): ([^{]*?)}");
var wrongText = "{0: n0} träffar hittades i {1: n0} ms";
var fixedText = RE_FixExtraSpace.Replace(wrongText, "{$1:$2}");
I wondered if it would be possible to replace all interpolated string sections in such a way that it did not try to change them..
With Cloud Translate, it looks like you can markup the content as HTML and then add .. around the content that you don't want it to interfere with, I don't know if that would work with the Translate API call or not.
I've also seen a (kinda dirty hack, granted) where strings that shouldn't be changed are replaced with values that Google Translate won't try to translate -
support.google.com/translate/thread/18596146?hl=en&msgid=33005368
If that was reliable at all then there could be one pass to find interpolated values and replace them with non-translatable values, then run it through Google Translate, then replace the non-translatable values with their original text?
Just thinking out loud, I might be over thinking it (I just worried that there might be other formats of value that might be messed up, particularly if a variable name was mentioned in the interpolated value that was a valid word that Google tried to translate into the target language..?)