From d7d9f40ddb7c39dc21c42a971c45e6942bc93733 Mon Sep 17 00:00:00 2001 From: Frederic Bardin Date: Sun, 7 Jun 2015 12:33:01 +0200 Subject: [PATCH] v1.2 Add multi lang support --- .gitignore | 2 +- LICENSE => LICENCE.txt | 10 +++--- README.md | 3 +- include/config.tpl.php | 4 ++- include/functions.php | 6 ++-- include/hueapi.php | 3 ++ include/huecolor.php | 4 +-- include/lights_details.php | 40 +++++++++++------------ include/scenes.php | 2 +- include/scenes_details.php | 8 ++--- include/text_en.json | 65 ++++++++++++++++++++++++++++++++++++++ include/text_fr.json | 65 ++++++++++++++++++++++++++++++++++++++ index.php | 17 +++++++--- js/functions.js | 4 +-- js/lights.js | 45 +++++++++++++------------- js/scenes.js | 4 +-- 16 files changed, 213 insertions(+), 69 deletions(-) rename LICENSE => LICENCE.txt (88%) create mode 100644 include/text_en.json create mode 100644 include/text_fr.json diff --git a/.gitignore b/.gitignore index 763b3ae..22cfc56 100644 --- a/.gitignore +++ b/.gitignore @@ -18,9 +18,9 @@ $RECYCLE.BIN/ *.lnk # other -.gitignore *.zip *.txt +!LICENCE.txt *.swp include/config.php jquery-ui_FULL diff --git a/LICENSE b/LICENCE.txt similarity index 88% rename from LICENSE rename to LICENCE.txt index 5093088..acb64a4 100644 --- a/LICENSE +++ b/LICENCE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 FredBardin +Copyright (c) 2015 Frederic Bardin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -9,14 +9,14 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index c817f1b..30c29d5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Php web interface to manage Philips Hue lights in a lan. ## Installation 1. Copy 'phpMyHue' directory and its content in your web server. 2. Rename 'include/config.tpl.php' as 'include/config.php' -3. Edit 'include/config.php' and put correct values for '$bridgeip' and '$username'. +3. Edit 'include/config.php' and put correct values for '$bridgeip', '$username' and, if needed, for '$lang' (in reference to an exiting 'text_.json' file). brigeip is the ip address of your hue bridge in your lan. username is a registered user in your hue bridge (cf http://www.developers.meethue.com/documentation/api-core-concepts). @@ -17,6 +17,7 @@ username is a registered user in your hue bridge (cf http://www.developers.meeth * Run effects * Hue API class available in 'include/hueapi.php' (see comments in file) * Fully touch device compatible +* Multi Lang * ... ![screenshot](screen1_pmh.jpg) diff --git a/include/config.tpl.php b/include/config.tpl.php index 4ee0892..2aa9d41 100644 --- a/include/config.tpl.php +++ b/include/config.tpl.php @@ -9,5 +9,7 @@ $appname = "phpMyHue"; // optional -$apiurl="http://$bridgeip/api/$username"; +$apiurl = "http://$bridgeip/api/$username"; + +$lang = "en"; ?> diff --git a/include/functions.php b/include/functions.php index 44a7368..65a64fa 100644 --- a/include/functions.php +++ b/include/functions.php @@ -79,14 +79,14 @@ function display_light_row($prefid,$lnum,$gnum,$cbpos="E",$brislider=false){ // brislider : optional, if true display a brightness slider at the end of a selected row // ------------------------------------------------------------- function display_lights_groups($prefid="",$cbpos="E",$brislider=false){ - global $HueAPI; + global $HueAPI, $trs; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; -echo ""; echo ""; echo "
"; if ($cbpos == "B"){display_lg_checkbox($prefid,"all");} - echo ""; + echo ""; echo ""; if ($cbpos == "E"){display_lg_checkbox($prefid,"all");} if ($brislider){display_bri_slider($prefid,"all","all");} @@ -107,7 +107,7 @@ function display_lights_groups($prefid="",$cbpos="E",$brislider=false){ echo "
"; if ($cbpos == "B"){display_lg_checkbox($prefid, "other", "grp", "other");} - echo ""; + echo ""; echo ""; if ($cbpos == "E"){display_lg_checkbox($prefid, "other", "grp", "other");} if ($brislider){display_bri_slider($prefid,"other","other");} diff --git a/include/hueapi.php b/include/hueapi.php index c1e9d91..d7b239c 100644 --- a/include/hueapi.php +++ b/include/hueapi.php @@ -32,6 +32,9 @@ // Init env include "include/config.php"; +// Load translations +$trs = json_decode(implode(file('include/text_'.$lang.'.json')),true); + //-- API Class class HueAPI { //===================================== diff --git a/include/huecolor.php b/include/huecolor.php index 7dfd0c2..1599a7c 100644 --- a/include/huecolor.php +++ b/include/huecolor.php @@ -195,7 +195,7 @@ function RGBToXy($RGB,$type="bulb"){ // Remark : HueAPI->info must be already set // ------------------------------------------ function display_light($lnum){ - global $HueAPI; + global $HueAPI, $trs; $linfo = &$HueAPI->info['lights'][$lnum]; @@ -212,7 +212,7 @@ function display_light($lnum){ $lcolor = "transparent"; if ($lstate['reachable'] == ""){ $unreachable = true; - $popup = " TITLE=\"Unreachable\""; + $popup = " TITLE=\"".$trs["Unreachable"]."\""; } } else { // light on : get rgb color $onoff = "on"; diff --git a/include/lights_details.php b/include/lights_details.php index 18c01b3..4562a3e 100644 --- a/include/lights_details.php +++ b/include/lights_details.php @@ -7,7 +7,7 @@ // Elements selected and name update if 1 element or color switch if 2 lights selected echo "\n
"; -echo " "; +echo " "; echo ""; // selname echo "
"; // dispname @@ -16,7 +16,7 @@ echo "\n
"; echo "\n
Brightness"; +echo "".$trs["Brightness"]; echo "\n
"; @@ -25,46 +25,46 @@ // Action buttons echo "\n
"; -echo "
Effects\n"; -echo ""; -echo ""; -echo ""; +echo "
".$trs["Effects"]."\n"; +echo ""; +echo ""; +echo ""; echo "  "; -echo ""; -echo ""; +echo ""; +echo ""; echo "
"; echo "\n
"; // actions // Transfert color settings echo "\n
"; -echo "
Copy color settings\n"; +echo "
".$trs["Copy_color_settings"]."\n"; echo "
"; -echo ""; -echo ""; -echo ""; +echo ""; +echo ""; +echo ""; echo "
"; // tsradio echo " \n"; echo "
"; -echo ""; +echo ""; echo "
"; // dtsexec echo "\n
"; echo "\n
"; // transset // Group management echo "\n
"; -echo "
Manage group\n"; +echo "
".$trs["Manage_group"]."\n"; echo "\n"; echo "\n"; -echo "\n"; +echo " ".$trs["or_create"]." \n"; +echo "\n"; echo "\n"; // grplightopt echo "\n"; -echo "\n"; +echo "\n"; echo "\n"; // grpopt echo "\n
"; echo "\n
"; // grpmgmt // Element description (if 1 element only) -echo "\n

Informations

"; +echo "\n

".$trs["Informations"]."

"; ?>