如何使用 POEdit 解析器忽略 PHP 换行符?

发布于 2024-09-08 04:57:55 字数 1029 浏览 9 评论 0原文

我目前正在使用 gettext 和 POEdit 翻译我的 PHP 应用程序。由于我尊重源代码中的打印边距,因此我习惯于编写这样的字符串:

print $this->translate("A long string of text
    that needs to follow the print margin and since
    php outputs whitespaces for every break line I do
    my sites renders correctly.");

但是,在 POEdit 中,正如预期的那样,换行符不会转义为空格。

A long string of text\n
    that needs to follow the print margin and since\n
    php outputs whitespaces for every break line I do\n
    my websites render correctly.\n

我知道一种方法是在更改源代码中的行时关闭字符串,如下所示:

print $this->translate("A long string of text " . 
    "that needs to follow the print margin and since " .
    "php outputs whitespaces for every break line I do " .
    "my sites renders correctly. ");

但是当文本需要更改和打印边距时,这不是一种可扩展的方法 仍然受到尊重,除非netbeans(我使用的IDE)可以像eclipse一样自动为我做到这一点 在Java中。

所以总而言之,有没有办法告诉 POEdit 解析器将换行符转义为首选项中的空格?

我知道即使换行符没有转义,字符串仍然是可翻译的,我问这个是为了让我的翻译者(有时甚至是客户/用户)避免混淆,认为他需要在 POEdit 中翻译时复制换行符。

I am currently translating my PHP application using gettext with POEdit. Since I respect the print margin in my source code, I was used to writing strings like that:

print $this->translate("A long string of text
    that needs to follow the print margin and since
    php outputs whitespaces for every break line I do
    my sites renders correctly.");

However, in POEdit, as expected, the linebreaks are not escaped to whitespaces.

A long string of text\n
    that needs to follow the print margin and since\n
    php outputs whitespaces for every break line I do\n
    my websites render correctly.\n

I know one approach would be to close the strings when changing lines in the source code like that:

print $this->translate("A long string of text " . 
    "that needs to follow the print margin and since " .
    "php outputs whitespaces for every break line I do " .
    "my sites renders correctly. ");

But it is not an approach that is extensible for me when texts need to change and print margin
still respected, unless netbeans (the IDE I use) can do that for me automatically just like eclipse
in java.

So in conclusion, is there a way to tell the POEdit parser to escape linebreaks as whitespaces in the preferences?

I know that the strings are still translatable even though linebreaks are not escaped, I'm asking this so my traductor (sometimes even the customer/user) will avoid confusion into thinking he needs to duplicate the linebreaks while he translates in POEdit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懷念過去 2024-09-15 04:58:03

您必须确保在脚本和应用程序中使用正确的换行符

 LF:    Line Feed, U+000A
 FF:    Form Feed, U+000C
 CR:    Carriage Return, U+000D
 CR+LF: CR (U+000D) followed by LF (U+000A)
 NEL:   Next Line, U+0085
 LS:    Line Separator, U+2028
 PS:    Paragraph Separator, U+2029

在 Windows 系统 (ms-dos) 中,换行符是 CR+LF,而在“类 Unix”系统中,它是LF adn 8Bit commodore's an CR

您必须确保源位置包含与您的编辑位置相同类型的提要。

您的服务器处理其换行符的方式与编辑器运行的主机不同,只需仔细检查这一点并根据您的操作系统开发一些自动替换 Unicode 字符的方法


正如您所说的“使用 POEdit 的 gettext 翻译我的 PHP 应用程序” ,我会创建一个脚本,通过 shell/doss/php 抛出所有文件,并自动将字符代码转换为您运行的系统类型。

因此,如果您在 Windows 上工作,那么您将搜索 U+000A 的所有字符并替换为 U+000DU+000A

You have to make sure that your using the right line breaks in your script and your app

 LF:    Line Feed, U+000A
 FF:    Form Feed, U+000C
 CR:    Carriage Return, U+000D
 CR+LF: CR (U+000D) followed by LF (U+000A)
 NEL:   Next Line, U+0085
 LS:    Line Separator, U+2028
 PS:    Paragraph Separator, U+2029

Within Windows systems (ms-dos) there line feed is CR+LF, And within "Unix-like" systems its LF adn 8Bit commodore's its a CR

You have to make sure that the source location contains the same type of feeds to your edit location.

Your server handles its line feeds different to the host that the editor is running on, just double check this and develope some means of auto replacing the Unicode chars depending on your OS


As you say that your "translating my PHP application using gettext with POEdit", i would create a script to go threw all your files via shell/doss/php and auto convert the character codes to the type of system your running on.

so if your working on Windows then you would search for all chars that are U+000A and replace with U+000DU+000A

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文