summaryrefslogtreecommitdiffstats
path: root/lang/i18n.php
diff options
context:
space:
mode:
Diffstat (limited to 'lang/i18n.php')
-rw-r--r--lang/i18n.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/lang/i18n.php b/lang/i18n.php
new file mode 100644
index 00000000..82da12a1
--- /dev/null
+++ b/lang/i18n.php
@@ -0,0 +1,47 @@
+<?php
+
+class Dictionary{
+ private static $messageArray;
+
+ function build(){
+ self::$messageArray = json_decode(file_get_contents("lang/" . LANG . "/messages.json"),true);
+ }
+
+ public static function getArrayTemplate($template){
+ $language = array('lang'=>LANG);
+ return array_merge($language,json_decode(file_get_contents("lang/" . LANG . "/" . $template . ".json"),true));
+ }
+
+ public static function translate($string){
+ $hardcoded = json_decode(file_get_contents("lang/" . LANG . "/messages-hardcoded.json"),true);
+ return $hardcoded[$string];
+ }
+
+ public static function getMessages(){
+ return self::$messageArray;
+ }
+
+}
+ //Array containing the allowed languages for the website
+ $langArray = array("de","en","pt");
+
+ //Changes the language in case there is a request to
+ if(isset($_GET['lang']))
+ if(in_array($_GET['lang'],$langArray)){
+ setcookie('lang',$_GET['lang'],time()+60*60*24*30*12);
+ header('Location: ' . $_SERVER['HTTP_REFERER']);
+ }
+
+ //Default language
+ $language = 'en';
+
+ //Language from the browser
+ $langBrowser = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
+
+ //User language
+ if(isset($_COOKIE['lang']) && in_array($_COOKIE['lang'],$langArray)){
+ $language = $_COOKIE['lang'];
+ }else if(in_array($langBrowser,$langArray)){
+ $language = $langBrowser;
+ }
+?>