diff --git a/includes/locale.inc b/includes/locale.inc index 4c52b9cc93269a823330fd9b0ec05eff16bfefb0..48351c12ffed0e6c2dfad0c389d19c971ffc1179 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -678,27 +678,33 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL 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; } diff --git a/modules/locale/locale.admin.inc b/modules/locale/locale.admin.inc index f938838661cacb20e551b2f45af74cca5aa94702..1422790f49631ee3b0f5078150c8be41f8dac155 100644 --- a/modules/locale/locale.admin.inc +++ b/modules/locale/locale.admin.inc @@ -962,8 +962,8 @@ function locale_translate_import_form($form) { '#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')); diff --git a/modules/locale/locale.test b/modules/locale/locale.test index d9c638671691165c3e9b1359ad109951f1369c9a..346dcc918d38c7959b870cf753c4579e5de434d8 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -613,6 +613,9 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { // 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 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { $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 @@ class LocaleImportFunctionalTest extends DrupalWebTestCase { ); $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 @@ msgstr "" "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" diff --git a/modules/rdf/rdf.module b/modules/rdf/rdf.module index 48e31c08386b3b1ecd1108e12f0be5e27a7cf099..97d3c33bf67280b7ae228d9860e06b33f175103d 100644 --- a/modules/rdf/rdf.module +++ b/modules/rdf/rdf.module @@ -668,6 +668,24 @@ function rdf_preprocess_comment(&$variables) { } } +/** + * 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(). */ diff --git a/modules/rdf/rdf.test b/modules/rdf/rdf.test index 5c487403aae59ee1fbcced1bbcffa20489e2a47a..85dac897083abf1022e147a1b243c05b0a9e5a59 100644 --- a/modules/rdf/rdf.test +++ b/modules/rdf/rdf.test @@ -332,6 +332,21 @@ class RdfMappingDefinitionTestCase extends DrupalWebTestCase { $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.')); + } }