JSFiddle - React, Tailwind, and code Playground

by Babar Raza

HTML

<input type="button" value="click me" id="button1">
<ul>
  <li>https://blog.aspose.com/</li>
  <li>https://blog.aspose.com/category/aspose-products/aspose-barcode-product-family/</li>
  <li>https://blog.aspose.com/2017/03/16/improved-multi-threaded-processing-png-codec-implementation-fast-processing-aspose.imaging-.net-17.03/</li>
  <li>https://zh.blog.aspose.com/</li>
  <li>https://zh.blog.aspose.com/2017/03/16/improved-multi-threaded-processing-png-codec-implementation-fast-processing-aspose.imaging-.net-17.03/</li>
  <li>https://zh.aspose.com/</li>
  <li>https://www.aspose.com/</li>
  <li>https://www.aspose.com/products/total</li>
  <li>https://www.aspose.com/products/total</li>
  <li>https://www.aspose.com/purchase/order-online-step-1-of-8.aspx</li>
  <li>http://www.aspose.com/corporate/default.aspx</li>
  <li>http://www.aspose.com/corporate/press-center/default.aspx</li>
  <li>http://www.aspose.com/corporate/purchase/temporary-license.aspx</li>
  <li>https://www.aspose.com/community/forums/default.aspx</li>
  <li>https://downloads.aspose.com/</li>
  <li>https://downloads.aspose.com/cells/net</li>
  <li>https://www.aspose.com/products/email</li>
  <li>https://www.aspose.com/products/email/java</li>
  <li>https://www.aspose.com/purchase/pricing/email/java</li>
  <li>https://www.aspose.com/products/barcode</li>
  <li>http://www.aspose.com/corporate/purchase/end-user-license-agreement.aspx</li>
  <li>https://docs.aspose.com/display/barcodeproductfamily/Home</li>
  <li>https://apireference.aspose.com/</li>
  <li>https://www.aspose.com/community/forums/aspose.barcode-product-family/193/showforum.aspx</li>
  <li>http://www.aspose.com/corporate/press-center/default</li>
  <li>http://www.aspose.com/products/total/java#support-resources</li>
  <li>https://downloads.aspose.com/corporate/case-studies/aspose.cells/</li>
  <li>https://www.aspose.com/Products/cells</li>
</ul>

JavaScript

$(document).ready(function() {

   $("#button1").on("click", function() {
     $("li").each(function(index) {
       $(this).text(onClick_languageMenu($(this).text()));
     });
   })
 });
 // Uncomment for live site
 //function onClick_languageMenu() 

 // Comment for live site
 function onClick_languageMenu(uri) {

   // Uncomment for live site
   //var uri = window.location.href;

   var anchor = document.createElement('a');
   anchor.href = uri;
   var hostparts = anchor.host.split('.');
   var newUrl;
   if (anchor.pathname.split('/')[1] == "products" && (hostparts[0] != "blog" || hostparts[1] != "blog")) {
     newUrl = "https://" + anchor.hostname.replace("www", "zh") + anchor.pathname.replace(/\/\s*$/, '') + anchor.hash;
   } else {
     newUrl = "https://zh.aspose.com";
   }


   if (hostparts[0] == "zh" && hostparts[1] == "blog") {
     var separate = hostparts;
     separate.shift();
     var currentdomain = separate.join('.');
     newUrl = "https://" + currentdomain + anchor.pathname.replace(/\/\s*$/, '') + anchor.hash;
   } else if (hostparts[0] == "blog") {
     hostparts.splice(0, 0, "zh");
     var currentdomain = hostparts.join(".");
     newUrl = "https://" + currentdomain + anchor.pathname.replace(/\/\s*$/, '') + anchor.hash;
   }


   // Comment for live site
   return newUrl;

   // Uncomment for live site
   //window.location = newUrl;
 }