XUnity.AutoTranslator icon indicating copy to clipboard operation
XUnity.AutoTranslator copied to clipboard

Add Post-processing after regex

Open GeBo1 opened this issue 5 years ago • 8 comments

Could RegexPostProcessing be added (similar to RomajiPostProcessing, TranslationPostProcessing) that's run on translations that match an r: or sr:? TranslationPostProcessing doesn't apply if a network job isn't created, but I would like ReplaceWideCharacters to be applied.

GeBo1 avatar Jul 08 '20 16:07 GeBo1

Could you provide an example so I am sure I understand the use-case? I assume this would only be run on specific regexes are not globally?

gravydevsupreme avatar Jul 11 '20 09:07 gravydevsupreme

I very much want it to be globally if the line matched an r: or sr: and it's enabled.

Given: r:"^例([0-90-9]+)$"=Example $1

I want 例0 => Example 0 if I have ReplaceWideCharacters enabled. (if that's non-obvious that was a wide on the left)

Given r:"^([A-ZA-Z]+)型$"=Type $1

A型 => Type A

GeBo1 avatar Jul 13 '20 14:07 GeBo1

Doing something like this for r:-style regexes is certainly possible. But sr: is much different.

First recognize that whatever is written in the text translation files should take priority. So if someone uses a wide-character there I would expect that to be honored.

But sr: regexes are splitting a given translation up and making an additional lookup for each part. That means the whatever the result of that lookup is should prevail. Often a lookup fails because the term is not present (such as when it is a number or a letter). In that case the plugin just returns that as a part translation.

I guess what you would want is that it is ONLY in this case this "post processing" logic should be applied. But in this scenario there is also the configuration option OutputUntranslatableText to handle. Under normal circumstances if that option is enabled the plugin is going to output just the number/letters as 1:1 translations. But if this is going to make sense that would have to be after this post processing IF the translation is a part of a regex.

I will have to consider if there are more potential features this might conflict with.

gravydevsupreme avatar Jul 16 '20 13:07 gravydevsupreme

Yeah, that makes sense about sr:. Even having just r: support would be great, if possible.

GeBo1 avatar Jul 22 '20 12:07 GeBo1

Alternately, having it only work with named groups that are flagged (similar to _i) (_p for "apply post procesing" and in an sr: allow _ip for "only apply post processing").

GeBo1 avatar Jul 28 '20 19:07 GeBo1

That is also something I considered. From a practical perspective it is not much different. But it might have some inconsistencies because then I would say the same have to be implemented for normal regexes as well. And in that case _i makes no sense.

gravydevsupreme avatar Jul 28 '20 21:07 gravydevsupreme

Isn't every named group in regular regexs treated as _i already?

GeBo1 avatar Aug 03 '20 16:08 GeBo1

Yes. There are no additional lookups.

gravydevsupreme avatar Aug 05 '20 19:08 gravydevsupreme