Zend_Date / Zend_Locale:更改特定语言环境的日期格式?
是否可以指示 Zend_Locale 它应该使用特定的语言环境,除了对日期格式进行微小的更改之外?我不想将 Zend_Date::toString() 与特定格式一起使用,因为这将在所有语言环境中使用此格式。
有问题的案例:我有根据用户的区域设置格式化的日期。我的荷兰同胞 (nl_NL) 用户要求使用 dd-mm-yyyy 格式的日期,而不是 Zend_Locale 强烈声称是我们的短日期格式的 dd-mm-yy。如果我更改输出日期的代码以显式使用自定义格式,则这适用于所有客户而不仅仅是奶酪头。我可以检查用户的区域设置,但如果需要创建更多例外,每次回显日期时我都需要添加这些检查和例外,这让我感到畏缩。
我无法直接更改 Zend_Locale XML 数据(也不想),因为 ZF 库被多个站点使用。
我确信这是那些“非常简单”的问题之一......一旦你知道如何做。有什么想法吗?
Is it possible to instruct Zend_Locale that it should use a certain locale, except for a minor alteration to the date format? I don't want to use the Zend_Date::toString() with the specific formatting, because that would use this format on all locales.
Case in question: I have dates formatted according to a user's locale setting. My fellow Dutch (nl_NL) users are asking for dd-mm-yyyy formatted dates, instead of dd-mm-yy which Zend_Locale vehemently claims to be our short date format. If I change the code where the date is outputted to explicitly use a custom format, that applies to all customers instead of just the cheeseheads. I could check the user's locale, but if more exceptions need to be created, every time a date is echo'd I'd need to add these checks and exceptions, the prospect of which makes me cringe.
I can't alter the Zend_Locale XML data directly (and don't want to), as the ZF library is used by various sites.
I'm sure this is one of those "really simple" issues... once you know how. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
[尝试一个新的答案,因为这种方法与以前的答案有本质上的不同。]
我假设您将在视图中调用
Zend_Date::toString()
。因此,也许您可以在配置文件中存储格式覆盖列表。在
Bootstrap
期间,检查加载的区域设置是否需要覆盖,然后将格式存储在视图中。然后,每当您输出日期时,请使用该格式。像这样的东西:
在
application/configs/application.ini
中:在
application/Bootstrap.php
中:最后在视图脚本中,其中
$date
是一个Zend_Date
对象:如果
$view->dateFormat
为 null,则将使用当前语言环境的格式。否则,您的覆盖将适用。[Trying a new answer since this approach is substantively different than the previous answer.]
I assume that you would be calling
Zend_Date::toString()
in a view.So, maybe you could store a list of format overrides in a config file. During
Bootstrap
, check if the loaded locale requires an override and then store the format in the view. Then whenever you output a date, use that format.Something like this:
In
application/configs/application.ini
:In
application/Bootstrap.php
:Finally in a view-script, where
$date
is aZend_Date
object:If
$view->dateFormat
is null, then the format for the current locale will be used. Otherwise, your override will apply.必须有某种方法可以:
Zend_Locale
然后,在
Bootstrap
中创建新的区域设置对象。如果当前区域设置与您要自定义的区域设置相匹配,则手动切换到新区域设置。关键可能是在哪里放置新的 XML 文件以及如何定义映射。当然,您可能不想在 Zend 文件夹中放置任何新内容,那么我们如何告诉
Zend_Locale
和他的朋友使用新位置呢?该映射信息是否“硬编码”在各个Zend_Locale_XXX
类中?无论如何,只是谈谈一些想法。希望它能给您一些方向或启发比我更有知识的其他人 - 确实,一个相当低的门槛! - 提出一些更明确和权威的东西。
干杯!
There must be some way to:
Zend_Locale
Then, in
Bootstrap
, create the new locale object. If the current locale matches the locale you wish to customize, then manually switch to the new locale.The key is probably where to place the new XML files and how to define the mapping. Of course, you probably don't want to place anything new in the Zend folders, so how do we tell
Zend_Locale
and his friends to use the new location? Is that mapping information "hard-coded" in the variousZend_Locale_XXX
classes?Anyway, just talking out some ideas. Hope it gives you some direction or inspires someone else more knowledgeable than me - a rather low bar, indeed! - to come up with something more definitive and authoritative.
Cheers!
我也开始考虑 David Weinraub 的第二个解决方案。
以下是我对任何区域设置切换到 4 位数字年份的风格:
在
Bootstrap
类(application/Bootstrap.php
文件)中使用它(使用新常量而不是 <代码>Zend_Date::DATE_SHORT):
I was also commencing to consider David Weinraub's second solution.
Here is my flavour for switching to 4-digits years for any Locale:
In
Bootstrap
class (application/Bootstrap.php
file)Use it (use the new constant instead of
Zend_Date::DATE_SHORT
):