Better fallback in getTokenizer when exact locale not found. For example fa_ir to fa, a=chris

Chris Pollett [2015-11-06 17:Nov:th]
Better fallback in getTokenizer when exact locale not found. For example fa_ir to fa, a=chris
Filename
src/index.php
src/library/PhraseParser.php
diff --git a/src/index.php b/src/index.php
index c16d30ae3..3543c382a 100755
--- a/src/index.php
+++ b/src/index.php
@@ -75,8 +75,10 @@ function bootstrap()
         For none dumb browsers this should help prevent against XSS attacks
         to images containing HTML. Also, might help against PRSSI attacks.
         */
-    session_name(C\SESSION_NAME);
-    session_start();
+    if (session_status() == PHP_SESSION_NONE) {
+        session_name(C\SESSION_NAME);
+        session_start();
+    }
     /**
      * Load global functions related to checking Yioop! version
      */
diff --git a/src/library/PhraseParser.php b/src/library/PhraseParser.php
index e7c4b9c00..cb7eee67d 100755
--- a/src/library/PhraseParser.php
+++ b/src/library/PhraseParser.php
@@ -754,6 +754,16 @@ class PhraseParser
             }
         } else {
             $tag = str_replace("-", "_", $lang);
+            if (!file_exists(C\LOCALE_DIR . "/$tag/resources/Tokenizer.php")) {
+                $tokenizer_list = glob(C\LOCALE_DIR .
+                    "/{$lang_parts[0]}*/resources/Tokenizer.php");
+                if(isset($tokenizer_list[0])) {
+                    $tag = substr($tokenizer_list[0], strlen(C\LOCALE_DIR) + 1,
+                        - strlen("/resources/Tokenizer.php"));
+                } else {
+                    $tag = "";
+                }
+            }
         }
         $tokenizer_class_name = C\NS_LOCALE . "$tag\\resources\\Tokenizer";
         if (class_exists($tokenizer_class_name)) {
ViewGit