2016-03-25 4 views
4

Der folgende Code gehostet in einem System, wo die Sprache des Betriebssystems Japanisch ist und ich die Anzeige der Zeitzone in japanischer Sprache bekomme. Ich habe die Globalisierungseinstellung in web.config auf Englisch gesetzt, aber kein Glück. Gibt es eine Möglichkeit, die Anzeige in englischer Sprache anzuzeigen?System TimeZone Anzeige in Englisch Text

<select id="timezone" name="timezone"> 
    @foreach (var timeZone in TimeZoneInfo.GetSystemTimeZones()) { 
     <option value="@timeZone.Id">@timeZone.DisplayName</option> 
    } 
</select> 

Screenshot der Benutzeroberfläche

enter image description here

+3

könnte ein Problem damit verbunden sein: http://stackoverflow.com/questions/13163241/getting-system-timezones-in-different-languages ​​ – greenshade

+0

Ich habe die Erlaubnis, meine Website in Hosting-Umgebung hosten und nicht haben jede Berechtigung, ein Sprachpaket zu installieren. – Hoque

+0

Ja, es hängt von der Betriebssystemlokalisierung und nicht von den Globalisierungsfunktionen von .NET ab. Dies wurde in [dem Zeitzonen-Tag-Wiki] (http://stackoverflow.com/tags/timezone/info) dokumentiert. Siehe auch [mein Blog zu diesem Thema] (http://codeofmatt.com/2014/12/26/localized-time-zone-names-in-net/) und versuche [diese Bibliothek] (http: // mj1856.github.io/TimeZoneNames/) für eine Lösung. –

Antwort

2

Sie ein Wörterbuch verwenden können, aber dann würden Sie haben um sie beizubehalten, wenn die Betriebssystem-Zeitzonen des Hosts aktualisiert werden (falls Zeitzonen sich ändern ... und sie DO ändern). Wenn du den Host nicht kontrollierst, könnte das eine echte Nervensäge sein.

ich gemacht habe es für Sie (Sie können es in this fiddle ... ignorieren alle Standardcode, es ist der Standard-Code in dotnetfiddle für MVC, Ich habe gerade die Aussicht):

@functions{ 
    string GetTimeZonesInEnglish(string timeZoneId, string defaultDisplayName) 
    { 
    var dict = new Dictionary<string, string>() 
    { 
     { "Dateline Standard Time"," (UTC-12:00) International Date Line West" }, 
     { "UTC-11"," (UTC-11:00) Coordinated Universal Time-11" }, 
     { "Hawaiian Standard Time"," (UTC-10:00) Hawaii" }, 
     { "Alaskan Standard Time"," (UTC-09:00) Alaska" }, 
     { "Pacific Standard Time (Mexico)"," (UTC-08:00) Baja California" }, 
     { "Pacific Standard Time"," (UTC-08:00) Pacific Time (US & Canada)" }, 
     { "US Mountain Standard Time"," (UTC-07:00) Arizona" }, 
     { "Mountain Standard Time (Mexico)"," (UTC-07:00) Chihuahua, La Paz, Mazatlan" }, 
     { "Mountain Standard Time"," (UTC-07:00) Mountain Time (US & Canada)" }, 
     { "Central America Standard Time"," (UTC-06:00) Central America" }, 
     { "Central Standard Time"," (UTC-06:00) Central Time (US & Canada)" }, 
     { "Central Standard Time (Mexico)"," (UTC-06:00) Guadalajara, Mexico City, Monterrey" }, 
     { "Canada Central Standard Time"," (UTC-06:00) Saskatchewan" }, 
     { "SA Pacific Standard Time"," (UTC-05:00) Bogota, Lima, Quito, Rio Branco" }, 
     { "Eastern Standard Time (Mexico)"," (UTC-05:00) Chetumal" }, 
     { "Eastern Standard Time"," (UTC-05:00) Eastern Time (US & Canada)" }, 
     { "US Eastern Standard Time"," (UTC-05:00) Indiana (East)" }, 
     { "Venezuela Standard Time"," (UTC-04:30) Caracas" }, 
     { "Paraguay Standard Time"," (UTC-04:00) Asuncion" }, 
     { "Atlantic Standard Time"," (UTC-04:00) Atlantic Time (Canada)" }, 
     { "Central Brazilian Standard Time"," (UTC-04:00) Cuiaba" }, 
     { "SA Western Standard Time"," (UTC-04:00) Georgetown, La Paz, Manaus, San Juan" }, 
     { "Newfoundland Standard Time"," (UTC-03:30) Newfoundland" }, 
     { "E. South America Standard Time"," (UTC-03:00) Brasilia" }, 
     { "SA Eastern Standard Time"," (UTC-03:00) Cayenne, Fortaleza" }, 
     { "Argentina Standard Time"," (UTC-03:00) City of Buenos Aires" }, 
     { "Greenland Standard Time"," (UTC-03:00) Greenland" }, 
     { "Montevideo Standard Time"," (UTC-03:00) Montevideo" }, 
     { "Bahia Standard Time"," (UTC-03:00) Salvador" }, 
     { "Pacific SA Standard Time"," (UTC-03:00) Santiago" }, 
     { "UTC-02"," (UTC-02:00) Coordinated Universal Time-02" }, 
     { "Mid-Atlantic Standard Time"," (UTC-02:00) Mid-Atlantic - Old" }, 
     { "Azores Standard Time"," (UTC-01:00) Azores" }, 
     { "Cape Verde Standard Time"," (UTC-01:00) Cabo Verde Is." }, 
     { "Morocco Standard Time"," (UTC) Casablanca" }, 
     { "UTC"," (UTC) Coordinated Universal Time" }, 
     { "GMT Standard Time"," (UTC) Dublin, Edinburgh, Lisbon, London" }, 
     { "Greenwich Standard Time"," (UTC) Monrovia, Reykjavik" }, 
     { "W. Europe Standard Time"," (UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna" }, 
     { "Central Europe Standard Time"," (UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague" }, 
     { "Romance Standard Time"," (UTC+01:00) Brussels, Copenhagen, Madrid, Paris" }, 
     { "Central European Standard Time"," (UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb" }, 
     { "W. Central Africa Standard Time"," (UTC+01:00) West Central Africa" }, 
     { "Namibia Standard Time"," (UTC+01:00) Windhoek" }, 
     { "Jordan Standard Time"," (UTC+02:00) Amman" }, 
     { "GTB Standard Time"," (UTC+02:00) Athens, Bucharest" }, 
     { "Middle East Standard Time"," (UTC+02:00) Beirut" }, 
     { "Egypt Standard Time"," (UTC+02:00) Cairo" }, 
     { "Syria Standard Time"," (UTC+02:00) Damascus" }, 
     { "E. Europe Standard Time"," (UTC+02:00) E. Europe" }, 
     { "South Africa Standard Time"," (UTC+02:00) Harare, Pretoria" }, 
     { "FLE Standard Time"," (UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius" }, 
     { "Turkey Standard Time"," (UTC+02:00) Istanbul" }, 
     { "Israel Standard Time"," (UTC+02:00) Jerusalem" }, 
     { "Kaliningrad Standard Time"," (UTC+02:00) Kaliningrad (RTZ 1)" }, 
     { "Libya Standard Time"," (UTC+02:00) Tripoli" }, 
     { "Arabic Standard Time"," (UTC+03:00) Baghdad" }, 
     { "Arab Standard Time"," (UTC+03:00) Kuwait, Riyadh" }, 
     { "Belarus Standard Time"," (UTC+03:00) Minsk" }, 
     { "Russian Standard Time"," (UTC+03:00) Moscow, St. Petersburg, Volgograd (RTZ 2)" }, 
     { "E. Africa Standard Time"," (UTC+03:00) Nairobi" }, 
     { "Iran Standard Time"," (UTC+03:30) Tehran" }, 
     { "Arabian Standard Time"," (UTC+04:00) Abu Dhabi, Muscat" }, 
     { "Azerbaijan Standard Time"," (UTC+04:00) Baku" }, 
     { "Russia Time Zone 3"," (UTC+04:00) Izhevsk, Samara (RTZ 3)" }, 
     { "Mauritius Standard Time"," (UTC+04:00) Port Louis" }, 
     { "Georgian Standard Time"," (UTC+04:00) Tbilisi" }, 
     { "Caucasus Standard Time"," (UTC+04:00) Yerevan" }, 
     { "Afghanistan Standard Time"," (UTC+04:30) Kabul" }, 
     { "West Asia Standard Time"," (UTC+05:00) Ashgabat, Tashkent" }, 
     { "Ekaterinburg Standard Time"," (UTC+05:00) Ekaterinburg (RTZ 4)" }, 
     { "Pakistan Standard Time"," (UTC+05:00) Islamabad, Karachi" }, 
     { "India Standard Time"," (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi" }, 
     { "Sri Lanka Standard Time"," (UTC+05:30) Sri Jayawardenepura" }, 
     { "Nepal Standard Time"," (UTC+05:45) Kathmandu" }, 
     { "Central Asia Standard Time"," (UTC+06:00) Astana" }, 
     { "Bangladesh Standard Time"," (UTC+06:00) Dhaka" }, 
     { "N. Central Asia Standard Time"," (UTC+06:00) Novosibirsk (RTZ 5)" }, 
     { "Myanmar Standard Time"," (UTC+06:30) Yangon (Rangoon)" }, 
     { "SE Asia Standard Time"," (UTC+07:00) Bangkok, Hanoi, Jakarta" }, 
     { "North Asia Standard Time"," (UTC+07:00) Krasnoyarsk (RTZ 6)" }, 
     { "China Standard Time"," (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi" }, 
     { "North Asia East Standard Time"," (UTC+08:00) Irkutsk (RTZ 7)" }, 
     { "Singapore Standard Time"," (UTC+08:00) Kuala Lumpur, Singapore" }, 
     { "W. Australia Standard Time"," (UTC+08:00) Perth" }, 
     { "Taipei Standard Time"," (UTC+08:00) Taipei" }, 
     { "Ulaanbaatar Standard Time"," (UTC+08:00) Ulaanbaatar" }, 
     { "North Korea Standard Time"," (UTC+08:30) Pyongyang" }, 
     { "Tokyo Standard Time"," (UTC+09:00) Osaka, Sapporo, Tokyo" }, 
     { "Korea Standard Time"," (UTC+09:00) Seoul" }, 
     { "Yakutsk Standard Time"," (UTC+09:00) Yakutsk (RTZ 8)" }, 
     { "Cen. Australia Standard Time"," (UTC+09:30) Adelaide" }, 
     { "AUS Central Standard Time"," (UTC+09:30) Darwin" }, 
     { "E. Australia Standard Time"," (UTC+10:00) Brisbane" }, 
     { "AUS Eastern Standard Time"," (UTC+10:00) Canberra, Melbourne, Sydney" }, 
     { "West Pacific Standard Time"," (UTC+10:00) Guam, Port Moresby" }, 
     { "Tasmania Standard Time"," (UTC+10:00) Hobart" }, 
     { "Magadan Standard Time"," (UTC+10:00) Magadan" }, 
     { "Vladivostok Standard Time"," (UTC+10:00) Vladivostok, Magadan (RTZ 9)" }, 
     { "Russia Time Zone 10"," (UTC+11:00) Chokurdakh (RTZ 10)" }, 
     { "Central Pacific Standard Time"," (UTC+11:00) Solomon Is., New Caledonia" }, 
     { "Russia Time Zone 11"," (UTC+12:00) Anadyr, Petropavlovsk-Kamchatsky (RTZ 11)" }, 
     { "New Zealand Standard Time"," (UTC+12:00) Auckland, Wellington" }, 
     { "UTC+12"," (UTC+12:00) Coordinated Universal Time+12" }, 
     { "Fiji Standard Time"," (UTC+12:00) Fiji" }, 
     { "Kamchatka Standard Time"," (UTC+12:00) Petropavlovsk-Kamchatsky - Old" }, 
     { "Tonga Standard Time"," (UTC+13:00) Nuku'alofa" }, 
     { "Samoa Standard Time"," (UTC+13:00) Samoa" }, 
     { "Line Islands Standard Time"," (UTC+14:00) Kiritimati Island" }, 
    }; 
    string retVal; 
    if(dict.TryGetValue(timeZoneId, out retVal)) 
     return retVal; 
    return defaultDisplayName; 
    }    
} 

Und dann:

<select id="timezone" name="timezone"> 
    @foreach (var timeZone in TimeZoneInfo.GetSystemTimeZones()) { 
     <option value="@timeZone.Id">@GetTimeZonesInEnglish(timeZone.Id, timeZone.DisplayName)</option> 
    } 
</select> 

ich habe einiges einfaches Konsolenprogramm die Saiten in „Wörterbuch initializer Format“ von einer englischen Maschine, nur für den Fall, dass Sie wollen, dass sie die Ausgabe aktualisieren:

Check it out in this fiddle

dies nur gesagt, da die Zeitzonen-Namen angezeigt werden nach der Registrierung des Betriebssystems Host und sind sprachabhängig gefunden ... während das, was ich oben gesagt „funktioniert“, wenn sie nie update, ich würde sagen, es ist einfach nicht der beste Weg, damit umzugehen.

Ich würde persönlich meine eigenen Zeitzonen umgehen, wenn ich in meiner Datenbank oder was auch immer nicht in der Kontrolle über meine Gastgeber, bin ... können Sie eine aktualisierte Zeitzone-Datenbank in the IANA oder in den wikipedia wenn Sie finden, um ihn zu Datamine.

Es gibt auch die Common Locale Data Repository von Unicode, die zu zeigen, Zeitzonen Benutzer (ohne Berücksichtigung viele redundante Zeitzonen) und stellt seine (leicht parseable) XML-Datei in vielen Sprachen

Und natürlich im Allgemeinen besser geeignet ist, gibt es auch Noda Time von niemand anderem als Jon Skeet (et al.), die Sie überprüfen möchten. I denke, es unterhält seine eigene Olson Timezone Database, aber ich bin nicht so sicher davon.

0

Eine Lösung wäre, eine String-Tabelle in Englisch mit Ihren Werten zu verwenden. Sie greifen entweder serverseitig (wie oben) oder clientseitig auf die String-Tabelle zu und verwenden die darin enthaltenen Werte zum Auffüllen Ihrer Dropdown-Liste.

Beispiel JSON-Datei:

{ 
"timezones":{ 
    "en":{ 
     "standard":[ 
      {"zone":"(UTC-5:00)", 
      "title":"Eastern Standard Time"}, 
      {"zone":"(UTC-6:00)", 
      "title":"Central Standard Time"}, 
      {"zone":"(UTC-7:00)", 
      "title":"Mountain Standard Time"}, 
      {"zone":"(UTC-7:00)", 
      "title":"Phoenix Standard Time"}, 
      {"zone":"(UTC-8:00)", 
      "title":"Pacific Standard Time"} 
     ], 
     "daylightSavings":[ 
      {"zone":"(UTC-4:00)", 
      "title":"Eastern Standard Time"}, 
      {"zone":"(UTC-5:00)", 
      "title":"Central Standard Time"}, 
      {"zone":"(UTC-6:00)", 
      "title":"Mountain Standard Time"}, 
      {"zone":"(UTC-7:00)", 
      "title":"Pacific Standard Time"} 
     ] 
    } 
} 

}

Probe (Client-Seite) Implementierung

<!DOCTYPE html> 
<html> 
    <head> 
     <script src="jquery-2.0.3.js" ></script> 
     <script type="text/javascript"> 
      var inDaylightSavings = false; 

      $(document).ready(function() { 
       // TODO - set in daylight savings. 

       // Load data from local json file 
       $.getJSON("tz.json", function(obj) { 
        var targetDataset = obj.timezones.en.standard; 
        // Adjust for U.S. daylight savings 
        if(inDaylightSavings){ 
         targetDataset = obj.timezones.en.daylightSavings; 
        } 

        // Update the dropdown 
        $.each(targetDataset, function(key, value){ 
         $("#selectTimezones").append("<option>" + value.zone + " " + value.title + "</option>"); 
        }); 
       }); 
      }); 
     </script> 
    </head> 
    <body> 
     <label>Select Timezone</label> 
     <select name="timezones" id="selectTimezones"> 
      <option value="None" selected="Selected">- not selected -</option> 
     </select> 
    </body> 
</html> 

Result