How to convert a standard Time Noda identifier from English to localized?

I am currently trying to localize the Windows Time Time application for several countries. I use Noda Time because it was very easy for a beginner. The problem I encounter is that all Timezone identifiers are in standard English, and I am looking for a way to get these identifiers converted to local language strings.

One way is to make localized strings for each identifier in each language. But it seems to be very inefficient, as there are 500 time zones. Please suggest me a way to immediately get the TimeZone identifier converted to a local language in a less time-consuming way.

My code is:

var now = Instant.FromDateTimeUtc(DateTime.UtcNow);
var tzdb = DateTimeZoneProviders.Tzdb;

var list = from id in tzdb.Ids
           where id.Contains("/") && !id.StartsWith("etc", StringComparison.OrdinalIgnoreCase)
           let tz = tzdb[id]
           let offset = tz.GetUtcOffset(now)
           orderby offset, id
           select new
           {
               DisplayValue = string.Format("(UTC{0}) {1}  {2}  ", offset.ToString("+HH:mm", null), now.WithOffset(offset).TimeOfDay.ToString("hh:mm tt",null),id)
           };
+4
1

Noda Time, .

( ) Unicode CLDR. XML , CLDR. , , .

, .

TimeZoneNames Nuget:

PM>  Install-Package TimeZoneNames

:

// example input values
var names = TZNames.GetNamesForTimeZone("America/Los_Angeles", "en-US");

// example output values
Assert.Equal("Pacific Time", names.Generic);
Assert.Equal("Pacific Standard Time", names.Standard);
Assert.Equal("Pacific Daylight Time", names.Daylight);

. , CLDR.

. , , .

var zones = TZNames.GetTimeZoneIdsForCountry("US");

.

+3

Source: https://habr.com/ru/post/1568551/


All Articles