locales middleware refactor