Benutzer:Cloned/Events zweisprachig

Aus Guild Wars 2 Wiki
Zur Navigation springen Zur Suche springen

Nachfolgend der Code, mit dem man sich jedes Event in GW2 in 2 Sprachen anzeigen lassen kann. Der Code muss hierfür nur in einer *.html Datei gespeichert und in einem Browser aufgerufen werden. In der Ausgabe werden dann jeweils das deutsche + englische Event nacheinander angezeigt. Auch die Anzeige in einer anderen Sprache als deutsch (fr, es) ist möglich.


<!DOCTYPE HTML>
 <html>
 <head>
     <meta charset="utf-8" />
     <meta http-equiv="X-UA-Compatible" content="IE=10" />
     <title>GW2 language events</title>
     <link type="text/css" rel="stylesheet" href="Content/style.css" />
 </head>
     <body>
 		<div>
 			<label for="slctLang">Language:</label>
 			<select id="slctLang">
 				<option value="de">Deutsch</option>
 				<!--<option value="en">English</option>-->
 				<option value="es">Espanol</option>
 				<option value="fr">French</option>
 			</select> 

 			<button onclick="javascript:eventsList()"> Generate complete Event List</button>
 			
             <div>
                 <a id="autoUrl" style="display:none;"></a>
             </div>
         </div>
 
 		<div id="test1"></div>
 
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
 <script type="text/javascript">
 var lang = "?lang=" + $("#slctLang").val(),
 eventsUri = "https://api.guildwars2.com/v1/events.json",
 worldNamesUri = "https://api.guildwars2.com/v1/world_names.json",
 mapNamesUri = "https://api.guildwars2.com/v1/map_names.json",
 eventNamesUri = "https://api.guildwars2.com/v1/event_names.json"; 


 var events = {
     Pairs: [],
     Add: function (event) { this.Pairs.push(event); },
     Get: function (id) {
         var result = $.grep(this.Pairs, function (event) { return event.id == id; });
         if (result.length == 0) return '';
         return result[0].name;
     }
 }; 
 
 var eventsEN = {
     Pairs: [],
     Add: function (event) { this.Pairs.push(event); },
     Get: function (id) {
         var result = $.grep(this.Pairs, function (event) { return event.id == id; });
         if (result.length == 0) return '';
         return result[0].name;
     }
 };
 
 function eventsList() {
 	console.log("start");
 	lang = "?lang=" + $("#slctLang").val();
 	/*selected Language*/
 	$.getJSON(eventNamesUri+lang,function(data){
 		$.each(data, function () {
              events.Add(this);
          });
 		
 		/*get english language after first lang is finished*/
 		$.getJSON(eventNamesUri,function(data){
 			$.each(data, function () {
 				eventsEN.Add(this);
         });
 		/*output list after each language has finished loading*/
 		outputList();
 	});
 
 	});
 }
 function outputList(){	
 	$("#test1").empty();
 	i = eventsEN.Pairs.length;
 	while (i--) {
 		var pTag = "<p>";
 		pTag += '<a target="_blank" href="http://wiki.guildwars2.com/wiki/' + eventsEN.Pairs[i].name.substring(0, eventsEN.Pairs[i].name.length - 1) + '">'+ eventsEN.Pairs[i].name.substring(0, eventsEN.Pairs[i].name.length - 1) +'</a> <br />';
 		pTag += '<a target="_blank" href="http://wiki-'+ $('#slctLang').val()+'.guildwars2.com/wiki/' + events.Pairs[i].name.substring(0, events.Pairs[i].name.length - 1) + '">'+ events.Pairs[i].name.substring(0, events.Pairs[i].name.length - 1) +'</a> <br /> </p>';
 		$("#test1").append(pTag);
 	}
 }

 function getURLParameter(name) {
     return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
 }
 </script>	
     </body>
 </html>