I think it is bad idea to use to string manipulation to do the URL shortening as AEM is a enterprise level CMS and you can never restrict the URL length. Please use the either/combination of options mentioned in below post along with externalizer to get the absolute paths. The same logic will also help you in shortening url in page content using link rewrites in future. I would love to use Sling Resolution along with Server level redirects to best use of the implementations.
For both of the things to work, please write a sling model based on Page and init() post construct method, put the logic of getting the current page and get the language properties and set the calculated language attribute into a gettermethod, please follow the same for second scenario as well.