Trim leading/trailing whitespace for Apertium

Apertium can strip whitespace when translating, which confuses getRangeMappings.
This patch trims leading/trailing whitespace before pushing text to Apertium,
then reapplies it to the translated output.

Command-line diagnostic tool error reporting is also enhanced.

Change-Id: If22066aa5e04ad95f81d3160baf876ec09295874