客户端定位客户端

2023-09-03 17:08:58 作者:无药可医╰

我愿做客户端的定位(即嵌入javascript和资源文件)。一切工作正常,直到我们有两个js文件,并在同一个项目(XXX.Web)的资源文件。

I would like to do client side localization (i.e embedding the javascript and resource files). Everything was working fine until we had both the js file and the resource file in the same project("XXX.Web").

由于要求的一部分,我不得不把所有的资源文件XXX.LocalizedResources项目,同时我还需要做的客户端本地化的JS文件。

As a part of a requirement, I had to move out all the resource files to "XXX.LocalizedResources" project, while I still need to do client side localization for the js file.

我试图在Web项目的AssemblyInfo.vb的以下内容:

I tried the following in the AssemblyInfo.vb of the Web project:

大会:System.Web.UI.WebResource(XXX.Web.GlobalStrings.js   文/ JavaScript的)

Assembly: System.Web.UI.WebResource("XXX.Web.GlobalStrings.js", "text/javascript")

大会:System.Web.UI.ScriptResource(XXX.Web.GlobalStrings.js   XXX.Web.Resources,资源)

Assembly: System.Web.UI.ScriptResource("XXX.Web.GlobalStrings.js", "XXX.Web.Resources", "Resources")

大会:System.Web.UI.WebResource(XXX.Web.GlobalStrings.js   文/ JavaScript的)

Assembly: System.Web.UI.WebResource("XXX.Web.GlobalStrings.js", "text/javascript")

大会:System.Web.UI.ScriptResource(XXX.Web.GlobalStrings.js   XXX.LocalizedResources.Resources,资源)

Assembly: System.Web.UI.ScriptResource("XXX.Web.GlobalStrings.js", "XXX.LocalizedResources.Resources", "Resources")

(请忽略以上线路的语法错误 ) 我现在得到的错误是:

(Please ignore the syntactical errors in the above lines ) And the error I get now is the following:

找不到任何资源适合于指定的区域性或   中性文化。确保XXX.LocalizedResources.Resources是   正确嵌入或链接到程序集​​XXX.Web在编译时,   或者确保所有需要的附属程序集都可加载并完全   签署。

寻你定位app下载 寻你定位安卓版手机客户端

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "XXX.LocalizedResources.Resources" was correctly embedded or linked into assembly "XXX.Web" at compile time, or that all the satellite assemblies required are loadable and fully signed.

从小事研发我碰到能中使用,只有Web或web.extension项目大会:System.Web.UI.ScriptResource(...)。

From little researching I came across that only web or web.extension projects could be used in "Assembly: System.Web.UI.ScriptResource (...)".

我尝试添加大会:InternalsVisibleTo(XXX.Web)中的XXX.LocalizedResources的程序集信息,但不做出资源文件开放给XXX.Web帮助。另外,资源文件已经公开,并嵌入选项设置过。

I tried adding "Assembly: InternalsVisibleTo("XXX.Web")" in AssemblyInfo of "XXX.LocalizedResources" but that doesn't help in making the resource file open to "XXX.Web". Also the resource files are already public and embed option is set too.

任何想法如何,我可以嵌入外部资源文件到一个JavaScript用于客户端的定位?

Any idea how I could embed an external resource file into a javascript for client side localization?

推荐答案

这包含在你的页面:

<script>
//declare string variable defaults here
function UrlExists(url){
var http = new XMLHttpRequest();
try{http.open('HEAD', url, false);
    http.send();
    return http.status!=404;
}catch(e){return false;}
}

var lang=navigator.userLanguage || navigator.language.toLowerCase();
var langsrc   = document.createElement("script");
langsrc.type  = "text/javascript";

if(UrlExists(lang+".js")){
   langsrc.src=lang+".js";
}else{
   langsrc.src="en-us.js";
}
document.body.appendChild(langsrc);
//rest of code here:
</script>

然后为每个支持的语言,建立了一个文件,如en-us.js

then for each supported language, set up a file such as en-us.js

//en-us.js localization for....
//set language specific variables here
//define language specific functions    

本文件云在相同的目录页,并且可以通过在该目录中的所有页面共享(与修改,它可以做多个目录或网站或只有一个文件,而是保持简单,所以你可以调味)

This file goes in the same directory as your page and can be shared by all pages in that directory (with modifications it could do multiple directories or sites or only one file, but keeping it simple so you can season to taste)

我会建议使用JSON对象为你的变量如果可能的话,虽然,这样你可以与你的服务器端(PHP的实例)共享一个本地化文件可能需要,如果你需要包括第二档为任何本地化的JavaScript函数任何

I would recommend using a JSON object for your variables if possible though so that you can share a single localization file with your server side (php for instance) You may need to include a second file for any localized javascript functions if you need any.