How can I change window.location?

According to the locale value, language information comes after the domain name in the URL. For example, when it is tr, it is http://127.0.0.1:3000/tr/home. When it is English, it is http://127.0.0.1:3000/en/home. When locale tr comes, I want to do tr. When en gfel, I want to use en. I also want it to preserve any value that comes after the grammar.

In the examples above, there is /home, but it can also be other paths in the URL.

How can I change part of the location URL?