不同语言的可靠 strtotime() 结果
在 Joomla 中添加新文章时,后端显示的语言不是英语(对我来说是俄语),总是有一个奇怪的错误。 “完成发布”字段开始为当前日期,而不是俄语中的“从不”等效项。
对于php4中的一个站点,最后发现strtotime函数对于任意单词返回不同的结果。对于“从不”,它始终为 -1,并且 joomla 在 JDate 实现中依赖于此结果。但在其他情况下,它有时会返回有效日期。对于 Never (Никогда) 的俄语翻译是这种情况,对于单个“N”也是这种情况,因此如果决定将字符串更改为其他字符串,他或她将面临同样的问题。
因此,下面的代码
<?php
echo "Res:".strtotime("N")."<br>";
echo "Res:".strtotime("Nev")."<br>";
echo "Res:".strtotime("Neve")."<br>";
echo "Res:".strtotime("Never")."<br>";
?>
输出:
Res:1271120400
Res:-1
Res:-1
Res:-1
那么在这种情况下,解决方案是什么?我不想编写特定于语言的 date.php 处理程序,而是修改 JDate 类的日期方法,但是与语言无关的更改是为了检测无效字符串。
谢谢
There was always a strange bug in Joomla when adding new article with back-end displayed with a language other than English (for me it's Russian). The field "Finish Publishing" started to be current date instead of "Never" equivalent in Russian.
For a site in php4 finally found that strtotime function returns different results for arbitrary words. For "Never" it always -1 and joomla relies on this result in the JDate implementation. But in other case it sometimes returns a valid date. For russian translation of Never (Никогда) it is the case, but also for single "N" it is the case, so if one decided to change the string to some other he or she would face the same issue.
So the code below
<?php
echo "Res:".strtotime("N")."<br>";
echo "Res:".strtotime("Nev")."<br>";
echo "Res:".strtotime("Neve")."<br>";
echo "Res:".strtotime("Never")."<br>";
?>
Outputs:
Res:1271120400
Res:-1
Res:-1
Res:-1
So what are the solutions would be in this case? I would like not to write language-specific date.php handler, but to modify date method of JDate class, but what are language-neutral changes would be in order to detect invalid string.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试一种不同的方法。
为什么不尝试将新的语言变量
$example="-1"
添加到您的语言文件中,并将现有变量(“Никогда”输出)替换为$example 这样你就可以简单地获得相同的功能。
I would try a different aproach.
Why don't you try just to add a new language variable
$example="-1"
to your language files and replace the existing variable ("Никогда" output) with$example
so you can simply get the same functionallity.