{"id":26,"date":"2009-11-17T19:13:17","date_gmt":"2009-11-17T18:13:17","guid":{"rendered":"http:\/\/blog.gocept.com\/?p=26"},"modified":"2012-12-03T15:11:28","modified_gmt":"2012-12-03T14:11:28","slug":"localized-dates-with-zope-2-and-zope-3","status":"publish","type":"post","link":"https:\/\/blog.gocept.com\/2009\/11\/17\/localized-dates-with-zope-2-and-zope-3\/","title":{"rendered":"Localized dates with Zope 2 and Zope 3"},"content":{"rendered":"

Imagine, you want to display a date in a nicer way than just 2009-11-17<\/em>. It’s not that difficult to localize it into e.g. German and output 17.11.2009<\/em>. But what, if you need to display\u00a0Mittwoch, 11.November 2009<\/em> instead?<\/em><\/p>\n

<\/em>Calling\u00a0strftime(‘%A, %d.%B %Y’) <\/em> on your date object would format the date with month- and week names, but in most cases display the names in English and not in German, as we @gocept need it.<\/span><\/span><\/p>\n

Locales<\/em> provide you with the nessecary functionality to format your datetime<\/em> object in the users local format and language. You can choose from different templates (parameter length<\/em>) or even create your own templates.<\/p>\n

The example defines a method formatDate<\/em> which takes a datetime<\/em> object. It retrieves the users\u00a0locale<\/em> settings from the request<\/em>, chooses a format template and then “mixes<\/em>” everything together :-).<\/p>\n

So, to get something like “Wednesday, 17.November 2009”, you will need to submit the length<\/em> parameter full<\/em> as shown in the above example:<\/p>\n

class MyView(object):<\/span>\r\ndef formatDate(self, datetime_date):<\/span>\r\nif not self.request._locale:<\/span>\r\n# zope2 doesn't initialize the locale itself<\/span>\r\nself.request.setupLocale()<\/span>\r\nformatter = self.request._locale.dates.getFormatter(<\/span>\r\n'date', \u00a0length='full')<\/span>\r\nreturn formatter.format(datetime_date)<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"

Imagine, you want to display a date in a nicer way than just 2009-11-17. It’s not that difficult to localize it into e.g. German and output 17.11.2009. But what, if you need to display\u00a0Mittwoch, 11.November 2009 instead? Calling\u00a0strftime(‘%A, %d.%B %Y’) on your date object would format the date with month- and week names, but in … Continue reading “Localized dates with Zope 2 and Zope 3”<\/span><\/a><\/p>\n","protected":false},"author":2072375,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[10221],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pFP3y-q","jetpack-related-posts":[{"id":2890,"url":"https:\/\/blog.gocept.com\/2017\/10\/24\/zope4-errorhandling\/","url_meta":{"origin":26,"position":0},"title":"Catching and rendering exceptions","author":"Michael Howitz","date":"October 24, 2017","format":false,"excerpt":"Error handling in Zope 4","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2789,"url":"https:\/\/blog.gocept.com\/2017\/10\/25\/testing-zope-4beta2\/","url_meta":{"origin":26,"position":1},"title":"Migrating from Zope 2.13 to 4.0b2","author":"Michael Howitz","date":"October 25, 2017","format":false,"excerpt":"Beta-Testing Zope 4 together with PerFact Innovation","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3229,"url":"https:\/\/blog.gocept.com\/2018\/06\/07\/migrate-a-zope-zodb-data-fs-to-python-3\/","url_meta":{"origin":26,"position":2},"title":"Migrate a Zope ZODB Data.fs to Python 3","author":"Michael Howitz","date":"June 7, 2018","format":false,"excerpt":"TL;DR Use\u00a0zodbupdate. Problem A ZODB\u00a0Data.fs\u00a0which was created under Python 2 cannot be opened under Python 3. This is prevented by using a different magic code in the first bytes of the file. This is done on purpose because str\u00a0has a different meaning for the two Python versions: Under Python 2\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/06\/spring-3383890_1280.jpg?fit=1200%2C797&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/06\/spring-3383890_1280.jpg?fit=1200%2C797&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/06\/spring-3383890_1280.jpg?fit=1200%2C797&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/06\/spring-3383890_1280.jpg?fit=1200%2C797&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/06\/spring-3383890_1280.jpg?fit=1200%2C797&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3225,"url":"https:\/\/blog.gocept.com\/2018\/05\/24\/zope-is-welcome-in-the-python-3-wonderland\/","url_meta":{"origin":26,"position":3},"title":"Zope is welcome in the Python 3 wonderland!","author":"Michael Howitz","date":"May 24, 2018","format":false,"excerpt":"Earl Zope already got the beta permission to stay in the Python 3 wonderland some months ago. His current objective is to help old friends to come to the Python 3 wonderland and to make new friends. He has to build trust in his will and ability to stay in\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/05\/zope-4-welcome-sprint.jpg?fit=1200%2C637&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/05\/zope-4-welcome-sprint.jpg?fit=1200%2C637&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/05\/zope-4-welcome-sprint.jpg?fit=1200%2C637&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/05\/zope-4-welcome-sprint.jpg?fit=1200%2C637&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/05\/zope-4-welcome-sprint.jpg?fit=1200%2C637&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1558,"url":"https:\/\/blog.gocept.com\/2016\/09\/05\/zope-in-the-python-3-wonderland\/","url_meta":{"origin":26,"position":4},"title":"Zope in the Python 3 wonderland","author":"Michael Howitz","date":"September 5, 2016","format":false,"excerpt":"A little tale Once upon the time there was the\u00a0big mighty Zope II. It was one of the leaders in the Python land. It had mighty features like TTW (trough the web) development\u00a0and its own object oriented database. Many\u00a0people liked Zope II and trusted it to be the basis for\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2632,"url":"https:\/\/blog.gocept.com\/2017\/09\/22\/earl-zope-ii-is-dead-long-live-earl-zope\/","url_meta":{"origin":26,"position":5},"title":"Earl Zope II is dead, long live Earl Zope","author":"Michael Howitz","date":"September 22, 2017","format":false,"excerpt":"Zope 4.0b1 released","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2017\/09\/pexels-photo-68806-e1506067407549.jpg?fit=1200%2C832&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2017\/09\/pexels-photo-68806-e1506067407549.jpg?fit=1200%2C832&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2017\/09\/pexels-photo-68806-e1506067407549.jpg?fit=1200%2C832&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2017\/09\/pexels-photo-68806-e1506067407549.jpg?fit=1200%2C832&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2017\/09\/pexels-photo-68806-e1506067407549.jpg?fit=1200%2C832&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/26"}],"collection":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/users\/2072375"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":14,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":335,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/26\/revisions\/335"}],"wp:attachment":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}