Browse Source

Replace T_() by _() for pot generation

Julien VAUBOURG 9 years ago
parent
commit
d7b3aaf910

+ 2 - 2
sources/config.php

@@ -28,7 +28,7 @@ function configure() {
 }
 
 // Gettext function
-function T_($string) {
+function _($string) {
   return gettext($string);
 }
 
@@ -39,7 +39,7 @@ function before($route) {
   );
 
   if(!isset($_SESSION['locale'])) {
-    $locale = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
+    $locale = explode(',', $_SERVER['HTTP_ACCEP_LANGUAGE']);
     $_SESSION['locale'] = strtolower(substr(chop($locale[0]), 0, 2));
   }
 

+ 18 - 18
sources/controller.php

@@ -185,44 +185,44 @@ dispatch_put('/settings', function() {
         }
 
         if(in_array($ssid['wifi_ssid'], $wifi_ssid_uniqueness)) {
-          throw new Exception(T_('All Wifi names must be unique'));
+          throw new Exception(_('All Wifi names must be unique'));
         } else {
           array_push($wifi_ssid_uniqueness, $ssid['wifi_ssid']);
         }
     
         if(in_array($ssid['ip4_nat_prefix'], $ip4_nat_prefix_uniqueness)) {
-          throw new Exception(T_('All IPv4 NAT prefixes must be unique'));
+          throw new Exception(_('All IPv4 NAT prefixes must be unique'));
         } else {
           array_push($ip4_nat_prefix_uniqueness, $ssid['ip4_nat_prefix']);
         }
 
         if($ssid['ip6_net'] != 'none' && in_array($ssid['ip6_net'], $ip6_net_uniqueness)) {
-          throw new Exception(T_('All IPv6 delegated prefixes must be unique'));
+          throw new Exception(_('All IPv6 delegated prefixes must be unique'));
         } else {
           array_push($ip6_net_uniqueness, $ssid['ip6_net']);
         }
 
         if(empty($ssid['wifi_ssid']) || empty($ssid['wifi_passphrase'])) {
-          throw new Exception(T_('Your Wifi Hotspot needs a name and a password'));
+          throw new Exception(_('Your Wifi Hotspot needs a name and a password'));
         }
      
         if($ssid['wifi_secure'] && (strlen($ssid['wifi_passphrase']) < 8 || strlen($ssid['wifi_passphrase']) > 63)) {
-          throw new Exception(T_('Your password must from 8 to 63 characters (WPA2 passphrase)'));
+          throw new Exception(_('Your password must from 8 to 63 characters (WPA2 passphrase)'));
         }
      
         if($ssid['wifi_secure'] && preg_match('/[^[:print:]]/', $ssid['wifi_passphrase'])) {
-          throw new Exception(T_('Only printable ASCII characters are permitted in your password'));
+          throw new Exception(_('Only printable ASCII characters are permitted in your password'));
         }
      
         if(!$wifi_device_exists) {
-          throw new Exception(T_('The wifi antenna interface seems not exist on the system'));
+          throw new Exception(_('The wifi antenna interface seems not exist on the system'));
         }
      
         if($ssid['ip6_net'] != 'none') {
           $ssid['ip6_net'] = ipv6_expanded($ssid['ip6_net']);
       
           if(empty($ssid['ip6_net'])) {
-            throw new Exception(T_('The IPv6 Delegated Prefix format looks bad'));
+            throw new Exception(_('The IPv6 Delegated Prefix format looks bad'));
           }
       
           $ip6_blocs = explode(':', $ssid['ip6_net']);
@@ -236,7 +236,7 @@ dispatch_put('/settings', function() {
           $ssid['ip6_dns0'] = ipv6_expanded($ssid['ip6_dns0']);
      
           if(empty($ssid['ip6_dns0'])) {
-            throw new Exception(T_('The format of the first IPv6 DNS Resolver looks bad'));
+            throw new Exception(_('The format of the first IPv6 DNS Resolver looks bad'));
           }
      
           $ssid['ip6_dns0'] = ipv6_compressed($ssid['ip6_dns0']);
@@ -245,7 +245,7 @@ dispatch_put('/settings', function() {
             $ssid['ip6_dns1'] = ipv6_expanded($ssid['ip6_dns1']);
       
             if(empty($ssid['ip6_dns1'])) {
-               throw new Exception(T_('The format of the second IPv6 DNS Resolver looks bad'));
+               throw new Exception(_('The format of the second IPv6 DNS Resolver looks bad'));
             }
      
             $ssid['ip6_dns1'] = ipv6_compressed($ssid['ip6_dns1']);
@@ -253,25 +253,25 @@ dispatch_put('/settings', function() {
         }
      
         if(inet_pton($ssid['ip4_dns0']) === false) {
-          throw new Exception(T_('The format of the first IPv4 DNS Resolver looks bad'));
+          throw new Exception(_('The format of the first IPv4 DNS Resolver looks bad'));
         }
      
         if(inet_pton($ssid['ip4_dns1']) === false) {
-          throw new Exception(T_('The format of the second IPv4 DNS Resolver looks bad'));
+          throw new Exception(_('The format of the second IPv4 DNS Resolver looks bad'));
         }
      
         if(inet_pton("${ssid['ip4_nat_prefix']}.0") === false) {
-          throw new Exception(T_('The format of the IPv4 NAT Prefix (/24) looks bad : x.x.x expected)'));
+          throw new Exception(_('The format of the IPv4 NAT Prefix (/24) looks bad : x.x.x expected)'));
         }
      
         if(filter_var("${ssid['ip4_nat_prefix']}.0", FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE) !== false) {
-          throw new Exception(T_('The IPv4 NAT Prefix must be from a private range'));
+          throw new Exception(_('The IPv4 NAT Prefix must be from a private range'));
         }
 
         array_push($ssids, $ssid);
       }
     } catch(Exception $e) {
-      flash('error', T_('Hotspot')." $id: ".$e->getMessage().' ('.T_('configuration not updated').').');
+      flash('error', _('Hotspot')." $id: ".$e->getMessage().' ('._('configuration not updated').').');
       goto redirect;
     }
   }
@@ -299,13 +299,13 @@ dispatch_put('/settings', function() {
     $retcode = start_service();
 
     if($retcode == 0) {
-      flash('success', T_('Configuration updated and service successfully reloaded'));
+      flash('success', _('Configuration updated and service successfully reloaded'));
     } else {
-      flash('error', T_('Configuration updated but service reload failed'));
+      flash('error', _('Configuration updated but service reload failed'));
     }
 
   } else {
-      flash('success', T_('Service successfully disabled'));
+      flash('success', _('Service successfully disabled'));
   }
 
   redirect:

+ 1 - 1
sources/i18n/README.md

@@ -25,7 +25,7 @@ mkdir -p sources/i18n/fr_FR/LC_MESSAGES/
 
 Generate the po file:
 ```
-msginit --locale=fr_FR.UTF-8 -i sources/i18n/localization.pot -o sources/i18n/fr_FR/LC_MESSAGES/localization.po
+msginit --locale=fr_FR.UTF-8 --no-translator -i sources/i18n/localization.pot -o sources/i18n/fr_FR/LC_MESSAGES/localization.po
 ```
 
 You can use poedit for translating the po:

+ 19 - 19
sources/views/_ssid.html.php

@@ -1,26 +1,26 @@
 <div class="panel panel-default ssid enabled" <?= $service_enabled == 0 ? 'style="display: none"' : '' ?>>
   <div class="panel-heading">
-    <h3 class="panel-title" data-label="<?= T_("Hotspot") ?>"><?= T_("Hotspot") ?> <?= $ssid['id'] + 1 ?></h3>
+    <h3 class="panel-title" data-label="<?= _("Hotspot") ?>"><?= _("Hotspot") ?> <?= $ssid['id'] + 1 ?></h3>
   </div>
 
   <ul class="nav nav-tabs nav-justified">
-    <li role="presentation" data-tab="wifi" class="active"><a href="#"><?= T_("Wifi") ?></a></li>
-    <li role="presentation" data-tab="ipv6"><a href="#"><?= T_("IPv6") ?></a></li>
-    <li role="presentation" data-tab="ipv4"><a href="#"><?= T_("IPv4") ?></a></li>
+    <li role="presentation" data-tab="wifi" class="active"><a href="#"><?= _("Wifi") ?></a></li>
+    <li role="presentation" data-tab="ipv6"><a href="#"><?= _("IPv6") ?></a></li>
+    <li role="presentation" data-tab="ipv4"><a href="#"><?= _("IPv4") ?></a></li>
   </ul>
 
   <!-- Wifi -->
   <div class="tabs tabwifi">
     <div class="form-group">
-      <label class="col-sm-3 control-label"><?= T_('Name (SSID)') ?></label>
+      <label class="col-sm-3 control-label"><?= _('Name (SSID)') ?></label>
       <div class="col-sm-9">
         <input type="text" class="form-control" name="ssid[<?= $ssid['id'] ?>][wifi_ssid]" placeholder="myNeutralNetwork" value="<?= $ssid['wifi_ssid'] ?>" />
       </div>
     </div>
 
     <div class="form-group">
-      <label for="wifi_secure" class="col-sm-3 control-label"><?= T_('Secure') ?></label>
-      <div class="col-sm-9 input-group-btn" data-toggle="tooltip" data-title="<?= T_('Disabling the Secure Wifi allows everyone to join the hotspot and spy the traffic (but it\'s perfect for a PirateBox)') ?>">
+      <label for="wifi_secure" class="col-sm-3 control-label"><?= _('Secure') ?></label>
+      <div class="col-sm-9 input-group-btn" data-toggle="tooltip" data-title="<?= _('Disabling the Secure Wifi allows everyone to join the hotspot and spy the traffic (but it\'s perfect for a PirateBox)') ?>">
         <div class="input-group">
           <input type="checkbox" class="form-control switch wifi_secure" name="ssid[<?= $ssid['id'] ?>][wifi_secure]" value="1" <?= $ssid['wifi_secure'] == 1 ? 'checked="checked"' : '' ?> />
         </div>
@@ -28,10 +28,10 @@
     </div>
 
     <div class="form-group wifi_passphrase" <?= $ssid['wifi_secure'] == 0 ? 'style="display: none"' : '' ?>>
-      <label class="col-sm-3 control-label"><?= T_('Password (WPA2)') ?></label>
+      <label class="col-sm-3 control-label"><?= _('Password (WPA2)') ?></label>
       <div class="input-group col-sm-9" style="padding: 0 15px">
-        <input type="text" data-toggle="tooltip" data-title="<?= T_('At least 8 characters') ?>" class="form-control" name="ssid[<?= $ssid['id'] ?>][wifi_passphrase]" placeholder="VhegT8oev0jZI" value="<?= $ssid['wifi_passphrase'] ?>" />
-        <a class="btn input-group-addon wifiparty" data-toggle="tooltip" data-title="<?= T_('Show to your friends how to access to your hotspot') ?>"><span class="glyphicon glyphicon-fullscreen"></span></a>
+        <input type="text" data-toggle="tooltip" data-title="<?= _('At least 8 characters') ?>" class="form-control" name="ssid[<?= $ssid['id'] ?>][wifi_passphrase]" placeholder="VhegT8oev0jZI" value="<?= $ssid['wifi_passphrase'] ?>" />
+        <a class="btn input-group-addon wifiparty" data-toggle="tooltip" data-title="<?= _('Show to your friends how to access to your hotspot') ?>"><span class="glyphicon glyphicon-fullscreen"></span></a>
       </div>
     </div>
   </div>
@@ -41,27 +41,27 @@
     <?php if(empty($ssid['ip6_net'])): ?>
       <div class="alert alert-dismissible alert-warning fade in" style="margin: 2px 2px 17px" role="alert">
         <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
-        <strong><?= T_('Notice') ?>:</strong> <?= T_("Currently, your wifi clients don't have IPv6 and it's a very bad thing. Ask your Internet Service Provider an IPv6 delegated prefix, or") ?>
-        <a href="http://db.ffdn.org" class="alert-link"><?= T_('change providers') ?></a>!
+        <strong><?= _('Notice') ?>:</strong> <?= _("Currently, your wifi clients don't have IPv6 and it's a very bad thing. Ask your Internet Service Provider an IPv6 delegated prefix, or") ?>
+        <a href="http://db.ffdn.org" class="alert-link"><?= _('change providers') ?></a>!
       </div>
     <?php endif; ?>
 
     <div class="form-group">
-      <label class="col-sm-3 control-label"><?= T_('Delegated prefix') ?></label>
+      <label class="col-sm-3 control-label"><?= _('Delegated prefix') ?></label>
       <div class="col-sm-9">
         <input type="text" class="form-control" name="ssid[<?= $ssid['id'] ?>][ip6_net]" placeholder="2001:db8:42::" value="<?= $ssid['ip6_net'] ?>" />
       </div>
     </div>
 
     <div class="form-group">
-      <label class="col-sm-3 control-label"><?= T_('First DNS resolver') ?></label>
+      <label class="col-sm-3 control-label"><?= _('First DNS resolver') ?></label>
       <div class="col-sm-9">
         <input type="text" class="form-control" name="ssid[<?= $ssid['id'] ?>][ip6_dns0]" placeholder="2001:913::8" value="<?= $ssid['ip6_dns0'] ?>" />
       </div>
     </div>
 
     <div class="form-group">
-      <label class="col-sm-3 control-label"><?= T_('Second DNS resolver') ?></label>
+      <label class="col-sm-3 control-label"><?= _('Second DNS resolver') ?></label>
       <div class="col-sm-9">
         <input type="text" class="form-control" name="ssid[<?= $ssid['id'] ?>][ip6_dns1]" placeholder="2001:910:800::40" value="<?= $ssid['ip6_dns1'] ?>" />
       </div>
@@ -71,21 +71,21 @@
   <!-- IPv4 -->
   <div class="tabs tabipv4" style="display: none">
     <div class="form-group">
-      <label class="col-sm-3 control-label"><?= T_('NAT prefix (/24)') ?></label>
+      <label class="col-sm-3 control-label"><?= _('NAT prefix (/24)') ?></label>
       <div class="col-sm-9">
         <input type="text" class="form-control" name="ssid[<?= $ssid['id'] ?>][ip4_nat_prefix]" placeholder="10.0.242" value="<?= $ssid['ip4_nat_prefix'] ?>" />
       </div>
     </div>
 
     <div class="form-group">
-      <label class="col-sm-3 control-label"><?= T_('First DNS resolver') ?></label>
+      <label class="col-sm-3 control-label"><?= _('First DNS resolver') ?></label>
       <div class="col-sm-9">
         <input type="text" class="form-control" name="ssid[<?= $ssid['id'] ?>][ip4_dns0]" placeholder="80.67.188.188" value="<?= $ssid['ip4_dns0'] ?>" />
       </div>
     </div>
 
     <div class="form-group">
-      <label class="col-sm-3 control-label"><?= T_('Second DNS resolver') ?></label>
+      <label class="col-sm-3 control-label"><?= _('Second DNS resolver') ?></label>
       <div class="col-sm-9">
         <input type="text" class="form-control" name="ssid[<?= $ssid['id'] ?>][ip4_dns1]" placeholder="80.67.169.12" value="<?= $ssid['ip4_dns1'] ?>" />
       </div>
@@ -93,7 +93,7 @@
   </div>
 
   <div class="deletessid" style="display: none">
-    <button type="button" class="btn btn-danger"><?= T_("Delete") ?></button>
+    <button type="button" class="btn btn-danger"><?= _("Delete") ?></button>
   </div>
 
   <div class="wifiparty_passphrase"><?php

+ 4 - 4
sources/views/layout.html.php

@@ -24,7 +24,7 @@
 <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
 <!--[if gt IE 8]><!--> <html class="no-js" lang="<?= $locale ?>"> <!--<![endif]-->
 <head>
-  <title><?= T_("Wifi Hotspot") ?><?php isset($title) ? " | $title" : '' ?></title>
+  <title><?= _("Wifi Hotspot") ?><?php isset($title) ? " | $title" : '' ?></title>
 
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width">
@@ -46,12 +46,12 @@
     <?php if(isset($flash['error'])): ?>
       <div class="alert alert-dismissible alert-danger fade in" style="margin-top: 20px" role="alert">
         <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
-        <strong><?= T_('Error') ?>:</strong> <?= $flash['error'] ?>
+        <strong><?= _('Error') ?>:</strong> <?= $flash['error'] ?>
       </div>
     <?php elseif(isset($flash['notice'])): ?>
       <div class="alert alert-dismissible alert-info fade in" style="margin-top: 20px" role="alert">
         <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
-        <strong><?= T_('Notice') ?>:</strong> <?= $flash['notice'] ?>
+        <strong><?= _('Notice') ?>:</strong> <?= $flash['notice'] ?>
       </div>
     <?php elseif(isset($flash['success'])): ?>
       <div class="alert alert-dismissible alert-success fade in" style="margin-top: 20px" role="alert">
@@ -63,7 +63,7 @@
     <?= $content?>
 
     <hr />
-    <div id="github"><a href="https://github.com/labriqueinternet/hotspot_ynh"><?= T_('Any problem? Contribute!') ?></a> - AGPL 3.0</div>
+    <div id="github"><a href="https://github.com/labriqueinternet/hotspot_ynh"><?= _('Any problem? Contribute!') ?></a> - AGPL 3.0</div>
   </div>
 </body>
 

+ 13 - 13
sources/views/settings.html.php

@@ -34,14 +34,14 @@
   </div>
 </div>
 
-<h2><?= T_("Wifi Hotspot Configuration") ?></h2>
+<h2><?= _("Wifi Hotspot Configuration") ?></h2>
 <?php if($faststatus): ?>
-  <span class="label label-success" data-toggle="tooltip" data-title="<?= T_('This is a fast status. Click on More details to show the complete status.') ?>"><?= T_('Running') ?></span>
+  <span class="label label-success" data-toggle="tooltip" data-title="<?= _('This is a fast status. Click on More details to show the complete status.') ?>"><?= _('Running') ?></span>
 <?php else: ?>
-  <span class="label label-danger" data-toggle="tooltip" data-title="<?= T_('This is a fast status. Click on More details to show the complete status.') ?>"><?= T_('Not Running') ?></span>
+  <span class="label label-danger" data-toggle="tooltip" data-title="<?= _('This is a fast status. Click on More details to show the complete status.') ?>"><?= _('Not Running') ?></span>
 <?php endif; ?>
 
- &nbsp; <img src="public/img/loading.gif" id="status-loading" alt="Loading..." /><a href="#" id="statusbtn" data-toggle="tooltip" data-title="<?= T_('Loading complete status may take a few minutes. Be patient.') ?>"><?= T_('More details') ?></a>
+ &nbsp; <img src="public/img/loading.gif" id="status-loading" alt="Loading..." /><a href="#" id="statusbtn" data-toggle="tooltip" data-title="<?= _('Loading complete status may take a few minutes. Be patient.') ?>"><?= _('More details') ?></a>
 
 <div id="status" class="alert alert-dismissible alert-info fade in" style="margin-top: 10px" role="alert">
   <button type="button" class="close"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
@@ -57,12 +57,12 @@
 
       <div class="panel panel-default">
         <div class="panel-heading">
-          <h3 class="panel-title"><?= T_("Service") ?></h3>
+          <h3 class="panel-title"><?= _("Service") ?></h3>
         </div>
 
         <div style="padding: 14px 14px 0 10px">
           <div class="form-group">
-            <label for="service_enabled" class="col-sm-3 control-label"><?= T_('Hotspot Enabled') ?></label>
+            <label for="service_enabled" class="col-sm-3 control-label"><?= _('Hotspot Enabled') ?></label>
             <div class="col-sm-9 input-group-btn">
               <div class="input-group">
                 <input type="checkbox" class="form-control switch" name="service_enabled" id="service_enabled" value="1" <?= $service_enabled == 1 ? 'checked="checked"' : '' ?> />
@@ -70,7 +70,7 @@
             </div>
           </div>
           <div class="form-group">
-            <label for="wifi_device" class="col-sm-3 control-label"><?= T_('Device') ?></label>
+            <label for="wifi_device" class="col-sm-3 control-label"><?= _('Device') ?></label>
             <div class="col-sm-9 input-group-btn">
               <div class="input-group">
                   <input type="text" name="wifi_device" id="wifi_device" value="<?= $wifi_device ?>" style="display: none" />
@@ -82,7 +82,7 @@
             </div>
           </div>
           <div class="form-group">
-            <label class="col-sm-3 control-label"><?= T_('Channel') ?></label>
+            <label class="col-sm-3 control-label"><?= _('Channel') ?></label>
             <div class="col-sm-9 input-group-btn">
               <div class="input-group dropdownmenu">
                   <input type="text" name="wifi_channel" value="<?= $wifi_channel ?>" style="display: none" />
@@ -113,21 +113,21 @@
       <?php endforeach; ?>
       </div>
 
-      <button id="newssid" type="button" class="btn btn-success"><?= T_("Add a hotspot") ?> <span class="badge">0</span></button>
+      <button id="newssid" type="button" class="btn btn-success"><?= _("Add a hotspot") ?> <span class="badge">0</span></button>
 
       <div class="form-group">
         <div style="text-align: center">
 <?php if($is_connected_through_hotspot): ?>
           <div class="alert alert-dismissible alert-warning fade in" role="alert" id="saveconfirmation">
-            <strong><?= T_('Notice') ?>:</strong> <?= T_("You are currently connected through the wifi hotspot. Please, confirm the reloading, wait for the wifi disconnect/reconnect and go back here to check that everything is okay.") ?>
+            <strong><?= _('Notice') ?>:</strong> <?= _("You are currently connected through the wifi hotspot. Please, confirm the reloading, wait for the wifi disconnect/reconnect and go back here to check that everything is okay.") ?>
             <div id="confirm">
-              <button type="submit" class="btn btn-default" data-toggle="tooltip" id="save" data-title="<?= T_('Reloading may take a few minutes. Be patient.') ?>"><?= T_('Confirm') ?></button> <img src="public/img/loading.gif" id="save-loading" alt="Loading..." />
+              <button type="submit" class="btn btn-default" data-toggle="tooltip" id="save" data-title="<?= _('Reloading may take a few minutes. Be patient.') ?>"><?= _('Confirm') ?></button> <img src="public/img/loading.gif" id="save-loading" alt="Loading..." />
             </div>
           </div>
 
-          <button type="button" class="btn btn-default" id="saveconfirm"><?= T_('Save and reload') ?></button>
+          <button type="button" class="btn btn-default" id="saveconfirm"><?= _('Save and reload') ?></button>
 <?php else: ?>
-          <button type="submit" class="btn btn-default" data-toggle="tooltip" id="save" data-title="<?= T_('Reloading may take a few minutes. Be patient.') ?>"><?= T_('Save and reload') ?></button> <img src="public/img/loading.gif" id="save-loading" alt="Loading..." />
+          <button type="submit" class="btn btn-default" data-toggle="tooltip" id="save" data-title="<?= _('Reloading may take a few minutes. Be patient.') ?>"><?= _('Save and reload') ?></button> <img src="public/img/loading.gif" id="save-loading" alt="Loading..." />
 <?php endif; ?>
         </div>
       </div>