Prefix Locale Filter

This is a basic helper to convert a simple string devoid of whitespaces, into a URI relative to the server root and current locale. The generated URI will essentially have /[locale] (or just / for the default locale) prepended to the given input.

The only validations this filter involve are checking if the given input is a String or if the input is an absolute URI. Additionally, the filter strips away multiple slashes in the input string.

Default Locale: en
Current Locale: en
Input Output
{{ 'about' | prefix_locale }} /about
{{ '//about//' | prefix_locale }} /about/
{{ 'about me' | prefix_locale }} /about me
{{ 'https://www.example.com/about/' | prefix_locale }} https://www.example.com/about/
Default Locale: en
Current Locale: fr
Input Output
{{ 'about' | prefix_locale }} /fr/about
{{ '//about//' | prefix_locale }} /fr/about/
{{ 'about me' | prefix_locale }} /fr/about me
{{ 'https://www.example.com/about/' | prefix_locale }} https://www.example.com/about/