Can I make Piwik aware of locale specific URLs?

I’m using Piwik with a multilingual page which works like this:
English is defined as default and doesn’t add anything to the URL.
When switching to another language, the 2-letter language code is added as first path element.
E.g. foo.com/bar would be the English version, foo.com/es/bar the Spanish one.
In Piwik that has the effect that I can’t show the cumulated visits for the page bar, but need to manually navigate through all language nodes and manually sum it up.
Is there a way to configure Piwik such that it can handle that better?

You might do that within the JavaScript Tracking.
You could override the url that is tracked in piwik using setCustomUrl().
If you still wish to have the information which language the user has choosen, you might set that as a custom variable.

See the javascript tracking doku for more information: JavaScript Tracking Client: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3