|
Luca Fabbri |
|
|
Hi all,
I performed some search about a problem but I don't find any good tips. Let me introduce my doubt. I've a situation with a code that directly call to "datetimeobject.strftime(...)". It works on local machine but on the production server will ignore show localization as english. On the same Plone installation all other date/time information are displayed correctly (for example: the folder_listing view display dates in italian). So I started to analyze why. 1) referring to python date/time documentation, seems that the strftime is sensible to the current system locale, and can be changed using setlocales function (http://docs.python.org/library/locale.html), however I think that Plone never do this (for sure, for a good reason). Also in the same page is explicitly noted: "setlocale() is not thread-safe on most systems. Applications typically start with a call of >>> import locale >>> locale.setlocale(locale.LC_ALL, '') This sets the locale for all categories to the user’s default setting (typically specified in the LANG environment variable). If the locale is not changed thereafter, using multithreading should not cause problems." So I think that if a explicitly set a locale in the python envirinment of the server, I will have problem when the displayed date is not in italian, but for example I need all this works in english and italian. 2) checking how Plone is doing such kind of things, for example for translating "date_format_long" and "date_format_short", he is using translation inside the plonelocales domain. Inside those file all locales-sensible data like month names and weekdays names, are translated again. ---- Conclusion: I simply need to know if this analysis is correct, and if the direct use of strftime with localized information as weekday or month names is wrong. Nobody had the same problem? -- -- luca ------------------------------------------------------------------------------ 10 Tips for Better Web Security Learn 10 ways to better secure your business today. Topics covered include: Web security, SSL, hacker attacks & Denial of Service (DoS), private keys, security Microsoft Exchange, secure Instant Messaging, and much more. http://www.accelacomm.com/jaw/sfnl/114/51426210/ _______________________________________________ Plone-Users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/plone-users |
|
Balazs Ree-2 |
|
|
On 2011-07-20 14:13:13 +0200, Luca Fabbri said:
> Hi all, > > I performed some search about a problem but I don't find any good > tips. Let me introduce my doubt. > > I've a situation with a code that directly call to > "datetimeobject.strftime(...)". It works on local machine but on the > production server will ignore show localization as english. On the > same Plone installation all other date/time information are displayed > correctly (for example: the folder_listing view display dates in > italian). According to my knowledge, Plone is independent from the system locale. To have Plone working in the page's language (note that each page can have a different language, or the same page can be shown with different users in different languages) you should never need to touch the system locale. This was a practice in some old version of Zope, and turned out to be the wrong pattern, the first confusion it caused was with the character encodings. On the other hand if you want to change the locale, and use that locale from python, you could do that, and Plone should be ignoring this setting. Thread safeness is a problem, as I remember if you change the locale, it will change in all threads, not only in the one where you issued the setlocale from. So I would not do more than just setting the locale at application startup (otherwise you would need some simple locking which may be a pita) - or, not even that. I would try to use Plone's own way for the date formatting. Just my two cents. > So I started to analyze why. > > 1) referring to python date/time documentation, seems that the > strftime is sensible to the current system locale, and can be changed > using setlocales function > (http://docs.python.org/library/locale.html), however I think that > Plone never do this (for sure, for a good reason). > > Also in the same page is explicitly noted: > > "setlocale() is not thread-safe on most systems. Applications > typically start with a call of > > >>> import locale > >>> locale.setlocale(locale.LC_ALL, '') > > This sets the locale for all categories to the users default > setting (typically specified in the > LANG environment variable). If the locale is not changed > thereafter, using multithreading > should not cause problems." > > So I think that if a explicitly set a locale in the python envirinment > of the server, I will have problem when the displayed date is not in > italian, but for example I need all this works in english and italian. > 2) checking how Plone is doing such kind of things, for example for > translating "date_format_long" and "date_format_short", he is using > translation inside the plonelocales domain. Inside those file all > locales-sensible data like month names and weekdays names, are > translated again. > > ---- > > Conclusion: I simply need to know if this analysis is correct, and if > the direct use of strftime with localized information as weekday or > month names is wrong. > > Nobody had the same problem? -- Balazs Ree, Greenfinity, LLC ------------------------------------------------------------------------------ 5 Ways to Improve & Secure Unified Communications Unified Communications promises greater efficiencies for business. UC can improve internal communications as well as offer faster, more efficient ways to interact with customers and streamline customer service. Learn more! http://www.accelacomm.com/jaw/sfnl/114/51426253/ _______________________________________________ Plone-Users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/plone-users |
|
Luca Fabbri |
|
|
On Thu, Jul 21, 2011 at 12:34 PM, Balazs Ree <[hidden email]> wrote:
> On 2011-07-20 14:13:13 +0200, Luca Fabbri said: > >> Hi all, >> >> I performed some search about a problem but I don't find any good >> tips. Let me introduce my doubt. >> >> I've a situation with a code that directly call to >> "datetimeobject.strftime(...)". It works on local machine but on the >> production server will ignore show localization as english. On the >> same Plone installation all other date/time information are displayed >> correctly (for example: the folder_listing view display dates in >> italian). > > According to my knowledge, Plone is independent from the system locale. > To have Plone working in the page's language (note that each page can > have a different language, or the same page can be shown with different > users in different languages) you should never need to touch the system > locale. This was a practice in some old version of Zope, and turned out > to be the wrong pattern, the first confusion it caused was with the > character encodings. > > On the other hand if you want to change the locale, and use that locale > from python, you could do that, and Plone should be ignoring this > setting. Thread safeness is a problem, as I remember if you change the > locale, it will change in all threads, not only in the one where you > issued the setlocale from. So I would not do more than just setting the > locale at application startup (otherwise you would need some simple > locking which may be a pita) - or, not even that. I would try to use > Plone's own way for the date formatting. > > Just my two cents. > Thanks Balazs, in fact I think that the python setlocale is wrong, and so I want to use the ploneview toLocalizedTime, but it is quite limited in two format (long_format=True or False). I monkey patched it for translate whatever type of format I need. Seems the only way. -- -- luca twitter: http://twitter.com/keul linkedin: http://linkedin.com/in/lucafbb blog: http://blog.keul.it/ ------------------------------------------------------------------------------ 5 Ways to Improve & Secure Unified Communications Unified Communications promises greater efficiencies for business. UC can improve internal communications as well as offer faster, more efficient ways to interact with customers and streamline customer service. Learn more! http://www.accelacomm.com/jaw/sfnl/114/51426253/ _______________________________________________ Plone-Users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/plone-users |
| Powered by Nabble | Edit this page |