如何在本地托管g​​oogle libphonenumber? [英] How to host the google libphonenumber locally?

查看:150
本文介绍了如何在本地托管g​​oogle libphonenumber?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本地主机上进行开发期间,我试图自托管 libphonenumber 库.我正在尝试以下操作:

During development on my localhost, I am trying to self host the libphonenumber library. I am trying with the following:

<script src="//closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script>
<script>goog.require('goog.proto2.Message');</script>
<script src="scripts/vendor/pn/phonemetadata.pb.js"></script>
<script src="scripts/vendor/pn/phonenumber.pb.js"></script>
<script src="scripts/vendor/pn/metadata.js"></script>
<script src="scripts/vendor/pn/phonenumberutil.js"></script>
<script src="scripts/vendor/pn/asyoutypeformatter.js"></script>

这是可行的,但是我仍然依赖于外部托管的组件:闭包库.我尝试使用 closure-lite ,这(显然是我的新手)完整版本的闭包库,可用于自托管.我尝试执行以下操作:

This is working, but I still have a dependency to an externally hosted component: the closure library. I have tried using closure-lite, which is (apparently, I am new here) a quite complete version of the closure library, available for self-hosting. I have tried doing the following:

<script src="scripts/vendor/closure-lite.js"></script>
<script>goog.require('goog.proto2.Message');</script>
<script src="scripts/vendor/pn/phonemetadata.pb.js"></script>
<script src="scripts/vendor/pn/phonenumber.pb.js"></script>
<script src="scripts/vendor/pn/metadata.js"></script>
<script src="scripts/vendor/pn/phonenumberutil.js"></script>
<script src="scripts/vendor/pn/asyoutypeformatter.js"></script>

但是goog.proto2.Message不可用.我收到以下错误:

But the goog.proto2.Message is not available. I am getting the following errors:

Uncaught TypeError: Cannot read property 'Message' of undefined

错误来自phonemetadata.pb.js脚本:

goog.inherits(i18n.phonenumbers.NumberFormat, goog.proto2.Message);

我该怎么做才能完全自托管libphonenumber?

What can I do to completely self-host the libphonenumber?

推荐答案

您可能已经解决了这个问题,但是我发现了一种非常简单的方法,可以将所有libphonenumber代码编译成一个包含闭包库内容的文件.

You may have solved this already, but I found a really easy way to compile all the libphonenumber code into one file that includes closure library stuff.

转到 http://closure-compiler.appspot.com/home

这是Google的闭包编译器的在线版本.

This is Google's online version of the closure compiler.

然后输入如下内容:

// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name libphonenumber.js
// @use_closure_library true
// @code_url https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/phonemetadata.pb.js
// @code_url https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/phonenumber.pb.js
// @code_url https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/metadata.js
// @code_url https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/phonenumberutil.js
// @code_url https://raw.githubusercontent.com/googlei18n/libphonenumber/master/javascript/i18n/phonenumbers/asyoutypeformatter.js
// @formatting pretty_print
// ==/ClosureCompiler==

您可以添加或删除所需的任何其他文件.

You can add or delete any extra files you want.

然后单击编译.

这将从存储库中检索每个最新文件,并将其构建为单个javascript文件.

This will retrieve each of the latest files from the repository and build it into a single javascript file.

现在,您无需担心处理所有闭包库代码,因为您所需要的已经在其中编译了.

Now you don't need to worry about handling all the closure library code, as what you will need has already been compiled in.

希望这会有所帮助.

我发现这对于处理库的更新也非常有用.如果您只是在编译器中重新运行此程序,则将获得具有所有最新更新的新javascript文件.

I find that this is really useful for handling updates to the library as well. If you just rerun this in the compiler, you will get your new javascript file with all the latest updates.

这篇关于如何在本地托管g​​oogle libphonenumber?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆