I have made a website that has 2 WordPress installs one for English language and one for Irish language. They are identical setups with same categories, page names etc.
I have 'English | Irish' links in my header on each page.
When you are on the english page and you click the 'irish' link at top I would like it to take you to the same page but on the Irish site.
The link structure is shown below:
http://mysite.com/english/about
So I really only need 'english' in the url to be replaced by 'irish'
Their are standard wordpress plugins that handle multi-language issue's for you. But if you whant to stay with you choise this script does exactly what you asked.
Are you using localization - see http://codex.wordpress.org/I18n_for_WordPress_Developers and http://codex.wordpress.org/Multilingual_WordPress? If so, see http://codex.wordpress.org/Function_Reference/get_locale. You can use this to detect the locale and update the link accordingly. If you're using a plugin, you should check the plugin documentation.
If not, you could parse the current URL and explode the path, then update the link this way - http://php.net/manual/en/function.parse-url.php
Example:
Adapted from http://www.codingforums.com/archive/index.php/t-186104.html