MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

UI for user to change locale  (Mono Support )

Viewed 49814 time(s), 17 post(s) 7/18/2014 10:18:52 AMby Zoomicon

Related topics

Zoomicon

Zoomicon

8/19/2014 2:21:37 PM

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

This content has not been rated yet. 
2793 Reputation 345 Total posts
Zoomicon

Zoomicon

8/19/2014 3:57:27 PM

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>

This content has not been rated yet. 
2793 Reputation 345 Total posts
Zoomicon

Zoomicon

8/19/2014 2:58:14 PM
(without the </br> of course which the editor insterted (IE11/Win8 issue reported in the past)
This content has not been rated yet. 
2793 Reputation 345 Total posts
Zoomicon

Zoomicon

8/20/2014 12:28:16 PM

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>

This content has not been rated yet. 
2793 Reputation 345 Total posts
Zoomicon

Zoomicon

8/20/2014 12:28:38 PM

(without the </br>'s)

This content has not been rated yet. 
2793 Reputation 345 Total posts
Zoomicon

Zoomicon

8/20/2014 1:03:28 PM

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>

This content has not been rated yet. 
2793 Reputation 345 Total posts
Zoomicon

Zoomicon

8/20/2014 1:42:41 PM
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>
This content has not been rated yet. 
2793 Reputation 345 Total posts
1 2