better language detection and permalink replacements