I need to make a WPF control, which will allow a user to select a time zone. This control also needs to support multiple languages. I.e., time zone names should be displayed in the language, selected in the application.
.NET 3.5 supports an easy way of getting time zones list from the registry, by calling TimeZoneInfo.GetSystemTimeZones method. The problem with this approach is that it depends on current system. This means that different users may have different time zone list displayed on their machines. Some of that lists may be out of date, if the user refused to update his system.
One way to solve this may be to get an up-to-date list by calling TimeZoneInfo.GetSystemTimeZones on a up-to-date machine. And then serialize it to a file, which will be deployed with the application. Also, since this list is returned in the current system languag开发者_如何学Ce, I'll need to generate lists for every language on different Windows localizations. Or just make translations manually. With this approach, the user will have an up-to-date list provided he has the latest version of the application.
Another approach may be to use another time zones information source, like tz database. In this case I'll need to use some converters to translate tz database time zone API objects to standard TimeZoneInfo objects.
What approach do you use or recommend in such or similar cases?
I see how this could be problematic.
Option 1:
To keep things consistent I would create a list from an up-to-date machine (your dev machine for ex.) and include it as a resource file deployed with your app.
Then I would take care of the localization as part of the normal localization process, i.e. the time zones would be translated with the rest of the UI.
Option 2:
Assuming a client-server application you could restrict use of the timezone on client-side (i.e. always sending-receiving UTC times and converting them on the client), so that you can use the OS time zones and don't have to care what those zones actually are.
精彩评论