Commit 28b2f098 authored by Dries's avatar Dries

- Patch #334283 by Damien Tournoud, andypost, Freso et al: add context to t()...

- Patch #334283 by Damien Tournoud, andypost, Freso et al: add context to t() to help deal with ambigious strings (and improved the locale APIs a bit). Example: May is both a short month name as a long month name in English, but not necessarily in other languages.
parent ece9032a
......@@ -123,6 +123,8 @@ Drupal 7.0, xxxx-xx-xx (development version)
with other blocks in the same region.
* Blocks can now return structured arrays for later rendering just
like page callbacks.
- Translation system
* The translation system now supports message context (msgctxt).
- Upgraded the core JavaScript library to jQuery version 1.3.2.
- Upgraded the jQuery Forms library to 2.21.
......
......@@ -1126,37 +1126,44 @@ function fix_gpc_magic() {
* - @variable: escape plain text to HTML (check_plain)
* - %variable: escape text and theme as a placeholder for user-submitted
* content (check_plain + theme_placeholder)
* @param $langcode
* Optional language code to translate to a language other than what is used
* to display the page.
* @param $options
* An associative array of additional options, with the following keys:
* - 'langcode' (default to the current language) The language code to
* translate to a language other than what is used to display the page.
* - 'context' (default to the empty context) The context the source string
* belongs to.
* @return
* The translated string.
*/
function t($string, $args = array(), $langcode = NULL) {
function t($string, array $args = array(), array $options = array()) {
global $language;
$custom_strings = &drupal_static(__FUNCTION__);
if (!isset($langcode)) {
$langcode = isset($language->language) ? $language->language : 'en';
// Merge in default.
if (empty($options['langcode'])) {
$options['langcode'] = isset($language->language) ? $language->language : 'en';
}
if (empty($options['context'])) {
$options['context'] = '';
}
// 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[$langcode])) {
$custom_strings[$langcode] = variable_get('locale_custom_strings_' . $langcode, array());
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[$langcode][$string])) {
$string = $custom_strings[$langcode][$string];
if (isset($custom_strings[$options['langcode']][$options['context']][$string])) {
$string = $custom_strings[$options['langcode']][$options['context']][$string];
}
// Translate with locale module if enabled.
// We don't use drupal_function_exists() here, because it breaks the testing
// framework if the locale module is enabled in the parent site (we cannot
// unload functions in PHP).
elseif (module_exists('locale') && $langcode != 'en') {
$string = locale($string, $langcode);
elseif (module_exists('locale') && $options['langcode'] != 'en') {
$string = locale($string, $options['context'], $options['langcode']);
}
if (empty($args)) {
return $string;
......@@ -1711,34 +1718,37 @@ function format_xml_elements($array) {
* content (check_plain + theme_placeholder)
* Note that you do not need to include @count in this array.
* This replacement is done automatically for the plural case.
* @param $langcode
* Optional language code to translate to a language other than
* what is used to display the page.
* @param $options
* An associative array of additional options, with the following keys:
* - 'langcode' (default to the current language) The language code to
* translate to a language other than what is used to display the page.
* - 'context' (default to the empty context) The context the source string
* belongs to.
* @return
* A translated string.
*/
function format_plural($count, $singular, $plural, $args = array(), $langcode = NULL) {
function format_plural($count, $singular, $plural, array $args = array(), array $options = array()) {
$args['@count'] = $count;
if ($count == 1) {
return t($singular, $args, $langcode);
return t($singular, $args, $options);
}
// Get the plural index through the gettext formula.
$index = (function_exists('locale_get_plural')) ? locale_get_plural($count, $langcode) : -1;
$index = (function_exists('locale_get_plural')) ? locale_get_plural($count, isset($options['langcode']) ? $options['langcode'] : NULL) : -1;
// Backwards compatibility.
if ($index < 0) {
return t($plural, $args, $langcode);
return t($plural, $args, $options);
}
else {
switch ($index) {
case "0":
return t($singular, $args, $langcode);
return t($singular, $args, $options);
case "1":
return t($plural, $args, $langcode);
return t($plural, $args, $options);
default:
unset($args['@count']);
$args['@count[' . $index . ']'] = $count;
return t(strtr($plural, array('@count' => '@count[' . $index . ']')), $args, $langcode);
return t(strtr($plural, array('@count' => '@count[' . $index . ']')), $args, $options);
}
}
}
......@@ -1777,19 +1787,19 @@ function parse_size($size) {
*/
function format_size($size, $langcode = NULL) {
if ($size < DRUPAL_KILOBYTE) {
return format_plural($size, '1 byte', '@count bytes', array(), $langcode);
return format_plural($size, '1 byte', '@count bytes', array(), array('langcode' => $langcode));
}
else {
$size = $size / DRUPAL_KILOBYTE; // Convert bytes to kilobytes.
$units = array(
t('@size KB', array(), $langcode),
t('@size MB', array(), $langcode),
t('@size GB', array(), $langcode),
t('@size TB', array(), $langcode),
t('@size PB', array(), $langcode),
t('@size EB', array(), $langcode),
t('@size ZB', array(), $langcode),
t('@size YB', array(), $langcode),
t('@size KB', array(), array('langcode' => $langcode)),
t('@size MB', array(), array('langcode' => $langcode)),
t('@size GB', array(), array('langcode' => $langcode)),
t('@size TB', array(), array('langcode' => $langcode)),
t('@size PB', array(), array('langcode' => $langcode)),
t('@size EB', array(), array('langcode' => $langcode)),
t('@size ZB', array(), array('langcode' => $langcode)),
t('@size YB', array(), array('langcode' => $langcode)),
);
foreach ($units as $unit) {
if (round($size, 2) >= DRUPAL_KILOBYTE) {
......@@ -1830,7 +1840,7 @@ function format_interval($timestamp, $granularity = 2, $langcode = NULL) {
foreach ($units as $key => $value) {
$key = explode('|', $key);
if ($timestamp >= $value) {
$output .= ($output ? ' ' : '') . format_plural(floor($timestamp / $value), $key[0], $key[1], array(), $langcode);
$output .= ($output ? ' ' : '') . format_plural(floor($timestamp / $value), $key[0], $key[1], array(), array('langcode' => $langcode));
$timestamp %= $value;
$granularity--;
}
......@@ -1839,7 +1849,7 @@ function format_interval($timestamp, $granularity = 2, $langcode = NULL) {
break;
}
}
return $output ? $output : t('0 sec', array(), $langcode);
return $output ? $output : t('0 sec', array(), array('langcode' => $langcode));
}
/**
......@@ -1908,13 +1918,13 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL
for ($i = 0; $i < $max; $i++) {
$c = $format[$i];
if (strpos('AaeDlMT', $c) !== FALSE) {
$date .= t(date_format($date_time, $c), array(), $langcode);
$date .= t(date_format($date_time, $c), array(), array('langcode' => $langcode));
}
elseif ($c == 'F') {
// Special treatment for long month names: May is both an abbreviation
// and a full month name in English, but other languages have
// different abbreviations.
$date .= trim(t('!long-month-name ' . date_format($date_time, $c), array('!long-month-name' => ''), $langcode));
$date .= t(date_format($date_time, $c), array(), array('context' => 'Long month name', 'langcode' => $langcode));
}
elseif (strpos('BcdGgHhIijLmNnOoPSstUuWwYyZz', $c) !== FALSE) {
$date .= date_format($date_time, $c);
......
This diff is collapsed.
......@@ -178,13 +178,13 @@ function contact_mail($key, &$message, $params) {
case 'page_mail':
case 'page_copy':
$contact = $params['contact'];
$message['subject'] .= t('[!category] !subject', array('!category' => $contact['category'], '!subject' => $params['subject']), $language->language);
$message['body'][] = t("!name sent a message using the contact form at !form.", array('!name' => $params['name'], '!form' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language))), $language->language);
$message['subject'] .= t('[!category] !subject', array('!category' => $contact['category'], '!subject' => $params['subject']), array('langcode' => $language->language));
$message['body'][] = t("!name sent a message using the contact form at !form.", array('!name' => $params['name'], '!form' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language))), array('langcode' => $language->language));
$message['body'][] = $params['message'];
break;
case 'page_autoreply':
$contact = $params['contact'];
$message['subject'] .= t('[!category] !subject', array('!category' => $contact['category'], '!subject' => $params['subject']), $language->language);
$message['subject'] .= t('[!category] !subject', array('!category' => $contact['category'], '!subject' => $params['subject']), array('langcode' => $language->language));
$message['body'][] = $contact['reply'];
break;
case 'user_mail':
......@@ -193,9 +193,9 @@ function contact_mail($key, &$message, $params) {
$account = $params['account'];
$message['subject'] .= '[' . variable_get('site_name', 'Drupal') . '] ' . $params['subject'];
$message['body'][] = "$account->name,";
$message['body'][] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array('!name' => $user->name, '!name-url' => url("user/$user->uid", array('absolute' => TRUE, 'language' => $language)), '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)), '!site' => variable_get('site_name', 'Drupal')), $language->language);
$message['body'][] = t("If you don't want to receive such e-mails, you can change your settings at !url.", array('!url' => url("user/$account->uid", array('absolute' => TRUE, 'language' => $language))), $language->language);
$message['body'][] = t('Message:', NULL, $language->language);
$message['body'][] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array('!name' => $user->name, '!name-url' => url("user/$user->uid", array('absolute' => TRUE, 'language' => $language)), '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)), '!site' => variable_get('site_name', 'Drupal')), array('langcode' => $language->language));
$message['body'][] = t("If you don't want to receive such e-mails, you can change your settings at !url.", array('!url' => url("user/$account->uid", array('absolute' => TRUE, 'language' => $language))), array('langcode' => $language->language));
$message['body'][] = t('Message:', array(), array('langcode' => $language->language));
$message['body'][] = $params['message'];
break;
}
......
......@@ -229,6 +229,25 @@ function locale_update_6006() {
* @} End of "defgroup updates-5.x-to-6.x"
*/
/**
* @defgroup updates-6.x-to-7.x Locale updates from 6.x to 7.x
* @{
*/
/**
* Allow longer location.
*/
function locale_update_7000() {
$ret = array();
db_drop_index($ret, 'locales_source', 'source');
db_add_index($ret, 'locales_source', 'source_context', array(array('source', 30), 'context'));
return $ret;
}
/**
* @} End of "defgroup updates-6.x-to-7.x"
*/
/**
* Implement hook_uninstall().
*/
......@@ -381,6 +400,13 @@ function locale_schema() {
'not null' => TRUE,
'description' => 'The original string in English.',
),
'context' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The context this string applies to.',
),
'version' => array(
'type' => 'varchar',
'length' => 20,
......@@ -391,7 +417,7 @@ function locale_schema() {
),
'primary key' => array('lid'),
'indexes' => array(
'source' => array(array('source', 30)),
'source_context' => array(array('source', 30), 'context'),
),
);
......
......@@ -341,12 +341,14 @@ function locale_theme() {
* A string to look up translation for. If omitted, all the
* cached strings will be returned in all languages already
* used on the page.
* @param $context
* The context of this string.
* @param $langcode
* Language code to use for the lookup.
* @param $reset
* Set to TRUE to reset the in-memory cache.
*/
function locale($string = NULL, $langcode = NULL, $reset = FALSE) {
function locale($string = NULL, $context = NULL, $langcode = NULL, $reset = FALSE) {
global $language;
static $locale_t;
......@@ -377,9 +379,9 @@ function locale($string = NULL, $langcode = NULL, $reset = FALSE) {
// Refresh database stored cache of translations for given language.
// We only store short strings used in current version, to improve
// performance and consume less memory.
$result = db_query("SELECT s.source, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) < 75", array(':language' => $langcode, ':version' => VERSION));
$result = db_query("SELECT s.source, s.context, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) < 75", array(':language' => $langcode, ':version' => VERSION));
foreach ($result as $data) {
$locale_t[$langcode][$data->source] = (empty($data->translation) ? TRUE : $data->translation);
$locale_t[$langcode][$data->context][$data->source] = (empty($data->translation) ? TRUE : $data->translation);
}
cache_set('locale:' . $langcode, $locale_t[$langcode]);
}
......@@ -387,17 +389,18 @@ function locale($string = NULL, $langcode = NULL, $reset = FALSE) {
}
// If we have the translation cached, skip checking the database
if (!isset($locale_t[$langcode][$string])) {
if (!isset($locale_t[$langcode][$context][$string])) {
// We do not have this translation cached, so get it from the DB.
$translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.textgroup = 'default'", array(
$translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default'", array(
':language' => $langcode,
':source' => $string,
':context' => (string) $context,
))->fetchObject();
if ($translation) {
// We have the source string at least.
// Cache translation string or TRUE if no translation exists.
$locale_t[$langcode][$string] = (empty($translation->translation) ? TRUE : $translation->translation);
$locale_t[$langcode][$context][$string] = (empty($translation->translation) ? TRUE : $translation->translation);
if ($translation->version != VERSION) {
// This is the first use of this string under current Drupal version. Save version
......@@ -416,17 +419,18 @@ function locale($string = NULL, $langcode = NULL, $reset = FALSE) {
->fields(array(
'location' => request_uri(),
'source' => $string,
'context' => (string) $context,
'textgroup' => 'default',
'version' => VERSION,
))
->execute();
$locale_t[$langcode][$string] = TRUE;
$locale_t[$langcode][$context][$string] = TRUE;
// Clear locale cache so this string can be added in a later request.
cache_clear_all('locale:', 'cache', TRUE);
}
}
return ($locale_t[$langcode][$string] === TRUE ? $string : $locale_t[$langcode][$string]);
return ($locale_t[$langcode][$context][$string] === TRUE ? $string : $locale_t[$langcode][$context][$string]);
}
/**
......
......@@ -212,9 +212,9 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
);
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
// Add string.
t($name, array(), $langcode);
t($name, array(), array('langcode' => $langcode));
// Reset locale cache.
locale(NULL, NULL, TRUE);
locale(NULL, NULL, NULL, TRUE);
$this->assertText($langcode, t('Language code found.'));
$this->assertText($name, t('Name found.'));
$this->assertText($native, t('Native found.'));
......@@ -251,7 +251,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
$this->drupalPost(NULL, $edit, t('Save translations'));
$this->assertText(t('The string has been saved.'), t('The string has been saved.'));
$this->assertEqual($this->getUrl(), url('admin/international/translate/translate', array('absolute' => TRUE)), t('Correct page redirection.'));
$this->assertTrue($name != $translation && t($name, array(), $langcode) == $translation, t('t() works.'));
$this->assertTrue($name != $translation && t($name, array(), array('langcode' => $langcode)) == $translation, t('t() works.'));
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
// The indicator should not be here.
$this->assertNoRaw($language_indicator, t('String is translated.'));
......@@ -344,7 +344,7 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
);
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
// Add string.
t($name, array(), $langcode);
t($name, array(), array('langcode' => $langcode));
// Reset locale cache.
$search = array(
'string' => $name,
......@@ -405,9 +405,9 @@ class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
);
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
// Add string.
t($name, array(), $langcode);
t($name, array(), array('langcode' => $langcode));
// Reset locale cache.
locale(NULL, NULL, TRUE);
locale(NULL, NULL, NULL, TRUE);
$this->drupalLogout();
// Search for the name.
......@@ -553,13 +553,9 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase {
*/
function testStandalonePoFile() {
// Try importing a .po file.
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $this->getPoFile());
$this->drupalPost('admin/international/translate/import', array(
$this->importPoFile($this->getPoFile(), array(
'langcode' => 'fr',
'files[file]' => $name,
), t('Import'));
unlink($name);
));
// The import should automatically create the corresponding language.
$this->assertRaw(t('The language %language has been created.', array('%language' => 'French')), t('The language has been automatically created.'));
......@@ -570,31 +566,28 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase {
// Ensure we were redirected correctly.
$this->assertEqual($this->getUrl(), url('admin/international/translate', array('absolute' => TRUE)), t('Correct page redirection.'));
// Try importing a .po file with invalid tags in the default text group.
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $this->getBadPoFile());
$this->drupalPost('admin/international/translate/import', array(
$this->importPoFile($this->getBadPoFile(), array(
'langcode' => 'fr',
'files[file]' => $name,
), t('Import'));
unlink($name);
));
// The import should have created 1 string and rejected 2.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.'));
$skip_message = format_plural(2, 'One translation string was skipped because it contains disallowed HTML.', '@count translation strings were skipped because they contain disallowed HTML.');
$this->assertRaw($skip_message, t('Unsafe strings were skipped.'));
// Try importing a .po file with invalid tags in a non default text group.
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $this->getBadPoFile());
$this->drupalPost('admin/international/translate/import', array(
$this->importPoFile($this->getBadPoFile(), array(
'langcode' => 'fr',
'files[file]' => $name,
'group' => 'custom',
), t('Import'));
unlink($name);
));
// The import should have created 3 strings.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 3, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.'));
// Try importing a .po file which doesn't exist.
$name = $this->randomName(16);
$this->drupalPost('admin/international/translate/import', array(
......@@ -605,16 +598,14 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase {
$this->assertEqual($this->getUrl(), url('admin/international/translate/import', array('absolute' => TRUE)), t('Correct page redirection.'));
$this->assertText(t('File to import not found.'), t('File to import not found message.'));
// Try importing a .po file with overriding strings, and ensure existing
// strings are kept.
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $this->getOverwritePoFile());
$this->drupalPost('admin/international/translate/import', array(
$this->importPoFile($this->getOverwritePoFile(), array(
'langcode' => 'fr',
'files[file]' => $name,
'mode' => 1, // Existing strings are kept, only new strings are added.
), t('Import'));
unlink($name);
));
// The import should have created 1 string.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.'));
// Ensure string wasn't overwritten.
......@@ -627,16 +618,14 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase {
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
$this->assertText(t('No strings found for your search.'), t('String not overwritten by imported string.'));
// Try importing a .po file with overriding strings, and ensure existing
// strings are overwritten.
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $this->getOverwritePoFile());
$this->drupalPost('admin/international/translate/import', array(
$this->importPoFile($this->getOverwritePoFile(), array(
'langcode' => 'fr',
'files[file]' => $name,
'mode' => 0, // Strings in the uploaded file replace existing ones, new ones are added.
), t('Import'));
unlink($name);
));
// The import should have updated 2 strings.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 0, '%update' => 2, '%delete' => 0)), t('The translation file was successfully imported.'));
// Ensure string was overwritten.
......@@ -689,6 +678,36 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase {
$this->assertNoText(t('No strings found for your search.'), t('String successfully imported.'));
}
/**
* Test automatic importation of a module's translation files when a language
* is enabled.
*/
function testLanguageContext() {
// Try importing a .po file.
$this->importPoFile($this->getPoFileWithContext(), array(
'langcode' => 'hr',
));
$this->assertIdentical(t('May', array(), array('langcode' => 'hr', 'context' => 'Long month name')), 'Svibanj', t('Long month name context is working.'));
$this->assertIdentical(t('May', array(), array('langcode' => 'hr', 'context' => 'Short month name')), 'Svi.', t('Short month name context is working.'));
}
/**
* Helper function: import a standalone .po file in a given language.
*
* @param $contents
* Contents of the .po file to import.
* @param $options
* Additional options to pass to the translation import form.
*/
function importPoFile($contents, array $options = array()) {
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $contents);
$options['files[file]'] = $name;
$this->drupalPost('admin/international/translate/import', $options, t('Import'));
unlink($name);
}
/**
* Helper function that returns a proper .po file.
*/
......@@ -772,6 +791,32 @@ msgstr "Jour"
EOF;
}
/**
* Helper function that returns a .po file with context.
*/
function getPoFileWithContext() {
// Croatian (code hr) is one the the languages that have a different
// form for the full name and the abbreviated name for the month May.
return <<< EOF
msgid ""
msgstr ""
"Project-Id-Version: Drupal 6\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\\n"
msgctxt "Long month name"
msgid "May"
msgstr "Svibanj"
msgctxt "Short month name"
msgid "May"
msgstr "Svi."
EOF;
}
}
/**
......
......@@ -414,11 +414,11 @@ function update_refresh() {
function update_mail($key, &$message, $params) {
$language = $message['language'];
$langcode = $language->language;
$message['subject'] .= t('New release(s) available for !site_name', array('!site_name' => variable_get('site_name', 'Drupal')), $langcode);
$message['subject'] .= t('New release(s) available for !site_name', array('!site_name' => variable_get('site_name', 'Drupal')), array('langcode' => $langcode));
foreach ($params as $msg_type => $msg_reason) {
$message['body'][] = _update_message_text($msg_type, $msg_reason, FALSE, $language);
}
$message['body'][] = t('See the available updates page for more information:', array(), $langcode) . "\n" . url('admin/reports/updates', array('absolute' => TRUE, 'language' => $language));
$message['body'][] = t('See the available updates page for more information:', array(), array('langcode' => $langcode)) . "\n" . url('admin/reports/updates', array('absolute' => TRUE, 'language' => $language));
}
/**
......@@ -447,37 +447,37 @@ function _update_message_text($msg_type, $msg_reason, $report_link = FALSE, $lan
switch ($msg_reason) {
case UPDATE_NOT_SECURE:
if ($msg_type == 'core') {
$text = t('There is a security update available for your version of Drupal. To ensure the security of your server, you should update immediately!', array(), $langcode);
$text = t('There is a security update available for your version of Drupal. To ensure the security of your server, you should update immediately!', array(), array('langcode' => $langcode));
}
else {
$text = t('There are security updates available for one or more of your modules or themes. To ensure the security of your server, you should update immediately!', array(), $langcode);
$text = t('There are security updates available for one or more of your modules or themes. To ensure the security of your server, you should update immediately!', array(), array('langcode' => $langcode));
}
break;
case UPDATE_REVOKED:
if ($msg_type == 'core') {
$text = t('Your version of Drupal has been revoked and is no longer available for download. Upgrading is strongly recommended!', array(), $langcode);
$text = t('Your version of Drupal has been revoked and is no longer available for download. Upgrading is strongly recommended!', array(), array('langcode' => $langcode));
}
else {
$text = t('The installed version of at least one of your modules or themes has been revoked and is no longer available for download. Upgrading or disabling is strongly recommended!', array(), $langcode);
$text = t('The installed version of at least one of your modules or themes has been revoked and is no longer available for download. Upgrading or disabling is strongly recommended!', array(), array('langcode' => $langcode));
}
break;
case UPDATE_NOT_SUPPORTED:
if ($msg_type == 'core') {
$text = t('Your version of Drupal is no longer supported. Upgrading is strongly recommended!', array(), $langcode);
$text = t('Your version of Drupal is no longer supported. Upgrading is strongly recommended!', array(), array('langcode' => $langcode));
}
else {
$text = t('The installed version of at least one of your modules or themes is no longer supported. Upgrading or disabling is strongly recommended! Please see the project homepage for more details.', array(), $langcode);
$text = t('The installed version of at least one of your modules or themes is no longer supported. Upgrading or disabling is strongly recommended! Please see the project homepage for more details.', array(), array('langcode' => $langcode));
}
break;
case UPDATE_NOT_CURRENT:
if ($msg_type == 'core') {
$text = t('There are updates available for your version of Drupal. To ensure the proper functioning of your site, you should update as soon as possible.', array(), $langcode);
$text = t('There are updates available for your version of Drupal. To ensure the proper functioning of your site, you should update as soon as possible.', array(), array('langcode' => $langcode));
}
else {
$text = t('There are updates available for one or more of your modules or themes. To ensure the proper functioning of your site, you should update as soon as possible.', array(), $langcode);
$text = t('There are updates available for one or more of your modules or themes. To ensure the proper functioning of your site, you should update as soon as possible.', array(), array('langcode' => $langcode));
}
break;
......@@ -485,16 +485,16 @@ function _update_message_text($msg_type, $msg_reason, $report_link = FALSE, $lan
case UPDATE_NOT_CHECKED:
case UPDATE_NOT_FETCHED:
if ($msg_type == 'core') {
$text = t('There was a problem determining the status of available updates for your version of Drupal.', array(), $langcode);
$text = t('There was a problem determining the status of available updates for your version of Drupal.', array(), array('langcode' => $langcode));
}
else {
$text = t('There was a problem determining the status of available updates for one or more of your modules or themes.', array(), $langcode);
$text = t('There was a problem determining the status of available updates for one or more of your modules or themes.', array(), array('langcode' => $langcode));
}
break;
}
if ($report_link) {
$text .= ' ' . t('See the <a href="@available_updates">available updates</a> page for more information.', array('@available_updates' => url('admin/reports/updates', array('language' => $language))), $langcode);
$text .= ' ' . t('See the <a href="@available_updates">available updates</a> page for more information.', array('@available_updates' => url('admin/reports/updates', array('language' => $language))), array('langcode' => $langcode));
}
return $text;
......
......@@ -2084,35 +2084,35 @@ function _user_mail_text($key, $language = NULL, $variables = array()) {
// No override, return default string.
switch ($key) {
case 'register_no_approval_required_subject':
return t('Account details for !username at !site', $variables, $langcode);
return t('Account details for !username at !site', $variables, array('langcode' => $langcode));
case 'register_no_approval_required_body':
return t("!username,\n\nThank you for registering at !site. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables, $langcode);
return t("!username,\n\nThank you for registering at !site. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables, array('langcode' => $langcode));
case 'register_admin_created_subject':
return t('An administrator created an account for you at !site', $variables, $langcode);
return t('An administrator created an account for you at !site', $variables, array('langcode' => $langcode));
case 'register_admin_created_body':
return t("!username,\n\nA site administrator at !site has created an account for you. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables, $langcode);
return t("!username,\n\nA site administrator at !site has created an account for you. You may now log in to !login_uri using the following username and password:\n\nusername: !username\npassword: !password\n\nYou may also log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\n\n-- !site team", $variables, array('langcode' => $langcode));
case 'register_pending_approval_subject':
case 'register_pending_approval_admin_subject':
return t('Account details for !username at !site (pending admin approval)', $variables, $langcode);
return t('Account details for !username at !site (pending admin approval)', $variables, array('langcode' => $langcode));
case 'register_pending_approval_body':
return t("!username,\n\nThank you for registering at !site. Your application for an account is currently pending approval. Once it has been approved, you will receive another e-mail containing information about how to log in, set your password, and other details.\n\n\n-- !site team", $variables, $langcode);
return t("!username,\n\nThank you for registering at !site. Your application for an account is currently pending approval. Once it has been approved, you will receive another e-mail containing information about how to log in, set your password, and other details.\n\n\n-- !site team", $variables, array('langcode' => $langcode));
case 'register_pending_approval_admin_body':
return t("!username has applied for an account.\n\n!edit_uri", $variables, $langcode);
return t("!username has applied for an account.\n\n!edit_uri", $variables, array('langcode' => $langcode));
case 'password_reset_subject':
return t('Replacement login information for !username at !site', $variables, $langcode);
return t('Replacement login information for !username at !site', $variables, array('langcode' => $langcode));
case 'password_reset_body':
return t("!username,\n\nA request to reset the password for your account has been made at !site.\n\nYou may now log in to !uri_brief by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once. It expires after one day and nothing will happen if it's not used.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.", $variables, $langcode);
return t("!username,\n\nA request to reset the password for your account has been made at !site.\n\nYou may now log in to !uri_brief by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once. It expires after one day and nothing will happen if it's not used.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.", $variables, array('langcode' => $langcode));
case 'status_activated_subject':
return t('Account details for !username at !site (approved)', $variables, $langcode);
return t('Account details for !username at !site (approved)', $variables, array('langcode' => $langcode));
case 'status_activated_body':
return t("!username,\n\nYour account at !site has been activated.\n\nYou may now log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\nOnce you have set your own password, you will be able to log in to !login_uri in the future using:\n\nusername: !username\n", $variables, $langcode);
return t("!username,\n\nYour account at !site has been activated.\n\nYou may now log in by clicking on this link or copying and pasting it in your browser:\n\n!login_url\n\nThis is a one-time login, so it can be used only once.\n\nAfter logging in, you will be redirected to !edit_uri so you can change your password.\n\nOnce you have set your own password, you will be able to log in to !login_uri in the future using:\n\nusername: !username\n", $variables, array('langcode' => $langcode));
case 'status_blocked_subject':
return t('Account details for !username at !site (blocked)', $variables, $langcode);
return t('Account details for !username at !site (blocked)', $variables, array('langcode' => $langcode));
case 'status_blocked_body':
return t("!username,\n\nYour account on !site has been blocked.", $variables, $langcode);
return t("!username,\n\nYour account on !site has been blocked.", $variables, array('langcode' => $langcode));
case 'cancel_confirm_subject':
return t('Account cancellation request for !username at !site', $variables, $langcode);
return t('Account cancellation request for !username at !site', $variables, array('langcode' => $langcode));
case 'cancel_confirm_body':
return t("!username,
......@@ -2124,14 +2124,14 @@ function _user_mail_text($key, $language = NULL, $variables = array()) {
NOTE: The cancellation of your account is not reversible.
This link expires in one day and nothing will happen if it is not used.", $variables, $langcode);
This link expires in one day and nothing will happen if it is not used.", $variables, array('langcode' => $langcode));
case 'status_canceled_subject':
return t('Account details for !username at !site (canceled)', $variables, $langcode);
return t('Account details for !username at !site (canceled)', $variables, array('langcode' => $langcode));
case 'status_canceled_body':
return t("!username,
Your account on !site has been canceled.", $variables, $langcode);
Your account on !site has been canceled.", $variables, array('langcode' => $langcode));
}
}
}
......