diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index e64bfca..f48883c 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -1392,23 +1392,24 @@ function drupal_unpack($obj, $field = 'data') { /** * Translates a string to the current language or to a given language. * - * The t() function serves two purposes. First, at run-time it translates - * user-visible text into the appropriate language. Second, various mechanisms - * that figure out what text needs to be translated work off t() -- the text - * inside t() calls is added to the database of strings to be translated. - * These strings are expected to be in English, so the first argument should - * always be in English. To enable a fully-translatable site, it is important - * that all human-readable text that will be displayed on the site or sent to - * a user is passed through the t() function, or a related function. See the - * @link http://drupal.org/node/322729 Localization API @endlink pages for - * more information, including recommendations on how to break up or not - * break up strings for translation. - * - * You should never use t() to translate variables, such as calling - * @code t($text); @endcode, unless the text that the variable holds has been - * passed through t() elsewhere (e.g., $text is one of several translated - * literal strings in an array). It is especially important never to call - * @code t($user_text); @endcode, where $user_text is some text that a user + * The t() function serves three purposes. First, at run-time it translates + * user-visible text into the appropriate language. Second, also at run-time it + * picks the correct language version of translateable configuration. Third, + * various mechanisms that figure out what text needs to be translated work + * off t() -- the text inside t() calls is added to the database of strings + * to be translated. These strings are expected to be in English, so the first + * argument should always be in English. To enable a fully-translatable site, + * it is important that all human-readable text that will be displayed on the + * site or sent to a user is passed through the t() function, or a related + * function. See the @link http://drupal.org/node/322729 Localization API + * @endlink pages for more information, including recommendations on how to + * break up or not break up strings for translation. + * + * You should never use t() to translate variables except config objects, such + * as calling @code t($text); @endcode, unless the text that the variable holds + * has been passed through t() elsewhere (e.g., $text is one of several + * translated literal strings in an array). It is especially important never to + * call @code t($user_text); @endcode, where $user_text is some text that a user * entered - doing that can lead to cross-site scripting and other security * problems. However, you can use variable substitution in your string, to put * variable text such as user names or link URLs into translated text. Variable @@ -1426,8 +1427,10 @@ function drupal_unpack($obj, $field = 'data') { * available to code that needs localization. See st() and get_t() for * alternatives. * - * @param $string - * A string containing the English string to translate. + * @param $input + * A string containing the English string to translate or a translated + * config array. To create a translated config pass in a langcode as a + * subkey to Drupal\Core\Config\DrupalConfig::set(). * @param $args * An associative array of replacements to make after translation. Based * on the first character of the key, the value is escaped and/or themed. @@ -1447,13 +1450,24 @@ function drupal_unpack($obj, $field = 'data') { * @see format_string() * @ingroup sanitization */ -function t($string, array $args = array(), array $options = array()) { +function t($input, array $args = array(), array $options = array()) { static $custom_strings; // Merge in default. if (empty($options['langcode'])) { $options['langcode'] = drupal_container()->get(LANGUAGE_TYPE_INTERFACE)->langcode; } + if (is_array($input)) { + if (isset($input[$options['langcode']])) { + return $input[$options['langcode']]; + } + elseif (isset($input['_default'])) { + return $input[$input['_default']]; + } + else { + return $input['en']; + } + } if (empty($options['context'])) { $options['context'] = ''; } @@ -1466,18 +1480,18 @@ function t($string, array $args = array(), array $options = array()) { $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]; + if (isset($custom_strings[$options['langcode']][$options['context']][$input])) { + $input = $custom_strings[$options['langcode']][$options['context']][$input]; } // Translate with locale module if enabled. elseif ($options['langcode'] != LANGUAGE_SYSTEM && ($options['langcode'] != 'en' || variable_get('locale_translate_english', FALSE)) && function_exists('locale')) { - $string = locale($string, $options['context'], $options['langcode']); + $input = locale($input, $options['context'], $options['langcode']); } if (empty($args)) { - return $string; + return $input; } else { - return format_string($string, $args); + return format_string($input, $args); } } diff --git a/core/includes/install.inc b/core/includes/install.inc index 1ebfb21..6d57f42 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -711,7 +711,7 @@ function drupal_requirements_url($severity) { * @see get_t() * @ingroup sanitization */ -function st($string, array $args = array(), array $options = array()) { +function st($input, array $args = array(), array $options = array()) { static $strings = NULL; global $install_state; @@ -754,7 +754,7 @@ function st($string, array $args = array(), array $options = array()) { case '!': } } - return strtr((!empty($strings[$options['context']][$string]) ? $strings[$options['context']][$string] : $string), $args); + return strtr((!empty($strings[$options['context']][$input]) ? $strings[$options['context']][$input] : $input), $args); } /** diff --git a/core/lib/Drupal/Core/Config/DrupalConfig.php b/core/lib/Drupal/Core/Config/DrupalConfig.php index f5a9220..dee4cf5 100644 --- a/core/lib/Drupal/Core/Config/DrupalConfig.php +++ b/core/lib/Drupal/Core/Config/DrupalConfig.php @@ -129,16 +129,28 @@ class DrupalConfig { * * @param $key * @todo + * @param $subkey + * Typically a langcode but can be anything. After using a langcode here, + * you can pass the result value of the corresponding get() call to t() + * to get the version in the current language. * @param $value * @todo */ - public function set($key, $value) { + public function set($key, $value, $subkey = '') { // Type-cast value into a string. $value = $this->castValue($value); // The dot/period is a reserved character; it may appear between keys, but // not within keys. $parts = explode('.', $key); + if ($subkey) { + $default = $parts; + $default[] = '_default'; + if (!drupal_array_get_nested_value($this->data, $default)) { + drupal_array_set_nested_value($this->data, $default, $subkey); + } + $parts[] = $subkey; + } if (count($parts) == 1) { $this->data[$key] = $value; }