我是靠谱客的博主 柔弱石头,最近开发中收集的这篇文章主要介绍根据页面路径 来给 bluemix 加 local url,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

// Chinese (Simplified) - /cloud-computing/bluemix/zh/
// Chinese (Traditional) - /cloud-computing/bluemix/zh-hant/
// French - /cloud-computing/bluemix/fr/
// French (Canadian) - /cloud-computing/bluemix/ca-fr/
// German - /cloud-computing/bluemix/de/
// Italian - /cloud-computing/bluemix/it/
// Japanese - /cloud-computing/bluemix/ja/
// Korean - /cloud-computing/bluemix/ko/
// Portuguese - /cloud-computing/bluemix/pt/
// Spanish - /cloud-computing/bluemix/es/
jQuery(document).ready(function($) {
  // console.log($('a'));
  var langList = ["zh", "fr", "de", "it", "ja", "kr", "pt", "es", "br", "cl", "co", "ec", "py", "uy", "ve", "bo", "pe", "mx", "ar", "ch", "at"];

  function getLocale() {
    var lang = window.location.pathname.match(//[a-z][a-z]-[a-z][a-z]//);
    if (lang) {
      return lang[0].substr(1, lang[0].length - 2).split('-');
    } else {
      lang = window.location.pathname.match(//[a-z][a-z]/[a-z][a-z]//);
      return lang[0].substr(1, lang[0].length - 2).split('/');
    }
  }
  $('a').each(function(i, v) {

    if ($(v).prop("href") && $(v).attr("href").match('/bluemix/')) {
      var $plain_url = $(v).attr('href');
      var locale = getLocale();

      if (locale[0] === 'ca' && locale[1] === 'fr') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/' + locale[0] + '-' + locale[1] + '/'));
      } else if (locale[0] === 'tw' && locale[1] === 'zh') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/zh-hant/'));
      } else if (locale[0] === 'cn' && locale[1] === 'zh') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/zh/'));
      } else if (locale[0] === 'br' && locale[1] === 'pt') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/pt/'));
      } else if (locale[0] === 'ch' && locale[1] === 'fr') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/fr/'));
      } else if (locale[0] === 'kr' && locale[1] === 'ko') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/ko/'));
      } else if (locale[0] === 'cl' && locale[1] === 'es') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/es/'));
      } else if (locale[0] === 'co' && locale[1] === 'es') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/es/'));
      } else if (locale[0] === 'ec' && locale[1] === 'es') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/es/'));
      } else if (locale[0] === 'py' && locale[1] === 'es') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/es/'));
      } else if (locale[0] === 'uy' && locale[1] === 'es') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/es/'));
      } else if (locale[0] === 've' && locale[1] === 'es') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/es/'));
      } else if (locale[0] === 'bo' && locale[1] === 'es') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/es/'));
      } else if (locale[0] === 'pe' && locale[1] === 'es') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/es/'));
      } else if (locale[0] === 'mx' && locale[1] === 'es') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/es/'));
      } else if (locale[0] === 'ar' && locale[1] === 'es') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/es/'));
      } else if (locale[0] === 'at' && locale[1] === 'de') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/de/'));
      } else if (locale[0] === 'ch' && locale[1] === 'de') {
        $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/de/'));
      } else if (locale[0] === 'jp' && locale[1] === 'ja') {
        if (!$(v).attr("href").match('/cloud-computing/jp/ja/bluemix/'))
          $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/ja/'));
      }
      else {
        if (langList.indexOf(locale[1]) !== -1) {
          $(v).attr("href", $plain_url.replace('/bluemix/', '/bluemix/' + locale[0] + '/'));
        }
      }
    }
  })
})

 

最后

以上就是柔弱石头为你收集整理的根据页面路径 来给 bluemix 加 local url的全部内容,希望文章能够帮你解决根据页面路径 来给 bluemix 加 local url所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部