问题描述
我还是想 {{1 + 2}}
来进行评价为正常。但是除了正常的内插器,我想创建一个自定义的,我可以计划做我想做的事情。
I still want {{1+2}}
to be evaluated as normal. But in addition to the normal interpolator, I want to create a custom one that I can program to do whatever I want.
例如。 < P> [WELCOME_MESSAGE]< / P>
应该是℃的快捷方式; P> {{'WELCOME_MESSAGE|翻译}}< / P>
或< p翻译=WELCOME_MESSAGE>< / P>
。这样一来,国际化功能的应用程序会更方便书写。
e.g. <p>[[welcome_message]]</p>
should be a shortcut for <p>{{'welcome_message' | translate}}</p>
, or <p translate="welcome_message"></p>
. That way, i18n apps would be much more convenient to write.
就像是可能的东西吗?我目前正在经历的angular.js源$ C $ c,而插值系统看起来pretty复杂的(?)。有什么建议?
Is anything like that possible? I'm currently going through the angular.js source code, but the interpolation system looks pretty complicated(?). Any suggestions?
推荐答案
我创建的正则表达式查找的,取代了指令它的innerHTML。基本上,我可以重写任何文本到任何其他文本。以下是我做的:
I created a directive that regex-find-replaces it's innerHTML. Basically, I can rewrite any text into any other text. Here's how I did it:
How做我做angular.js重新评估/编译内部HTML?
现在我所要做的就是把我的指令属性, autotranslate
,在那里我希望我的插补工作的父元素之一,它重写它,但是我想要它! :D
Now all I have to do is to place my directive-attribute, "autotranslate
", in one of the parent elements of where I want my interpolator to work, and it rewrites it however I want it! :D
<div class="panel panel-default" autotranslate>
<div class="panel-heading">[[WELCOME]]</div>
<div class="panel-body">
[[HELLO_WORLD]
</div>
</div>
变为
<div class="panel panel-default" autotranslate>
<div class="panel-heading"><span translate="WELCOME"></span></div>
<div class="panel-body">
<span translate="HELLO_WORLD"></span>
</div>
</div>
这不正是我想要的。
which does exactly what I wanted.
这篇关于加入Angularjs另一个定制插补的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!