我正在使用PHP的gettext函数进行本地化.我正在使用Poedit进行实际翻译,并且通过其"从源代码更新"功能,可以很容易地提取所有需要翻译的字符串 - 除了内部heredoc语法.
Poedit正在使用xgettext程序从PHP源文件生成.po文件.当PHP代码如下所示,它工作得很好:
echo "<h1>". _("test") ."</h1>";
但是没有提取以下内容(请注意需要使用伪t对象):
echo <<<EOD
<h1>{$->_('test')}
EOD;
在PHP代码中,您可以通过以下方式解决问题:
<?php
$t = _('test');
echo <<<EOD
<h1>$t</h1>
EOD
?>
但我真的希望xgettext程序可以从heredoc块中提取字符串.
一个对于解决办法已建议在PHP文档注释.解决方法是告诉xgettext程序将PHP源文件视为Python代码.但是在Poedit中使用这种方法会给我带来很多来自xgettext解析器的语法错误.
有没有人知道获取xgettext从PHP heredoc语法中提取翻译的解决方法?
在gettext项目的票证系统上打开了一个有点相关的票证:http://savannah.gnu.org/bugs/?27740这表明可以改进对heredoc语法的支持?
$ I = 1; while($ i <3){print <<"EOT"; def px $ i = new E(user)if(!px $ i.hasErrors()){println"$ {px $ i.name}/$ {px $ i.empr.to} OK"}
EOT
    $i++;
}
产生错误:
如果没有borrar.pl第3行的包或对象引用,则无法调用方法"px".
如何"逃脱"if?
谢谢.
Vim的一大优势是对象选择,可快速处理单词,段落和各种分隔符内的内容.
例如,
vi{
将选择一对{}括号内的所有内容.
是否有任何等效功能来选择here here或heredoc:
<<<HTML
    ....
    ....
HTML;
基于ErichBSchulz的回答,我想出了一个heredoc内部选择的以下内容:
nmap <F6> ?<<<<CR>w*kV?<<<<CR>j
?<<<<CR>w    " find beginning tag (after <<<)
*k           " find matching end tag and go up 1 line
V            " enter visual mode
?<<<<CR>j    " find beginning tag and go down 1 line
在编写Ruby(客户端脚本)时,我看到了三种构建更长字符串的方法,包括行结尾,所有这些对我来说都"难闻".
有没有更清洁,更好的方法?
if render_quote?
  quote =  "Now that there is the Tec-9, a crappy spray gun from South Miami."
  quote += "This gun is advertised as the most popular gun in American crime. Do you believe that shit?"
  quote += "It actually says that in the little book that comes with it: the most popular gun in American crime."
  quote += "Like they're actually proud of that shit."
  puts quote
end
if render_quote?
  quote =<<EOS
Now that there …我试图使用here-doc的自定义方法,并希望传递参数(没有商业案例,我只是想学习红宝石).在这种情况下有没有办法传递参数?这就是我到目前为止所拥有的.
简单的方法,只是工作正常.
def meth1
  self.upcase
end
str1 = <<MY.meth1
  i am a small case string
MY
# "I AM A SMALL CASE STRING\n"
现在,我想让我们放下一些参数并尝试不同的变化,并且irb给我一个空白的凝视.
#variation 1
def meth2( <<EOF1, <<EOF2 )
  EOF1.upcase + "..." + EOF2.downcase
end
str2 = <<MY.meth2
 some string
EOF1
 ANOTHER STRING
EOF2
MY
我想在我的bash shell脚本中的一些参数之后通过"Here Document"执行python脚本,如下所示
python <<'__SCRIPT__'
...
__SCRIPT__
ARG1 ARG2 ...
但不知道如何提出这些论点.我已经尝试将它们放在python之后,在SCRIPT后面和SCRIPT之后的新行.但是在执行时所有情况都会报告错误.
那么正确的方法是什么?
BR,RUOCHEN
我在PyCharm社区3.4.1中使用Python 2.7和unittest2.我需要将CLI命令的文本输出与字符串的内容进行匹配以进行自动测试.
该命令的输出通常在行尾有尾随空格; 如果我在我用来存储预期文本的heredoc中的行末尾添加空格,它们会在编辑器中神秘地被删除而不会进入文件.为了解决这个问题,我不得不将我的heredoc分开并用空格重新组合; 这非常难看,但这是我能让它发挥作用的唯一方法.
我试过谷歌搜索并寻找解释,但我没有找到; 我怀疑可能是PyCharm的autoformatting混淆并将其视为一行Python代码,可以安全地删除尾随空格.
这是我的代码; 它在unittest2类中:
def test_help_command(self):
    textgot = run_the_help_command()
    partone = """
blah blaah blah blah blah
This line has a space at the end in the help output"""
    parttwo = """
foo foo foo foo foo
This line also ends with a trailing space in the help output"""
    partthree = """
baz baz baz 
"""
    # Recombine parts with spaces
    helptext = partone + " " + parttwo + " " + partthree
    self.assertMultiLineEqual(helptext, …当我在http://guides.rubyonrails.org/active_record_migrations.html中在线引用active_record_migrations时
在以下代码段中:
Run Code Online (Sandbox Code Playgroud)class ExampleMigration < ActiveRecord::Migration[5.0] def up create_table :distributors do |t| t.string :zipcode end # add a CHECK constraint execute <<-SQL ALTER TABLE distributors ADD CONSTRAINT zipchk CHECK (char_length(zipcode) = 5); SQL add_column :users, :home_page_url, :string rename_column :users, :email, :email_address end def down rename_column :users, :email_address, :email remove_column :users, :home_page_url execute <<-SQL ALTER TABLE distributors DROP CONSTRAINT zipchk SQL drop_table :distributors end end
以下陈述是什么意思?
execute <<-SQL
  ALTER TABLE distributors
    ADD CONSTRAINT zipchk
    CHECK (char_length(zipcode) = 5);
SQL …我正在尝试使用 terraform 创建复合 cloudwatch 警报。但不幸的是我的 terraform 代码因以下错误而中断:
错误:创建 CloudWatch 复合警报时出错 (node-count-office-time-composite-alarm-DP-1474-desert):ValidationError:AlarmRule 不得包含前导或尾随空格或者为 null 状态代码:400,请求 ID:272b14ae- e6bd-4e65-8bb8-25372d9a5f7c
以下是我的地形代码:
resource "aws_cloudwatch_composite_alarm" "node_count_office_time_alarm" {
  depends_on = [aws_cloudwatch_metric_alarm.node_count, aws_cloudwatch_metric_alarm.office_time]
  alarm_description = "Composite alarm for node count & office time"
  alarm_name        = "node-count-office-time-composite-alarm-${local.postfix}"
  alarm_actions = [var.sns_topic_arn]
  ok_actions    = [var.sns_topic_arn]
alarm_rule =<<-EOF
ALARM(${aws_cloudwatch_metric_alarm.node_count.alarm_name}) AND
ALARM(${aws_cloudwatch_metric_alarm.office_time.alarm_name})
EOF
}
我检查了很多次,我的alarm_rule中没有前导或尾随空格。AND 运算符后仅换行。我正在使用 terraform 0.15.3 版本。有人遇到类似的问题吗?我该如何解决这个问题?谢谢
我有以下功能:
#!/bin/bash
get_instance{
dbname=$(sqlplus -s / as sysdba<<EOF
set pages 0
set feedback off
select name from v\$database;
exit;
EOF)
echo $dbname
}
get_instance
它似乎工作。在错误消息的中间,我得到了我的dbname,但仍然返回一个语法错误。
 oracle@testdb01:db01:/home/oracle/
 > ./test.sh
 ./test.sh: line 3: get_instance{: command not found
 DB01
 ./test.sh: line 11: syntax error near unexpected token `}'
 ./test.sh: line 11: `}'
如果我完全删除函数调用,我会得到没有错误的结果:
dbname=$(sqlplus -s / as sysdba<<EOF
set pages 0
set feedback off
select name from v\$database;
exit;
EOF)
echo $dbname
oracle@testdb01:db01:/home/oracle
> ./test.sh
DB01
我需要做什么才能让它在函数中工作?
以下建议在 EOF 标签后放置括号并添加 …