Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问大佬 merger.justhx.com 的多语言自动识别是通过什么实现的? #9

Closed
littlegolden opened this issue Jan 5, 2020 · 4 comments
Labels
answered A question that has been answered and no further action needed closing in 7 days The question in the issue has been answered and the issue will be closed if no replies in 7 days

Comments

@littlegolden
Copy link

littlegolden commented Jan 5, 2020

用 Accept-Language 吗?是用下面的方法吗?在主页用下面的js,会导致非中文用户无法自行跳转到中文页面。

				var type=navigator.appName ;
				if (type=="Netscape") 
				var lang = navigator.language ;
				else 
				var lang = navigator.userLanguage ;
				
				//cut down to first 2 chars of country code 
				var lang = lang.substr(0,5) ;
				
				// 英语
				if (lang == "en") 
				window.location.replace('./en/') ;
				
				// 日文
				else if (lang == "ja") 
				window.location.replace('./jp/') ;
@hifocus
Copy link
Collaborator

hifocus commented Jan 5, 2020

merger.justhx.com 本身没有做多语言识别,但是 https://docs.justhx.com/merger 是通过如下代码实现的:

    var userLang = navigator.language || navigator.userLanguage;
    if (userLang.includes("zh") || userLang.includes("cn")) {
        window.location.replace("https://merger.justhx.com/cn/");
    }
    else {
        window.location.replace("https://merger.justhx.com/");
    }

在写这类型代码的时候,请注意永远有一个 else { } fallback,即就算判断条件一个都不符合,也要给访客一个目的地。

@hifocus hifocus added answered A question that has been answered and no further action needed closing in 7 days The question in the issue has been answered and the issue will be closed if no replies in 7 days labels Jan 5, 2020
@littlegolden
Copy link
Author

littlegolden commented Jan 5, 2020

才发现只有测试版才支持多语言。。。对了,大佬加上下面的代码,让 PayPal 的弹窗居中出现吧?正式版屏幕左上角出现就很怪异。我的Merger用的是默认的CDN,所以我在本地改没效果,您可以在这里看效果,第一行的卡片的右边就是贝宝。

function openbox() {

	var paypal = "https://www.paypal.me/andrewsun74";
	
	//window.screen.height获得屏幕的高,window.screen.width获得屏幕的宽
	var iWidth = 500;                         //弹出窗口的宽度;
	var iHeight = 640;                        //弹出窗口的高度;
	var iTop = (window.screen.height-30-iHeight)/2; //获得窗口的垂直位置;  
	var iLeft = (window.screen.width-10-iWidth)/2; //获得窗口的水平位置;
	
    selected = "yes";
    window.open(
      paypal,
      "_blank",
      'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no'
	)
  }

@hifocus
Copy link
Collaborator

hifocus commented Jan 5, 2020

@littlegolden 这是一个好建议,将在下一个版本补充;但是我记得不需要这么繁复的 js...你可以去看看 function.js 里面应该是有的。

同时,目前 0.20 版本为 pre-release - 预先发布,而非测试版。0.20 版本仅有一个小错误,将会在下一个版本修复。

目前 0.20 还是预发布版本的原因为英文文档还没有同步新功能。

@hifocus hifocus added answered A question that has been answered and no further action needed closing in 7 days The question in the issue has been answered and the issue will be closed if no replies in 7 days and removed answered A question that has been answered and no further action needed closing in 7 days The question in the issue has been answered and the issue will be closed if no replies in 7 days labels Jan 5, 2020
@hifocus hifocus closed this as completed Jan 12, 2020
@hifocus
Copy link
Collaborator

hifocus commented Jan 18, 2020

才发现只有测试版才支持多语言。。。对了,大佬加上下面的代码,让 PayPal 的弹窗居中出现吧?正式版屏幕左上角出现就很怪异。我的Merger用的是默认的CDN,所以我在本地改没效果,您可以在这里看效果,第一行的卡片的右边就是贝宝。

function openbox() {

	var paypal = "https://www.paypal.me/andrewsun74";
	
	//window.screen.height获得屏幕的高,window.screen.width获得屏幕的宽
	var iWidth = 500;                         //弹出窗口的宽度;
	var iHeight = 640;                        //弹出窗口的高度;
	var iTop = (window.screen.height-30-iHeight)/2; //获得窗口的垂直位置;  
	var iLeft = (window.screen.width-10-iWidth)/2; //获得窗口的水平位置;
	
    selected = "yes";
    window.open(
      paypal,
      "_blank",
      'height='+iHeight+',innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no'
	)
  }

已于 084a93a 添加此特性;稍后会合并到主分支并发布新版本。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered A question that has been answered and no further action needed closing in 7 days The question in the issue has been answered and the issue will be closed if no replies in 7 days
Projects
None yet
Development

No branches or pull requests

2 participants