在 WordPress 中创建块时,我需要添加带有链接的翻译。我在 JS 中这样做,但它没有提供预期的结果:
import { render } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
export default function Final() {
let d = <a href="https://example.com">bothered me.</a>;
return (
<p> { __( 'The cold never {d} anyway.', 'text-domain' ) } </p>
)
}
document.addEventListener( "DOMContentLoaded", function(event) {
const appRoot = document.getElementById( 'root' );
if ( appRoot ) {
render(
<Final/>,
appRoot
)
}
});
Run Code Online (Sandbox Code Playgroud)
在 PHP 中,我可以使用 sprintf 并使用 %1s 等占位符轻松做到这一点。
echo sprintf(
__( 'The cold never %1s anyway', …Run Code Online (Sandbox Code Playgroud) 对于我们的应用程序,我们需要使用新功能template string.
var verLongKey= `834r845784576485
y84ery5845y485yu843
483y53485684576845
jhu87843647356756745==457485,mh
ererthe8t0998785==ery8`;
Run Code Online (Sandbox Code Playgroud)
但旧的浏览器(如Android默认浏览器)不支持模板字符串.
如何获得此功能的polyfill?尝试babel.我们让这个polyfill适用于所有功能但是template string.目前modernizr用于检测支持和显示警报以使用其他浏览器.这种方法对用户来说很烦人.如何让一些polyfill在非支持的浏览器上运行?
是什么让我们这样template strings.问题是我不能使用这些工具(trceur,babel),因为这个文件是在生产中生成的puppet.我们无法在那里运行这些转发器.想在浏览器端添加一些polyfill.键中包含一些\n需要保留它们的字符.我想要一些polyfill所以,我可以在configs js文件之前包含.
在python中,我可以执行以下操作:
name = "bob"
print("Hey, %s!" % name)
Run Code Online (Sandbox Code Playgroud)
.format()在JavaScript/NodeJS中是否有类似的东西(或Python )?
我必须输出一个必须始终有3位数的日期编号.而不是3,它必须写003,而不是12,它必须写012.如果它大于100输出它没有格式化.我想知道是否有一个我可以使用的正则表达式或一些快速的内联脚本,或者我必须创建一个应该这样做并返回结果的函数.谢谢!
在ruby中,您可以将变量插入到字符串中,如下所示:
x = "sake"
puts "I like #{x}"
$"I like sake"
Run Code Online (Sandbox Code Playgroud)
例如:
def what_i_like(word)
"I like #{word}"
end
Run Code Online (Sandbox Code Playgroud)
在javascript中有类似的方法吗?
我现在正在做的是:
x = "sake"
"I like" + x + ". "
Run Code Online (Sandbox Code Playgroud) 我遇到了这种奇怪的情况,其中像javascript构造的foreach在IE中不起作用,但它在FF中工作.好吧,并非所有for..in这些特殊的功能都不起作用.我会发布代码.在IE8中测试过.使用XHTML DTD进行测试.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Test </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script type="text/javascript">
<!--
String.prototype.format = function() {
var formatted = this;
var mycars = new Array(); //some
mycars[0] = "Saab";
mycars[1] = "Volvo";
mycars[2] = "BMW";
var arg;
for (arg in mycars) { alert('it comes here');
formatted = formatted.replace("{" + arg + "}", arguments[arg]); }
return formatted;
};
String.prototype.format2 = function() …Run Code Online (Sandbox Code Playgroud) 我如何在coffeescript中使用string.format()或sprintf()?
我想要一个模仿python .format()函数的javascript函数
.format(*args, **kwargs)
Run Code Online (Sandbox Code Playgroud)
前一个问题为'.format(*args)提供了一个可能的(但不是完整的)解决方案
JavaScript等效于printf/string.format
我希望能够做到
"hello {} and {}".format("you", "bob"
==> hello you and bob
"hello {0} and {1}".format("you", "bob")
==> hello you and bob
"hello {0} and {1} and {a}".format("you", "bob",a="mary")
==> hello you and bob and mary
"hello {0} and {1} and {a} and {2}".format("you", "bob","jill",a="mary")
==> hello you and bob and mary and jill
Run Code Online (Sandbox Code Playgroud)
我意识到这是一个很高的订单,但也许某个地方有一个包含关键字参数的完整(或至少部分)解决方案.
哦,我听说AJAX和JQuery可能有这方面的方法,但我希望能够在没有这些开销的情况下完成它.
特别是,我希望能够将其与google doc的脚本一起使用.
谢谢
现代编程语言允许开发人员使用占位符创建字符串,并使用通常调用的函数/方法替换正确的值format.有时,它看起来像这样:
"Hi {0}! How are you?".format('John');
Run Code Online (Sandbox Code Playgroud)
Oracle SQL或PL/SQL中是否有任何具有相同行为的函数?或者这里的最佳做法是什么?