From 6ba05cdbbb7d740d3c80f54c379b344cf0e17737 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 4 Jun 2019 20:03:50 -0500 Subject: [PATCH] Enable menu translation (#10298) And better translation support for sensors, not complete --- LibreNMS/Device/Sensor.php | 2 +- LibreNMS/Device/WirelessSensor.php | 139 +++----- app/Models/WirelessSensor.php | 4 +- .../html/pages/device/entphysical.inc.php | 2 +- includes/html/pages/device/wireless.inc.php | 11 +- includes/rewrites.php | 40 --- resources/lang/en/sensors.php | 169 ++++++++++ resources/lang/en/wireless.php | 110 +++++++ resources/views/layouts/menu.blade.php | 311 +++++++++++++----- 9 files changed, 556 insertions(+), 232 deletions(-) create mode 100644 resources/lang/en/sensors.php create mode 100644 resources/lang/en/wireless.php diff --git a/LibreNMS/Device/Sensor.php b/LibreNMS/Device/Sensor.php index 538cede8c1..8c4b655ce1 100644 --- a/LibreNMS/Device/Sensor.php +++ b/LibreNMS/Device/Sensor.php @@ -617,7 +617,7 @@ class Sensor implements DiscoveryModule, PollerModule foreach ($sensors as $sensor) { $sensor_value = $data[$sensor['sensor_id']]; - echo " {$sensor['sensor_descr']}: $sensor_value {$types[$sensor['sensor_class']]['unit']}\n"; + echo " {$sensor['sensor_descr']}: $sensor_value " . __('sensors.' . $sensor['sensor_class'] . '.unit') . PHP_EOL; // update rrd and database $rrd_name = array( diff --git a/LibreNMS/Device/WirelessSensor.php b/LibreNMS/Device/WirelessSensor.php index e2b26f45f0..7531af5511 100644 --- a/LibreNMS/Device/WirelessSensor.php +++ b/LibreNMS/Device/WirelessSensor.php @@ -129,125 +129,68 @@ class WirelessSensor extends Sensor */ public static function getTypes($valid = false, $device_id = null) { - // Add new types here + // Add new types here translations/descriptions/units in resources/lang//wireless.php // FIXME I'm really bad with icons, someone please help! - static $types = array( - 'ap-count' => array( - 'short' => 'APs', - 'long' => 'AP Count', - 'unit' => '', + static $types = [ + 'ap-count' => [ 'icon' => 'wifi', - ), - 'clients' => array( - 'short' => 'Clients', - 'long' => 'Client Count', - 'unit' => '', + ], + 'clients' => [ 'icon' => 'tablet', - ), - 'quality' => array( - 'short' => 'Quality', - 'long' => 'Quality', - 'unit' => '%', + ], + 'quality' => [ 'icon' => 'feed', - ), - 'capacity' => array( - 'short' => 'Capacity', - 'long' => 'Capacity', - 'unit' => '%', + ], + 'capacity' => [ 'icon' => 'feed', - ), - 'utilization' => array( - 'short' => 'Utilization', - 'long' => 'utilization', - 'unit' => '%', + ], + 'utilization' => [ 'icon' => 'percent', - ), - 'rate' => array( - 'short' => 'Rate', - 'long' => 'TX/RX Rate', - 'unit' => 'bps', + ], + 'rate' => [ 'icon' => 'tachometer', - ), - 'ccq' => array( - 'short' => 'CCQ', - 'long' => 'Client Connection Quality', - 'unit' => '%', + ], + 'ccq' => [ 'icon' => 'wifi', - ), - 'snr' => array( - 'short' => 'SNR', - 'long' => 'Signal-to-Noise Ratio', - 'unit' => 'dB', + ], + 'snr' => [ 'icon' => 'signal', - ), - 'ssr' => array( - 'short' => 'SSR', - 'long' => 'Signal Strength Ratio', - 'unit' => 'dB', + ], + 'ssr' => [ 'icon' => 'signal', - ), - 'mse' => array( - 'short' => 'MSE', - 'long' => 'Mean Square Error', - 'unit' => 'dB', + ], + 'mse' => [ 'icon' => 'signal', - ), - 'xpi' => array( - 'short' => 'XPI', - 'long' => 'Cross Polar Interference', - 'unit' => 'dB', + ], + 'xpi' => [ 'icon' => 'signal', - ), - 'rssi' => array( - 'short' => 'RSSI', - 'long' => 'Received Signal Strength Indicator', - 'unit' => 'dBm', + ], + 'rssi' => [ 'icon' => 'signal', - ), - 'power' => array( - 'short' => 'Power/Signal', - 'long' => 'TX/RX Power or Signal', - 'unit' => 'dBm', + ], + 'power' => [ 'icon' => 'bolt', - ), - 'noise-floor' => array( - 'short' => 'Noise Floor', - 'long' => 'Noise Floor', - 'unit' => 'dBm/Hz', + ], + 'noise-floor' => [ 'icon' => 'signal', - ), - 'errors' => array( - 'short' => 'Errors', - 'long' => 'Errors', - 'unit' => '', + ], + 'errors' => [ 'icon' => 'exclamation-triangle', 'type' => 'counter', - ), - 'error-ratio' => array( - 'short' => 'Error Ratio', - 'long' => 'Bit/Packet Error Ratio', - 'unit' => '%', + ], + 'error-ratio' => [ 'icon' => 'exclamation-triangle', - ), - 'error-rate' => array( - 'short' => 'BER', - 'long' => 'Bit Error Rate', - 'unit' => 'bps', + ], + 'error-rate' => [ 'icon' => 'exclamation-triangle', - ), - 'frequency' => array( - 'short' => 'Frequency', - 'long' => 'Frequency', - 'unit' => 'MHz', + ], + 'frequency' => [ 'icon' => 'line-chart', - ), - 'distance' => array( - 'short' => 'Distance', - 'long' => 'Distance', - 'unit' => 'km', + ], + 'distance' => [ 'icon' => 'space-shuttle', - ), - ); + ], + ]; if ($valid) { $sql = 'SELECT `sensor_class` FROM `wireless_sensors`'; diff --git a/app/Models/WirelessSensor.php b/app/Models/WirelessSensor.php index 5e33cf2e69..87b98b1dbf 100644 --- a/app/Models/WirelessSensor.php +++ b/app/Models/WirelessSensor.php @@ -34,9 +34,7 @@ class WirelessSensor extends DeviceRelatedModel public function classDescr() { - return collect(collect(\LibreNMS\Device\WirelessSensor::getTypes()) - ->get($this->sensor_class, [])) - ->get('short', ucwords(str_replace('_', ' ', $this->sensor_class))); + return __("wireless.$this->sensor_class.short"); } public function icon() diff --git a/includes/html/pages/device/entphysical.inc.php b/includes/html/pages/device/entphysical.inc.php index 89c1659528..b3b3a16429 100644 --- a/includes/html/pages/device/entphysical.inc.php +++ b/includes/html/pages/device/entphysical.inc.php @@ -58,7 +58,7 @@ function printEntPhysical($device, $ent, $level, $class) } if ($ent['entPhysicalClass'] == 'sensor' && isset($sensor)) { - echo ' ('.trim($sensor['sensor_current'] . ' ' . get_units_from_sensor($sensor)) . ')'; + echo ' (' . trim($sensor['sensor_current'] . ' ' . __('sensors.' . $sensor['sensor_class'] . '.unit')) . ')'; } if (isset($link)) { diff --git a/includes/html/pages/device/wireless.inc.php b/includes/html/pages/device/wireless.inc.php index b0eee9b678..c6be51c799 100644 --- a/includes/html/pages/device/wireless.inc.php +++ b/includes/html/pages/device/wireless.inc.php @@ -38,7 +38,7 @@ foreach ($datas as $type) { } echo '>'; - echo generate_link($types[$type]['short'], $wireless_link_array, array('metric' => $type)); + echo generate_link(__("wireless.$type.short"), $wireless_link_array, ['metric' => $type]); echo ''; } @@ -47,9 +47,10 @@ print_optionbar_end(); if ($vars['metric'] == 'overview') { foreach ($datas as $type) { - $text = $types[$type]['long']; - if (!empty($types[$type]['unit'])) { - $text .= ' (' . $types[$type]['unit'] . ')'; + $text = __("wireless.$type.long"); + $unit = __("wireless.$type.unit"); + if (!empty($unit)) { + $text .= " ($unit)"; } $graph_title = generate_link($text, $wireless_link_array, array('metric' => $type)); @@ -58,7 +59,7 @@ if ($vars['metric'] == 'overview') { include $config['install_dir'] . '/includes/html/print-device-graph.php'; } } elseif (isset($types[$vars['metric']])) { - $unit = $types[$vars['metric']]['unit']; + $unit = __('wireless.' . $vars['metric'] . '.unit'); $factor = 1; if ($unit == 'MHz') { $unit = 'Hz'; diff --git a/includes/rewrites.php b/includes/rewrites.php index 7aa4bfd0a7..9c196f836d 100644 --- a/includes/rewrites.php +++ b/includes/rewrites.php @@ -1676,46 +1676,6 @@ function return_number($value) return $value; } -function get_units_from_sensor($sensor) -{ - switch ($sensor['sensor_class']) { - case 'airflow': - return 'cfm'; - case 'current': - return 'A'; - case 'dbm': - case 'signal': - return 'dBm'; - case 'fanspeed': - return 'rpm'; - case 'frequency': - return 'Hz'; - case 'charge': - case 'humidity': - case 'load': - return '%'; - case 'cooling': - case 'power': - return 'W'; - case 'power_consumed': - return 'kWh'; - case 'pressure': - return 'kPa'; - case 'runtime': - return 'Min'; - case 'snr': - return 'SNR'; - case 'state': - return '#'; - case 'temperature': - return '°C'; - case 'voltage': - return 'V'; - default: - return ''; - } -} - function parse_entity_state($state, $value) { $data = array( diff --git a/resources/lang/en/sensors.php b/resources/lang/en/sensors.php new file mode 100644 index 0000000000..8ac971bc65 --- /dev/null +++ b/resources/lang/en/sensors.php @@ -0,0 +1,169 @@ + [ + 'short' => 'Airflow', + 'long' => 'Airflow', + 'unit' => 'cfm', + 'unit_long' => 'Cubic Feet per Minute', + ], + 'ber' => [ + 'short' => 'BER', + 'long' => 'Bit Error Rate', + 'unit' => '', + 'unit_long' => '', + ], + 'charge' => [ + 'short' => 'Charge', + 'long' => 'Charge Percent', + 'unit' => '%', + 'unit_long' => 'Percent', + ], + 'chromatic_dispersion' => [ + 'short' => 'Chromatic Dispersion', + 'long' => 'Chromatic Dispersion', + 'unit' => 'ps/nm/km', + 'unit_long' => 'Picoseconds per Nanometer per Kilometer', + ], + 'cooling' => [ + 'short' => 'Cooling', + 'long' => '', + 'unit' => 'W', + 'unit_long' => 'Watts', + ], + 'count' => [ + 'short' => 'Count', + 'long' => 'Count', + 'unit' => '', + 'unit_long' => '', + ], + 'current' => [ + 'short' => 'Current', + 'long' => 'Current', + 'unit' => 'A', + 'unit_long' => 'Amperes', + ], + 'dbm' => [ + 'short' => 'dBm', + 'long' => 'dBm', + 'unit' => 'dBm', + 'unit_long' => 'Decibal-Milliwatts', + ], + 'delay' => [ + 'short' => 'Delay', + 'long' => 'Delay', + 'unit' => 's', + 'unit_long' => 'Seconds', + ], + 'eer' => [ + 'short' => 'EER', + 'long' => 'Energy Efficient Ratio', + 'unit' => '', + 'unit_long' => '', + ], + 'fanspeed' => [ + 'short' => 'Fanspeed', + 'long' => 'Fan Speed', + 'unit' => 'RPM', + 'unit_long' => 'Rotations per Minute', + ], + 'frequency' => [ + 'short' => 'Frequency', + 'long' => 'Frequency', + 'unit' => 'Hz', + 'unit_long' => 'Hertz', + ], + 'humidity' => [ + 'short' => 'Humidity', + 'long' => 'Humidity Percent', + 'unit' => '%', + 'unit_long' => 'Percent', + ], + 'load' => [ + 'short' => 'Load', + 'long' => 'Load Percent', + 'unit' => '%', + 'unit_long' => 'Percent', + ], + 'power' => [ + 'short' => 'Power', + 'long' => 'Power', + 'unit' => 'W', + 'unit_long' => 'Watts', + ], + 'power_consumed' => [ + 'short' => 'Power Consumed', + 'long' => 'Power Consumed', + 'unit' => 'kWh', + 'unit_long' => 'Killowatt-Hours', + ], + 'power_factor' => [ + 'short' => 'Power Factor', + 'long' => 'Power Factor', + 'unit' => '', + 'unit_long' => '', + ], + 'pressure' => [ + 'short' => 'Pressure', + 'long' => 'Pressure', + 'unit' => 'kPa', + 'unit_long' => 'Kilopascals', + ], + 'quality_factor' => [ + 'short' => 'Quality Factor', + 'long' => 'Quality Factor', + 'unit' => '', + 'unit_long' => '', + ], + 'runtime' => [ + 'short' => 'Runtime', + 'long' => 'Runtime', + 'unit' => 'Min', + 'unit_long' => 'Minutes', + ], + 'signal' => [ + 'short' => 'Signal', + 'long' => 'Signal', + 'unit' => 'dBm', + 'unit_long' => 'Decibal-Milliwatts', + ], + 'snr' => [ + 'short' => 'SNR', + 'long' => 'Signal to Noise Ratio', + 'unit' => 'dB', + 'unit_long' => 'Decibels', + ], + 'state' => [ + 'short' => 'State', + 'long' => 'State', + 'unit' => '', + ], + 'temperature' => [ + 'short' => 'Temperature', + 'long' => 'Temperature', + 'unit' => '°C', + 'unit_long' => '° Celsius', + ], + 'voltage' => [ + 'short' => 'Voltage', + 'long' => 'voltage', + 'unit' => 'V', + 'unit_long' => 'Volts', + ], + 'waterflow' => [ + 'short' => 'Waterflow', + 'long' => 'Water Flow', + 'unit' => 'l/m', + 'unit_long' => 'Liters Per Minute', + ], +]; diff --git a/resources/lang/en/wireless.php b/resources/lang/en/wireless.php new file mode 100644 index 0000000000..ab2330357b --- /dev/null +++ b/resources/lang/en/wireless.php @@ -0,0 +1,110 @@ + [ + 'short' => 'APs', + 'long' => 'AP Count', + 'unit' => '', + ], + 'clients' => [ + 'short' => 'Clients', + 'long' => 'Client Count', + 'unit' => '', + ], + 'capacity' => [ + 'short' => 'Capacity', + 'long' => 'Capacity', + 'unit' => '%', + ], + 'ccq' => [ + 'short' => 'CCQ', + 'long' => 'Client Connection Quality', + 'unit' => '%', + ], + 'errors' => [ + 'short' => 'Errors', + 'long' => 'Error Count', + 'unit' => '', + ], + 'error-ratio' => [ + 'short' => 'Error Ratio', + 'long' => 'Bit/Packet Error Ratio', + 'unit' => '%', + ], + 'error-rate' => [ + 'short' => 'BER', + 'long' => 'Bit Error Rate', + 'unit' => 'bps', + ], + 'frequency' => [ + 'short' => 'Frequency', + 'long' => 'Frequency', + 'unit' => 'MHz', + ], + 'distance' => [ + 'short' => 'Distance', + 'long' => 'Distance', + 'unit' => 'km', + ], + 'mse' => [ + 'short' => 'MSE', + 'long' => 'Mean Square Error', + 'unit' => 'dB', + ], + 'noise-floor' => [ + 'short' => 'Noise Floor', + 'long' => 'Noise Floor', + 'unit' => 'dBm/Hz', + ], + 'power' => [ + 'short' => 'Power/Signal', + 'long' => 'TX/RX Power or Signal', + 'unit' => 'dBm', + ], + 'quality' => [ + 'short' => 'Quality', + 'long' => 'Quality', + 'unit' => '%', + ], + 'rate' => [ + 'short' => 'Rate', + 'long' => 'TX/RX Rate', + 'unit' => 'bps', + ], + 'rssi' => [ + 'short' => 'RSSI', + 'long' => 'Received Signal Strength Indicator', + 'unit' => 'dBm', + ], + 'snr' => [ + 'short' => 'SNR', + 'long' => 'Signal-to-Noise Ratio', + 'unit' => 'dB', + ], + 'ssr' => [ + 'short' => 'SSR', + 'long' => 'Signal Strength Ratio', + 'unit' => 'dB', + ], + 'utilization' => [ + 'short' => 'Utilization', + 'long' => 'utilization', + 'unit' => '%', + ], + 'xpi' => [ + 'short' => 'XPI', + 'long' => 'Cross Polar Interference', + 'unit' => 'dB', + ], + +]; diff --git a/resources/views/layouts/menu.blade.php b/resources/views/layouts/menu.blade.php index 46604e7c24..2cea9a02e5 100644 --- a/resources/views/layouts/menu.blade.php +++ b/resources/views/layouts/menu.blade.php @@ -2,7 +2,7 @@