首页 > 解决方案 > 标题的Onfly翻译

问题描述

我使用Hugo来构建我的网站,其中包含多个语言部分。我经常专注于文本,以至于忘记翻译文件的标题。

title: "This is the title"
date: 2020-03-01
shorttext: "Here come the shorttext in for the blog cards"
...

现在的问题是,当我使用 grep 成为 title/shorttext 的入口并通过 translation-shell 命令进行管道传输时,如何将 translation-shell 的输出保存在 title/shorttext 的双引号中?

egrep 'shorttext:' $file | sed 's/shorttext: //g' | trans -brief -e bing :fr
"Ceci est un titre"

“Ceci est un titre”现在应该写入短文本后面的文件。有没有办法实现它?谢谢你的帮助

问候西尔维奥

标签: bashshellsedgreptranslation

解决方案


无论您获取翻译的命令是什么,您都可以在另一个sed命令中使用命令替换,如

sed -E 's/(^shorttext: ).*/\1"'"$(egrep 'shorttext:' $file | sed ...)"'"/' your file

请注意,sed替换命令被分成 3 个字符串,第一个和最后一个用单引号括起来,中间的一个用双引号括起来,以便在其中进行命令替换,"$(…)".


推荐阅读