I wouldn't recommend having urls generated with javascript, but rather links on each of the page to the corresponding translated page using rel="alternative" and hreflang="code" with the language code corresponding to the 2 letter language code standard as depicted in http://googlewebmastercentral.blogspot.mx/2010/09/unifying-content-under-multilingual.html
to instruct the bots the pages are the same content in different languages.
If you could use a bit of php or server side code you could create your link reference very easily by replacing the urls with the new urls you are trying to create out of the current url. This is done by using patterns that perfectly match your criteria of url rewriting, that said, if you dont have any pattern, the best would be to set each link url separate per page.
Lets say you only need to convert english-site domain to welsh-site and news path segment to. According to http://reference.sitepoint.com/html/lang-codes, Welsh lang 2 letter standard would be 'cy'.
<?php
$lang['cy']['domain'] = 'welsh-site';
$lang['cy']['lang'] = 'Welsh';
$lang['cy']['news_slug'] = 'newyddion';
$lang['en']['domain'] = 'english-site';
$lang['en']['lang'] = 'English';
$lang['en']['news_slug'] = 'news';
$lang['default'] = 'en';
Explanation:
We are defining an array of languages where we will setup anything we need to translate. This is a multidimensional array map that defines each language by key in the first dimension, then each segment to translate in the second dimension. In this second dimansion we will setup special keys ending in _slug which will be part of the url to translate. This array can be saved in a special file apart for anything else and where we can go and edit easily without having us to modify the core code.
After defineyour initial language settings, now you need the code to identify the current language and path:
<?php
include('lang.php'); //this is the file where the language array is defined
$path = $_SERVER['REQUEST_URI'];
$host = isset($_SERVER['HTTP_HOST']) ? substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], ':')) : $_SERVER['SERVER_NAME'];
foreach ($lang as $code => $l) {
if ($l['domain'] == $host) {
$current_lang = $code;
break;
}
}
if ( ! isset($current_lang)) {
$current_lang = $lang['default'];
}
$_ = $lang[$current_lang];
$segment_1 = reset(explode('/', trim($path, '/'));
foreach ($lang[$current_lang] as $section => $url_segment) {
if ($segment_1 == $url_segment && substr($section, -5) == '_slug')
$current_section = $section;
break;
}
}
Explanation:
This code works as a bridge code that obtains the current section and language. First we obtain the host (domain name) and url path. In the first loop we match against any language domain to find the correct language we are on, then in the second loop we try to find the current section we are on with respect to the current language.
Now a little code to write the links using known information :
<head>
<?php foreach ($lang as $code => $l): ?><?php if ($code != $current_lang) : ?>
<?php $lang_path = isset($current_section) ? str_replace('/' . $_[$current_section] . '/', '/' . $l[$current_section] . '/', $path) : $path; ?>
<?php $lang_url = '//' . $l['domain'] . $lang_path; ?>
<link rel="alternative" hreflang="<?php echo $code; ?>" href="<?php echo $lang_url; ?>">
<?php endif; ?><?php endforeach; ?>
</head>
Explanation:
We are adding links that will tell bots the other links in your page are just different representations of this page in a different language. We also specify the lang code inside hreflang attribute (http://googlewebmastercentral.blogspot.mx/2010/09/unifying-content-under-multilingual.html)
Then you create your links (in the body section somewhere) the exact same way:
<ul>
<?php foreach ($lang as $code => $l): ?>
<?php if ($code != $current_lang) : ?>
<?php $lang_path = isset($current_section) ? str_replace('/' . $_[$current_section] . '/', '/' . $l[$current_section] . '/', $path) : $path; ?>
<?php $lang_url = '//' . $l['domain'] . $lang_path; ?>
<li><a href="<?php echo $lang_url; ?>"><?php echo $l['lang']; ?></a></li>
<?php else : ?>
<li class="active"><?php echo $l['lang']; ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
For all this to work your server must support PHP extension. I used php code because this is the most common code support to find.
You also need to change your file extensions, from .html to .php for this to work.
Hope it works for you. This might not be what you wanted, but rather what you actually need.