summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-03-10 14:23:32 +0000
committerDries Buytaert <dries@buytaert.net>2010-03-10 14:23:32 +0000
commit61569498046f531db5d06ad48009d69c59ccd26b (patch)
tree1417066fb91a276f4c621e3ba9dc2cb3bcfa8c20
parent76cdb8547897a94978f979e9014d925ffe64c1c9 (diff)
downloadbrdo-61569498046f531db5d06ad48009d69c59ccd26b.tar.gz
brdo-61569498046f531db5d06ad48009d69c59ccd26b.tar.bz2
- Patch #566390 by Gábor Hojtsy, Jose Reyero: apply locale import protection to the plural forms.
-rw-r--r--includes/locale.inc48
-rw-r--r--modules/locale/locale.admin.inc4
-rw-r--r--modules/locale/locale.test9
-rw-r--r--modules/rdf/rdf.module18
-rw-r--r--modules/rdf/rdf.test15
5 files changed, 70 insertions, 24 deletions
diff --git a/includes/locale.inc b/includes/locale.inc
index 4c52b9cc9..48351c12f 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 f93883866..1422790f4 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 d9c638671..346dcc918 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 48e31c083..97d3c33bf 100644
--- a/modules/rdf/rdf.module
+++ b/modules/rdf/rdf.module
@@ -669,6 +669,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().
*/
function rdf_field_attach_view_alter(&$output, $context) {
diff --git a/modules/rdf/rdf.test b/modules/rdf/rdf.test
index 5c487403a..85dac8970 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.'));
+ }
}