Skip to content

Commit

Permalink
improve translation to en for other languages than de
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianhegge committed Apr 23, 2020
1 parent 4edf424 commit eee67fc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
13 changes: 9 additions & 4 deletions geo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
header('Access-Control-Allow-Origin: *');
header('Content-type:application/json;charset=utf-8');

$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if($lang != 'de'){
$lang = 'en';
}

if(isset($_GET['ip'])){
$ip = $_GET['ip'];
$response = get_web_page('http://ip-api.com/json/'.$ip.'?fields=19187&lang=de');
$response = get_web_page('http://ip-api.com/json/'.$ip.'?fields=19187&lang='.$lang);
print_r($response);
}
else {
Expand All @@ -20,7 +25,7 @@
$ret_obj['country_code'] = (String)getenv('MM_COUNTRY_CODE_CITY_DB');
$ret_obj['status'] = 'success';
$ret_obj['ip_network'] = (String)getenv('MM_ASN_DB_NETWORK');
$ret_obj['country'] = locale_get_display_region('-'.$ret_obj['country_code'], 'de');
$ret_obj['country'] = locale_get_display_region('-'.$ret_obj['country_code'], $lang);
$ret_obj['city'] = (String)getenv('MM_CITY_NAME');
$ret_obj['zip'] = '';
$ret_obj['lat'] = (Float)getenv('MM_LATITUDE');
Expand All @@ -33,7 +38,7 @@
$ret_obj['as_organisation'] = $org_response_obj->data[0]->name;
$ret_obj['as_country_code'] = $org_response_obj->data[0]->country;
if(isset($org_response_obj->data[0]->country) && strlen($org_response_obj->data[0]->country) > 0){
$ret_obj['as_country'] = locale_get_display_region('-'.$org_response_obj->data[0]->country, 'de');
$ret_obj['as_country'] = locale_get_display_region('-'.$org_response_obj->data[0]->country, $lang);
}
else{
$ret_obj['as_country'] = '';
Expand Down Expand Up @@ -69,4 +74,4 @@ function get_web_page($url) {

return $content;
}
?>
?>
14 changes: 10 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
if($lang != 'de'){
$lang = 'en';
}
if($lang == substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)){
$language_string = locale_get_display_language(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2), substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));
}
else{
$language_string = locale_get_display_language(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2), substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2))." (".locale_get_display_language(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2), $lang).")";
}

if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'curl')!==false){
print($_SERVER['REMOTE_ADDR']."\n");
Expand Down Expand Up @@ -81,19 +87,19 @@
</tr>
<tr>
<th scope="row"><?php print(($lang == 'de')?('Geräte-Typ'):('Device type')); ?>:</th>
<td id="content-os"><?php print(($lang == 'de')?($browscap_translation['device_type'][$browscap['device_type']]):($browscap['device_type'])); ?></td>
<td id="content-device-type"><?php print(($lang == 'de')?($browscap_translation['device_type'][$browscap['device_type']]):($browscap['device_type'])); ?></td>
</tr>
<tr>
<th scope="row"><?php print(($lang == 'de')?('Betriebssystem'):('Operating system')); ?>:</th>
<td id="content-os"><?php print($browscap['platform']); ?></td>
</tr>
<tr>
<th scope="row">Browser:</th>
<td id="content-os"><?php print($browscap['browser']); ?></td>
<td id="content-browser"><?php print($browscap['browser']); ?></td>
</tr>
<tr>
<th scope="row"><?php print(($lang == 'de')?('Sprache'):('Language')); ?>:</th>
<td id="content-os"><?php print(locale_get_display_language(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2), substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2))); ?> <img src="flags/<?php print(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)); ?>.svg" width="20" height="16" style="margin-bottom: 2px;"></td>
<td id="content-language"><?php print($language_string); ?></td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -173,7 +179,7 @@
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="card mt-4">
<div class="card-header card-header-no-border text-center">
&copy; Sebastian Hegge &middot; <a href="https://heg.ge/impressum" target="_blank"><?php print(($lang == 'de')?('Impressum & Datenschutz'):('Imprint & Privacy policy')); ?></a> &middot; <a href="https://github.com/sebastianhegge/iptest" target="_blank"><?php print(($lang == 'de')?('Quellcode auf GitHub'):('Source on GitHub')); ?></a> &middot; v2.2
&copy; Sebastian Hegge &middot; <a href="https://heg.ge/impressum" target="_blank"><?php print(($lang == 'de')?('Impressum & Datenschutz'):('Imprint & Privacy policy')); ?></a> &middot; <a href="https://github.com/sebastianhegge/iptest" target="_blank"><?php print(($lang == 'de')?('Quellcode auf GitHub'):('Source on GitHub')); ?></a> &middot; v2.2.1
</div>
</div>
</div>
Expand Down
7 changes: 6 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,17 @@ $(document).ready(function(){
};

function get_dns_data() {
var lang = navigator.language || navigator.userLanguage;
lang = lang.substr(0,2);
if(lang != 'de'){
lang == 'en';
}
var random_string = '';
for (i = 0; i < 32; i++) {
random_string += '0123456789abcdefghijklmnopqrstuvwxyz'[Math.round(Math.random() * 35)]
}
$.ajax({
url: location.protocol + '//' + random_string + '.edns.ip-api.com/json?lang=de',
url: location.protocol + '//' + random_string + '.edns.ip-api.com/json?lang=' + lang,
type: 'GET',
crossDomain: true,
success: function(data){
Expand Down

0 comments on commit eee67fc

Please sign in to comment.