Commit 61569498 authored by Dries's avatar Dries

- Patch #566390 by Gábor Hojtsy, Jose Reyero: apply locale import protection to the plural forms.

parent 76cdb854
......@@ -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;
}
......
......@@ -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'));
......
......@@ -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"
......
......@@ -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().
*/
......
......@@ -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.'));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment