serge-community / serge

Continuous localization platform
https://serge.io/
Other
237 stars 53 forks source link

Add number replacement sub-plugin for `transform` plugin #117

Open iafan opened 5 years ago

iafan commented 5 years ago

Apart from other transformations available in transform plugin, it would be nice to add an extra one that replaces a number or a sequence of numbers. Consider the following example:

Source: US $30 is translated into Russian as 30 долларов США.

Now, a new string comes in that says: US $25. Based on the previous translation pair, we could guess the translation to be 20 долларов США.

This might work with multiple numbers as well, and could take into consideration a potentially different ordering of numbers in translation. But for as long as both source and translation share the same set of numbers (even if their ordering is different), we could identify which number to change in the guessed translation. Example:

Source: This will take 3-5 days is translated into Russian as Вам потребуется от 3 до 5 дней.

If a new string comes in that says: This will take 3-4 days (only one number has changed) or This will take 2-4 days (both numbers have changed) we should be able to guess the proper translation in either case.