Commit 339496 by dries
- Patch #566390 by Gábor Hojtsy, Jose Reyero: apply locale import protection to the plural forms.
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/locale.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/locale.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/locale.inc</a> 2010/03/07 07:44:18 1.249
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/locale.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/locale.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/locale.inc</a> 2010/03/10 14:23:31 1.250
@@ -678,27 +678,33 @@
case 'db-store':
// We got header information.
if ($value['msgid'] == '') {
- $header = _locale_import_parse_header($value['msgstr']);
-
- // Get the plural formula and update in database.
- if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->uri)) {
- list($nplurals, $plural) = $p;
- db_update('languages')
- ->fields(array(
- 'plurals' => $nplurals,
- 'formula' => $plural,
- ))
- ->condition('language', $lang)
- ->execute();
- }
- else {
- db_update('languages')
- ->fields(array(
- 'plurals' => 0,
- 'formula' => '',
- ))
- ->condition('language', $lang)
- ->execute();
+ $languages = language_list();
+ if (($mode != LOCALE_IMPORT_KEEP) || empty($languages[$lang]->plurals)) {
+ // Since we only need to parse the header if we ought to update the
+ // plural formula, only run this if we don't need to keep existing
+ // data untouched or if we don't have an existing plural formula.
+ $header = _locale_import_parse_header($value['msgstr']);
+
+ // Get the plural formula and update in database.
+ if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->uri)) {
+ list($nplurals, $plural) = $p;
+ db_update('languages')
+ ->fields(array(
+ 'plurals' => $nplurals,
+ 'formula' => $plural,
+ ))
+ ->condition('language', $lang)
+ ->execute();
+ }
+ else {
+ db_update('languages')
+ ->fields(array(
+ 'plurals' => 0,
+ 'formula' => '',
+ ))
+ ->condition('language', $lang)
+ ->execute();
+ }
}
$header_done = TRUE;
}
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc" title="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc</a> 2010/03/07 07:44:18 1.6
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc" title="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc</a> 2010/03/10 14:23:31 1.7
@@ -962,8 +962,8 @@
'#title' => t('Mode'),
'#default_value' => LOCALE_IMPORT_KEEP,
'#options' => array(
- LOCALE_IMPORT_OVERWRITE => t('Strings in the uploaded file replace existing ones, new ones are added'),
- LOCALE_IMPORT_KEEP => t('Existing strings are kept, only new strings are added')
+ LOCALE_IMPORT_OVERWRITE => t('Strings in the uploaded file replace existing ones, new ones are added. The plural format is updated.'),
+ LOCALE_IMPORT_KEEP => t('Existing strings and the plural format are kept, only new strings are added.')
),
);
$form['import']['submit'] = array('#type' => 'submit', '#value' => t('Import'));
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test" title="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test</a> 2010/03/07 18:52:27 1.65
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test" title="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test</a> 2010/03/10 14:23:31 1.66
@@ -613,6 +613,9 @@
// The import should have created 7 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' => 7, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.'));
+ // This import should have saved plural forms to have 2 variants.
+ $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, t('Plural number initialized.'));
+
// Ensure we were redirected correctly.
$this->assertEqual($this->getUrl(), url('admin/config/regional/translate', array('absolute' => TRUE)), t('Correct page redirection.'));
@@ -668,6 +671,8 @@
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertText(t('No strings available.'), t('String not overwritten by imported string.'));
+ // This import should not have changed number of plural forms.
+ $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, t('Plural numbers untouched.'));
// Try importing a .po file with overriding strings, and ensure existing
// strings are overwritten.
@@ -687,6 +692,8 @@
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertNoText(t('No strings available.'), t('String overwritten by imported string.'));
+ // This import should have changed number of plural forms.
+ $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 3, t('Plural numbers changed.'));
}
/**
@@ -831,7 +838,7 @@
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
-"Plural-Forms: nplurals=2; plural=(n > 1);\\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"
msgid "Monday"
msgstr "Montag"
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module" title="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module</a> 2010/03/07 07:08:41 1.30
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module" title="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module</a> 2010/03/10 14:23:32 1.31
@@ -669,6 +669,24 @@
}
/**
+ * Implements MODULE_preprocess_HOOK().
+ */
+function rdf_preprocess_taxonomy_term(&$variables) {
+ // Adds the RDF type of the term and the term name in a meta tag.
+ $term = $variables['term'];
+ $term_label_meta = array(
+ '#tag' => 'meta',
+ '#attributes' => array(
+ 'about' => url('taxonomy/term/' . $term->tid),
+ 'typeof' => $term->rdf_mapping['rdftype'],
+ 'property' => $term->rdf_mapping['name']['predicates'],
+ 'content' => $term->name,
+ ),
+ );
+ drupal_add_html_head($term_label_meta, 'rdf_term_label');
+}
+
+/**
* Implements hook_field_attach_view_alter().
*/
function rdf_field_attach_view_alter(&$output, $context) {
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test" title="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test</a> 2010/03/03 17:06:42 1.15
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test" title="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test</a> 2010/03/10 14:23:32 1.16
@@ -332,6 +332,21 @@
$author_about = $this->xpath("//a[@typeof='sioc:User' and @about='$account_uri' and @property='foaf:name' and contains(@xml:lang, '')]");
$this->assertTrue(!empty($author_about), t('RDFa markup found on author information on post. xml:lang on username is set to empty string.'));
}
+
+ /**
+ * Creates a random term and ensures the right RDFa markup is used.
+ */
+ function testTaxonomyTermRdfaAttributes() {
+ $vocabulary = TaxonomyWebTestCase::createVocabulary();
+ $term = TaxonomyWebTestCase::createTerm($vocabulary);
+
+ // Views the term and checks that the RDFa markup is correct.
+ $this->drupalGet('taxonomy/term/' . $term->tid);
+ $term_url = url('taxonomy/term/' . $term->tid);
+ $term_name = $term->name;
+ $term_rdfa_meta = $this->xpath("//meta[@typeof='skos:Concept' and @about='$term_url' and contains(@property, 'rdfs:label') and contains(@property, 'skos:prefLabel') and @content='$term_name']");
+ $this->assertTrue(!empty($term_rdfa_meta), t('RDFa markup found on term page.'));
+ }
}
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/locale.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/locale.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/locale.inc</a> 2010/03/10 14:23:31 1.250
@@ -678,27 +678,33 @@
case 'db-store':
// We got header information.
if ($value['msgid'] == '') {
- $header = _locale_import_parse_header($value['msgstr']);
-
- // Get the plural formula and update in database.
- if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->uri)) {
- list($nplurals, $plural) = $p;
- db_update('languages')
- ->fields(array(
- 'plurals' => $nplurals,
- 'formula' => $plural,
- ))
- ->condition('language', $lang)
- ->execute();
- }
- else {
- db_update('languages')
- ->fields(array(
- 'plurals' => 0,
- 'formula' => '',
- ))
- ->condition('language', $lang)
- ->execute();
+ $languages = language_list();
+ if (($mode != LOCALE_IMPORT_KEEP) || empty($languages[$lang]->plurals)) {
+ // Since we only need to parse the header if we ought to update the
+ // plural formula, only run this if we don't need to keep existing
+ // data untouched or if we don't have an existing plural formula.
+ $header = _locale_import_parse_header($value['msgstr']);
+
+ // Get the plural formula and update in database.
+ if (isset($header["Plural-Forms"]) && $p = _locale_import_parse_plural_forms($header["Plural-Forms"], $file->uri)) {
+ list($nplurals, $plural) = $p;
+ db_update('languages')
+ ->fields(array(
+ 'plurals' => $nplurals,
+ 'formula' => $plural,
+ ))
+ ->condition('language', $lang)
+ ->execute();
+ }
+ else {
+ db_update('languages')
+ ->fields(array(
+ 'plurals' => 0,
+ 'formula' => '',
+ ))
+ ->condition('language', $lang)
+ ->execute();
+ }
}
$header_done = TRUE;
}
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc" title="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc</a> 2010/03/07 07:44:18 1.6
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc" title="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.admin.inc</a> 2010/03/10 14:23:31 1.7
@@ -962,8 +962,8 @@
'#title' => t('Mode'),
'#default_value' => LOCALE_IMPORT_KEEP,
'#options' => array(
- LOCALE_IMPORT_OVERWRITE => t('Strings in the uploaded file replace existing ones, new ones are added'),
- LOCALE_IMPORT_KEEP => t('Existing strings are kept, only new strings are added')
+ LOCALE_IMPORT_OVERWRITE => t('Strings in the uploaded file replace existing ones, new ones are added. The plural format is updated.'),
+ LOCALE_IMPORT_KEEP => t('Existing strings and the plural format are kept, only new strings are added.')
),
);
$form['import']['submit'] = array('#type' => 'submit', '#value' => t('Import'));
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test" title="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test</a> 2010/03/07 18:52:27 1.65
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test" title="http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/locale/locale.test</a> 2010/03/10 14:23:31 1.66
@@ -613,6 +613,9 @@
// The import should have created 7 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' => 7, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.'));
+ // This import should have saved plural forms to have 2 variants.
+ $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, t('Plural number initialized.'));
+
// Ensure we were redirected correctly.
$this->assertEqual($this->getUrl(), url('admin/config/regional/translate', array('absolute' => TRUE)), t('Correct page redirection.'));
@@ -668,6 +671,8 @@
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertText(t('No strings available.'), t('String not overwritten by imported string.'));
+ // This import should not have changed number of plural forms.
+ $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 2, t('Plural numbers untouched.'));
// Try importing a .po file with overriding strings, and ensure existing
// strings are overwritten.
@@ -687,6 +692,8 @@
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertNoText(t('No strings available.'), t('String overwritten by imported string.'));
+ // This import should have changed number of plural forms.
+ $this->assert(db_query("SELECT plurals FROM {languages} WHERE language = 'fr'")->fetchField() == 3, t('Plural numbers changed.'));
}
/**
@@ -831,7 +838,7 @@
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
-"Plural-Forms: nplurals=2; plural=(n > 1);\\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"
msgid "Monday"
msgstr "Montag"
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module" title="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module</a> 2010/03/07 07:08:41 1.30
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module" title="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.module</a> 2010/03/10 14:23:32 1.31
@@ -669,6 +669,24 @@
}
/**
+ * Implements MODULE_preprocess_HOOK().
+ */
+function rdf_preprocess_taxonomy_term(&$variables) {
+ // Adds the RDF type of the term and the term name in a meta tag.
+ $term = $variables['term'];
+ $term_label_meta = array(
+ '#tag' => 'meta',
+ '#attributes' => array(
+ 'about' => url('taxonomy/term/' . $term->tid),
+ 'typeof' => $term->rdf_mapping['rdftype'],
+ 'property' => $term->rdf_mapping['name']['predicates'],
+ 'content' => $term->name,
+ ),
+ );
+ drupal_add_html_head($term_label_meta, 'rdf_term_label');
+}
+
+/**
* Implements hook_field_attach_view_alter().
*/
function rdf_field_attach_view_alter(&$output, $context) {
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test" title="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test</a> 2010/03/03 17:06:42 1.15
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test" title="http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/rdf/rdf.test</a> 2010/03/10 14:23:32 1.16
@@ -332,6 +332,21 @@
$author_about = $this->xpath("//a[@typeof='sioc:User' and @about='$account_uri' and @property='foaf:name' and contains(@xml:lang, '')]");
$this->assertTrue(!empty($author_about), t('RDFa markup found on author information on post. xml:lang on username is set to empty string.'));
}
+
+ /**
+ * Creates a random term and ensures the right RDFa markup is used.
+ */
+ function testTaxonomyTermRdfaAttributes() {
+ $vocabulary = TaxonomyWebTestCase::createVocabulary();
+ $term = TaxonomyWebTestCase::createTerm($vocabulary);
+
+ // Views the term and checks that the RDFa markup is correct.
+ $this->drupalGet('taxonomy/term/' . $term->tid);
+ $term_url = url('taxonomy/term/' . $term->tid);
+ $term_name = $term->name;
+ $term_rdfa_meta = $this->xpath("//meta[@typeof='skos:Concept' and @about='$term_url' and contains(@property, 'rdfs:label') and contains(@property, 'skos:prefLabel') and @content='$term_name']");
+ $this->assertTrue(!empty($term_rdfa_meta), t('RDFa markup found on term page.'));
+ }
}