Mono Support UI for user to change locale 

Viewed 54848 time(s), 17 post(s), 7/18/2014 10:18:52 AM - by Zoomicon
8/19/2014 2:21:37 PM
2793 Reputation 345 Total posts

there seems to be a crazy bug (in IE11/Win8.1 trying) with the texteditor here, I paste
</br>https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
</br>and when right-clicking in the editor the URL looks fine in the dialog shown when I select Properties...

but after I Post, the url address becomes damaged (this specific one says //Web and also string with small caps, maybe other changes too), although the text stays untouched. So the URL ends up broken

11
8/19/2014 3:57:27 PM
2793 Reputation 345 Total posts

so the javascript node I came up with (guess it parses ok since I wrote it using http://www.jshint.com) for adding in the ASPX is:
</br> </br>

<script>
</br> </br>var curAddr = document.location;
</br> </br>var newAddr = curAddr.replace(new RegExp("/lng/[a-z]{2}-[A-Z]{2}", "gi"), "");
</br> </br>if (curAddr != newAddr)
</br> </br>  document.location = newAddr;
</br> </br></script>

or the more cryptic:
</br> </br>
</br> </br><script>
</br> </br>var curAddr = document.location;
</br> </br>var newAddr = curAddr.replace(/\/lng\/[a-z]{2}-[A-Z]{2}/gi, "");
</br> </br>if (curAddr != newAddr)
</br> </br>  document.location = newAddr;
</br> </br></script>
</br> </br>
</br> </br>since according to

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp 

Literal and constructor notations of regular expressions are possible:
</br> </br>
</br> </br>/pattern/flags;
</br> </br>new RegExp(pattern [, flags]);

...

the following expressions create the same regular expression:
</br> </br>
</br> </br>/ab+c/i;
</br> </br>new RegExp("ab+c", "i");
</br> </br>

12
8/19/2014 2:58:14 PM
2793 Reputation 345 Total posts

(without the </br> of course which the editor insterted (IE11/Win8 issue reported in the past)

13
8/20/2014 12:28:16 PM
2793 Reputation 345 Total posts

seems to work fine, it just needs a fix to change document.location (which is an object) to document.location.href (which is a string), as I explain at http://stackoverflow.com/questions/2652816/what-is-the-difference-between-document-location-href-and-document-location/25404315#25404315

the correct script is:

<script>
</br>
var curAddr = document.location.href;
</br>
var newAddr = curAddr.replace(new RegExp("/lng/[a-z]{2}-[A-Z]{2}", "gi"), "");
</br>
if (curAddr != newAddr)
</br>
  document.location = newAddr;
</br>
</script>

14
8/20/2014 12:28:38 PM
2793 Reputation 345 Total posts

(without the </br>'s)

15
8/20/2014 1:03:28 PM
2793 Reputation 345 Total posts

So we will be using 3 master pages, one with the language selector webpart, a second one without the language selector that will contain the above script node to remove the /lng/xx-XX part from the URL and go to that URL, and a 3d one that will contain the language selector but will show a note at the top of the page (and the end of the master page / header that is) that will tell the user to visit the English version of the page for more content (e.g. we have a master English blog and some parts of it are translated at localized blogs, but not all).

the 3d master page will have a node like the following:

<div class="someCSSclass">
</br><script>
</br>   var curAddr = document.location.href;
</br>   var newAddr = curAddr.replace(new RegExp("/lng/[a-z]{2}-[A-Z]{2}","gi"), "/lng/en-US");
</br>   if (curAddr != newAddr)
</br>     document.write("<a href='" + newAddr + "'>Visit the English version of this page</a>");
</br>  </script>
</br></div>

16
8/20/2014 1:42:41 PM
2793 Reputation 345 Total posts

an a better version of that 3d script that redirects to the default instead of the /lng/en-US version
</br>
</br><div class="someCSSclass">
</br><script>
</br> if (document.location.href.search("/lng/en-US") == -1) {
</br>   var curAddr = document.location.href;
</br>   var newAddr = curAddr.replace(new RegExp("/lng/[a-z]{2}-[A-Z]{2}","gi"), "");
</br>   if (curAddr != newAddr)
</br>     document.write("<a href='" + newAddr + "'>Visit the English version of this page</a>");
</br>}
</br>  </script>
</br></div>
</br>
</br>

17
1 2
This is a demo site for MonoX. Please visit Mono Software for more info.