diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 06f8c68..641c55c 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -1197,6 +1197,50 @@ function drupal_unpack($obj, $field = 'data') {
 }
 
 /**
+ * Factory function that will fetch the translator object for the given
+ * language.
+ * 
+ * FIXME: I really don't like this function name. Seems odd. Some of its logic
+ * may be elsewhere, and we have to think about future D8 plugin system that
+ * may help somehow here.
+ * Another pitfall is if a t() call happens before modules are loaded, the
+ * locale implementation won't never show up, this is kind of bad. Strings
+ * should never be translated during bootstrap anyway, this doesn't make any
+ * sense.
+ * 
+ * @param string $langcode
+ */
+function _t_get_object($langcode) {
+  // FIXME: Do we need drupal_static() here? I'm not sure.
+  static $instances, $class;
+
+  // Determine which class to use depending on configuration.
+  if (!isset($class)) {
+    // FIXME: This is the piece of code that deeply needs rewrite.
+    $class = variable_get('locale_translator_backend_class', NULL);
+    if (!isset($class)) {
+      if (function_exists('locale')) {
+        $class = 'DrupalTranslatableLocale';
+      }
+      else {
+        $class = 'DrupalTranslatableDefault';
+      }
+    }
+
+    // Runtime failsafe for misconfigured environments.
+    if (!class_exists($class)) {
+      $class = 'DrupalTranslatableDefault';
+    }
+  }
+
+  if (!isset($instances[$langcode])) {
+    $instances[$langcode] = new $class($langcode, variable_get('locale_custom_strings_' . $langcode, array()));
+  }
+
+  return $instances[$langcode];
+}
+
+/**
  * Translates a string to the current language or to a given language.
  *
  * The t() function serves two purposes. First, at run-time it translates
@@ -1261,54 +1305,141 @@ function drupal_unpack($obj, $field = 'data') {
  */
 function t($string, array $args = array(), array $options = array()) {
   global $language;
-  static $custom_strings;
 
-  // Merge in default.
-  if (empty($options['langcode'])) {
-    $options['langcode'] = isset($language->language) ? $language->language : 'en';
-  }
-  if (empty($options['context'])) {
-    $options['context'] = '';
+  $langcode = isset($options['langcode']) ? $options['langcode'] : (isset($language->language) ? $language->language : 'en');
+  $context  = isset($options['context'])  ? $options['context']  : '';
+
+  return _t_get_object($langcode)->translate($string, $args, $context);
+}
+
+/**
+ * String translator: once instance per language will be spawned at runtime.
+ */
+interface DrupalTranslatorInterface {
+  /**
+   * Default constructor.
+   * 
+   * @param string $langcode = NULL
+   *   Language associated to this instance.
+   * @param array $customString = array()
+   *   Custom string overrides.
+   */
+  public function __construct($langcode, $customStrings = array());
+
+  /**
+   * Reset object state and ready it for usage with the new provided string
+   * and options.
+   * 
+   * Proceed to translation and arguments sanitize if needed, return the final
+   * human readable localized string.
+   * 
+   * @param string $string
+   *   Original string to translate.
+   * @param array $args = NULL
+   *   List of replacement tokens for the given string.
+   * @param string $context = ''
+   *   String context.
+   * 
+   * @return string
+   */
+  public function translate($string, $args = NULL, $context = '');
+}
+
+/**
+ * Default implementation acting as a pass-through that will only proceed to
+ * token replacements without carrying about the language.
+ */
+class DrupalTranslatableDefault implements DrupalTranslatorInterface {
+  /**
+   * @var array
+   */
+  protected $_customStrings = array();
+
+  /**
+   * @see DrupalTranslatorInterface::__construct().
+   */
+  public function __construct($langcode,  $customStrings = array()) {
+    $this->_langcode      = $langcode;
+    $this->_customStrings = $customStrings;
+  }
+
+  /**
+   * @see DrupalTranslatorInterface::translate()
+   */
+  public function translate($string, $args = NULL, $context = '') {
+    if (empty($args)) {
+      return $this->getLocalizedString($string, $context);
+    }
+    else {
+      return strtr($this->getLocalizedString($string, $context), $this->sanitize($args));
+    }
   }
 
-  // First, check for an array of customized strings. If present, use the array
-  // *instead of* database lookups. This is a high performance way to provide a
-  // handful of string replacements. See settings.php for examples.
-  // Cache the $custom_strings variable to improve performance.
-  if (!isset($custom_strings[$options['langcode']])) {
-    $custom_strings[$options['langcode']] = variable_get('locale_custom_strings_' . $options['langcode'], array());
-  }
-  // Custom strings work for English too, even if locale module is disabled.
-  if (isset($custom_strings[$options['langcode']][$options['context']][$string])) {
-    $string = $custom_strings[$options['langcode']][$options['context']][$string];
-  }
-  // Translate with locale module if enabled.
-  elseif ($options['langcode'] != 'en' && function_exists('locale')) {
-    $string = locale($string, $options['context'], $options['langcode']);
-  }
-  if (empty($args)) {
+  /**
+   * Sanitizes string token replacement arguments.
+   * 
+   * @param array $args
+   *   Arguments to sanitize.
+   * 
+   * @return array
+   *   Sanitized arguments.
+   */
+  protected function sanitize($args) {
+    if (!empty($args)) {
+      // Transform arguments before inserting them.
+      foreach ($args as $key => $value) {
+        switch ($key[0]) {
+          case '@':
+            // Escaped only.
+            $args[$key] = check_plain($value);
+            break;
+
+          case '%':
+          default:
+            // Escaped and placeholder.
+            $args[$key] = drupal_placeholder($value);
+            break;
+
+          case '!':
+            // Pass-through.
+        }
+      }
+    }
+    return $args;
+  }
+
+  /**
+   * Get localized version of the current string.
+   * 
+   * @param string $string
+   * @param string $context
+   * 
+   * @return string
+   */
+  protected function getLocalizedString($string, $context) {
+    // Custom by configuration string bypass.
+    if (isset($this->_customStrings[$context][$string])) {
+      $string = $this->_customStrings[$context][$string];
+    }
     return $string;
   }
-  else {
-    // Transform arguments before inserting them.
-    foreach ($args as $key => $value) {
-      switch ($key[0]) {
-        case '@':
-          // Escaped only.
-          $args[$key] = check_plain($value);
-          break;
-
-        case '%':
-        default:
-          // Escaped and placeholder.
-          $args[$key] = drupal_placeholder($value);
-          break;
+}
 
-        case '!':
-          // Pass-through.
-      }
-    }
-    return strtr($string, $args);
+/**
+ * Locale module implementation of DrupalTranslatorInterface.
+ */
+class DrupalTranslatableLocale extends DrupalTranslatableDefault {
+  /**
+   * @see DrupalTranslatableDefault::getLocalizedString()
+   */
+  public function getLocalizedString($string, $context) {
+    // Will replace the current string by the configuration override, if set.
+    $string = parent::getLocalizedString($string, $context);
+    // FIXME: This method should be replaced by the real locale() function:
+    // the original locale() function would become a pass-thought to the
+    // translator objects for compatibility, or just disappear.
+    $string = locale($string, $context, $this->_langcode);
+    return $string;
   }
 }
 
diff --git a/includes/common.inc b/includes/common.inc
index d7189ab..3a73e31 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -2262,7 +2262,9 @@ function drupal_http_header_attributes(array $attributes = array()) {
  */
 function drupal_attributes(array $attributes = array()) {
   foreach ($attributes as $attribute => &$data) {
-    $data = implode(' ', (array) $data);
+    if (is_array($data)) {
+      $data = implode(' ', $data);
+    }
     $data = $attribute . '="' . check_plain($data) . '"';
   }
   return $attributes ? ' ' . implode(' ', $attributes) : '';
diff --git a/includes/form.inc b/includes/form.inc
index 10e68ee..7cfc586 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -2578,7 +2578,7 @@ function form_select_options($element, $choices = NULL) {
       $options .= form_select_options($element, $choice);
       $options .= '</optgroup>';
     }
-    elseif (is_object($choice)) {
+    elseif (is_object($choice) && $choice instanceof stdClass) {
       $options .= form_select_options($element, $choice->option);
     }
     else {
