zoukankan      html  css  js  c++  java
  • translation.js

    /**
    * Global Config variables
    */
    supportLanguage1 = "en-US";
    supportLanguage1Alias = encodeURI("English Version");

    supportLanguage2 ="zh-CN";
    supportLanguage2Alias = encodeURI("中文版");


    var cookie = new JSCookie();


    /**
    * Auto translates the entire page when document is ready .
    *
    * @Author overseas
    */
    $(document).ready(function(){


    //language_complete = navigator.language.split("-");
    //language = (language_complete[0]);
    //console.log("Sprache (root): %s", language);
    //$(window).load(function(){

    var currentLanguage = cookie.GetCookie("power7000Language");

    if ( (!currentLanguage && typeof(currentLanguage)!="undefined" && currentLanguage!=0) || (currentLanguage=="") )
    {
    currentLanguage = supportLanguage1;//"en-US";
    changeLanguage();
    }

    var resPath = getRootPath_web() + '/locales/__lng__/__ns__.json';



    i18n.init({
    lng: currentLanguage,
    ns: { namespaces: ['power7000.jsp'], defaultNs:'power7000.jsp'},
    resGetPath: resPath,
    fallbackLng: false,
    useLocalStorage:false
    }, function() {
    // save to use translation function as resources are fetched
    $("*").i18n();

    //alert(currentLanguage);
    //alert(i18n.t("app.name")+":114");

    //后置翻译方法 2015-01-21 lkg
    //检测方法postTranslate是否存在
    if(window.loadData)
    {
    window.loadData();
    }

    // In order to display HTML page after loading complete 2015-01-20 lkg
    document.body.style.visibility="visible";

    //调整窗体布局 2015-01-21 lkg
    ///检测方法adjustLayout是否存在
    if(window.adjustLayout)
    {
    window.adjustLayout();
    }

    //div #hideAll: in order to display HTML page after loading complete
    //document.getElementById("hideAll").style.display = "none";

    });
    });


    /**
    * Read cookie value by name .
    *
    * @Author overseas
    */
    function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') c = c.substring(1, c.length);
    if (c.indexOf(nameEQ) == 0) {
    return decodeURIComponent(c.substring(nameEQ.length, c.length))
    }
    } return null
    }

    /**
    * Set cookie value .
    *
    * @Author overseas
    */
    function setCookie(name, value, expires, path, domain) {
    if (!expires) expires = -1;
    if (!path) path = "/";
    var d = "" + name + "=" + value;
    var e;

    if (expires < 0) {
    e = "";
    }
    else if (expires == 0) {
    var f = new Date(1970, 1, 1);
    e = ";expires=" + f.toUTCString();
    }
    else {
    var now = new Date();
    var f = new Date(now.getTime() + expires * 1000);
    e = ";expires=" + f.toUTCString();
    }
    var dm;
    if (!domain) {
    dm = "";
    }
    else {
    dm = ";domain=" + domain;
    }
    document.cookie = name + "=" + value + ";path=" + path + e + dm;

    };

    /**
    * Change language via cookie.
    */
    function changeLanguage(){
    var currentLanguage = cookie.GetCookie("power7000Language");
    var currentLanguageAlias = cookie.GetCookie("power7000LanguageAlias");
    var nextLanguageAlias = cookie.GetCookie("power7000NextLanguageAlias");


    //var supportLanguage1 = "en-US";
    //var supportLanguage1Alias = encodeURI("English Version");

    //var supportLanguage2 ="zh-CN";
    //var supportLanguage2Alias = encodeURI("中文版");

    var newLanguage = supportLanguage1;
    var newLanguageAlias = supportLanguage1Alias;

    var path = "/";


    if (!currentLanguage && typeof(currentLanguage)!="undefined" && currentLanguage!=0){
    //null
    newLanguage = supportLanguage1;
    newLanguageAlias = supportLanguage1Alias;
    nextLanguageAlias = supportLanguage2Alias;
    }
    else if(currentLanguage==supportLanguage1){

    newLanguage = supportLanguage2;
    newLanguageAlias = supportLanguage2Alias;
    nextLanguageAlias = supportLanguage1Alias;
    }
    else if(currentLanguage==supportLanguage2){
    newLanguage = supportLanguage1;
    newLanguageAlias = supportLanguage1Alias;
    nextLanguageAlias = supportLanguage2Alias;
    }
    else{
    //other
    newLanguage = supportLanguage1;
    newLanguageAlias = supportLanguage1Alias;
    nextLanguageAlias = supportLanguage2Alias;
    }

    //alert(currentLanguage +"-->"+newLanguage);

    var expire_time = new Date();
    expire_time.setFullYear(expire_time.getFullYear() + 100);

    cookie.SetCookie('power7000Language', newLanguage, expire_time);
    cookie.SetCookie('power7000LanguageAlias', newLanguageAlias, expire_time);
    cookie.SetCookie('power7000NextLanguageAlias', nextLanguageAlias, expire_time);

    //alert(readCookie("power7000Language"));
    i18n.setLng(newLanguage);
    $("*").i18n();
    }

    /**
    * Format a message with placeholder.
    *
    * Examples:
    * var addr = "{0}省, {1}市, {2}区";
    * alert(addr.format("广东","深圳"));
    * alert("{0}省, {1}市, {2}区".format("广东","深圳"));
    * @Author overseas
    */
    String.prototype.format = function(){
    var args = arguments;
    return this.replace(/{(d+)}/g,
    function(m,i){
    return args[i];
    });
    };


    /**
    * Get web root path .
    *
    * @Author overseas
    */
    function getRootPath_web() {
    //获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp
    var curWwwPath = window.document.location.href;
    //获取主机地址之后的目录,如: uimcardprj/share/meun.jsp
    var pathName = window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathName);
    //获取主机地址,如: http://localhost:8083
    var localhostPaht = curWwwPath.substring(0, pos);
    //获取带"/"的项目名,如:/uimcardprj
    var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
    return (localhostPaht + projectName);
    }


    /**
    * Get top most element by z-index .
    *
    * @Author overseas
    */
    $.fn.topmost = function () {
    var positionedDivs = this.filter( function() {
    return !isNaN( parseInt( $(this).css("z-index"), 10 ) );
    });
    var topElem = positionedDivs.first();

    positionedDivs.each( function() {
    if ( $(this).css('z-index') > +topElem.css("z-index") ) {
    topElem = $(this);
    }
    });

    return topElem.get(0) || this.get(0);
    };

  • 相关阅读:
    触发器_01(trigger)
    24.Show table status解析
    Mysql排名问题
    zabbix监控
    MyFlash工具
    23.Sharding:谁都能读懂的分库、分表、分区
    Mysql集群结构说明
    Percona XtraDB Cluster(PXC) Mysql集群
    mysql-router
    MGR搭建的过程中遇见的错误以及处理方法
  • 原文地址:https://www.cnblogs.com/zhu-java/p/4564734.html
Copyright © 2011-2022 走看看