Add sq_change_text_domain for plugins to use when switching text domains
authorpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 30 Mar 2007 20:45:55 +0000 (20:45 +0000)
committerpdontthink <pdontthink@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Fri, 30 Mar 2007 20:45:55 +0000 (20:45 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12356 7612ce4b-ef26-0410-bec9-ea0150e637f0

include/languages.php

index 0fbcc34d3f979b9374c7050c6d328788215ac9a2..592f1f543c5ad267079c6742ce6f4441e550586f 100644 (file)
  */
 
 
+/**
+ * Wrapper for textdomain(), bindtextdomain() and
+ * bind_textdomain_codeset() primarily intended for
+ * plugins when changing into their own text domain 
+ * and back again.
+ *
+ * Note that plugins using this function must have
+ * their translation files located in the SquirrelMail
+ * locale directory.
+ *
+ * @param string $domain_name The name of the text domain 
+ *                            (usually the plugin name, or 
+ *                            "squirrelmail") being switched to.                 
+ *
+ * @return void
+ *
+ * @since 1.5.2 and 1.4.10 
+ */
+function sq_change_text_domain($domain_name) {
+
+    global $languages, $sm_notAlias;
+    static $domains_already_seen = array();
+
+    // only need to call bindtextdomain() once 
+    //
+    if (in_array($domain_name, $domains_already_seen)) {
+        sq_textdomain($domain_name);
+        return;
+    }
+
+    $domains_already_seen[] = $domain_name;
+
+    sq_bindtextdomain($domain_name, SM_PATH . 'locale/');
+    sq_textdomain($domain_name);
+
+    // set codeset in order to avoid gettext charset conversions
+    if (function_exists('bind_textdomain_codeset') 
+     && isset($languages[$sm_notAlias]['CHARSET'])) {
+
+        // Japanese translation uses different internal charset
+        if ($sm_notAlias == 'ja_JP') {
+            bind_textdomain_codeset ($domain_name, 'EUC-JP');
+        } else {
+            bind_textdomain_codeset ($domain_name, $languages[$sm_notAlias]['CHARSET']);
+        }
+
+    }
+}
+
 /**
  * Gettext bindtextdomain wrapper.
  *