Skip to content

Commit

Permalink
Merge pull request #2408 from drshawnkwang/drupal_fix-prefxmltrim
Browse files Browse the repository at this point in the history
Drupal: Trim strings in project-specific XML to help translators.
  • Loading branch information
tristanolive committed Mar 15, 2018
2 parents 8c7c645 + 9a7627c commit 20b634b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
Expand Up @@ -1390,4 +1390,18 @@ function _boinctranslate_filter_tips_long() {
<p>The editor/admin may add as many of these tokens as you wish. You may add and remove them at your discretion. It is permitted for a page as no tokens, as the entire content will be a single chunk- such as for a shorter page.</p>
");
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Misc utility/helper functions
* * * * * * * * * * * * * * * * * * * * * * * * * * * */

/**
* Split a string by newline, and trim each line, implode back into a
* string. Used for cleaning whitespace title & description elements
* from project preferences XML upload before adding to translation
* database.
*/
function _boinctranslate_supertrim($instr) {
return implode("\n", array_map('trim', preg_split('/\r\n|\r|\n/', $instr) ) );
}
Expand Up @@ -407,12 +407,12 @@ function boincwork_generate_prefs_element(&$form, $type, $elements, $user_prefs

// Translate elements as appropriate
if ($title) {
i18nstrings_update('project:prefs_xml', $title);
$title = i18nstrings('project:prefs_xml', $title);
i18nstrings_update('project:prefs_xml', _boinctranslate_supertrim($title));
$title = i18nstrings('project:prefs_xml', _boinctranslate_supertrim($title));
}
if ($description) {
i18nstrings_update('project:prefs_xml', $description);
$description = i18nstrings('project:prefs_xml', $description);
i18nstrings_update('project:prefs_xml', _boinctranslate_supertrim($description));
$description = i18nstrings('project:prefs_xml', _boinctranslate_supertrim($description));
}

$form[$name] = array(
Expand Down Expand Up @@ -455,12 +455,12 @@ function boincwork_generate_prefs_element(&$form, $type, $elements, $user_prefs

// Translate elements as appropriate
if ($title) {
i18nstrings_update('project:prefs_xml', $title);
$title = i18nstrings('project:prefs_xml', $title);
i18nstrings_update('project:prefs_xml', _boinctranslate_supertrim($title));
$title = i18nstrings('project:prefs_xml', _boinctranslate_supertrim($title));
}
if ($description) {
i18nstrings_update('project:prefs_xml', $description);
$description = i18nstrings('project:prefs_xml', $description);
i18nstrings_update('project:prefs_xml', _boinctranslate_supertrim($description));
$description = i18nstrings('project:prefs_xml', _boinctranslate_supertrim($description));
}

$form[$name] = array(
Expand Down Expand Up @@ -512,12 +512,12 @@ function boincwork_generate_prefs_element(&$form, $type, $elements, $user_prefs

// Translate elements as appropriate
if ($title) {
i18nstrings_update('project:prefs_xml', $title);
$title = i18nstrings('project:prefs_xml', $title);
i18nstrings_update('project:prefs_xml', _boinctranslate_supertrim($title));
$title = i18nstrings('project:prefs_xml', _boinctranslate_supertrim($title));
}
if ($description) {
i18nstrings_update('project:prefs_xml', $description);
$description = i18nstrings('project:prefs_xml', $description);
i18nstrings_update('project:prefs_xml', _boinctranslate_supertrim($description));
$description = i18nstrings('project:prefs_xml', _boinctranslate_supertrim($description));
}

$form[$name] = array(
Expand All @@ -536,8 +536,8 @@ function boincwork_generate_prefs_element(&$form, $type, $elements, $user_prefs

// Translate elements as appropriate
if ($title) {
i18nstrings_update('project:prefs_xml', $title);
$title = i18nstrings('project:prefs_xml', $title);
i18nstrings_update('project:prefs_xml', _boinctranslate_supertrim($title));
$title = i18nstrings('project:prefs_xml', _boinctranslate_supertrim($title));
}

$form['applications'] = array(
Expand Down Expand Up @@ -596,8 +596,8 @@ function boincwork_generate_prefs_element(&$form, $type, $elements, $user_prefs

// Translate elements as appropriate
if ($title) {
i18nstrings_update('project:prefs_xml', $title);
$title = i18nstrings('project:prefs_xml', $title);
i18nstrings_update('project:prefs_xml', _boinctranslate_supertrim($title));
$title = i18nstrings('project:prefs_xml', _boinctranslate_supertrim($title));
}

$form[$name] = array(
Expand Down Expand Up @@ -625,8 +625,8 @@ function boincwork_generate_prefs_element(&$form, $type, $elements, $user_prefs

// Translate elements as appropriate
if ($title) {
i18nstrings_update('project:prefs_xml', $title);
$title = i18nstrings('project:prefs_xml', $title);
i18nstrings_update('project:prefs_xml', _boinctranslate_supertrim($title));
$title = i18nstrings('project:prefs_xml', _boinctranslate_supertrim($title));
}

$form[$name] = array(
Expand Down Expand Up @@ -1113,7 +1113,6 @@ function boincwork_format_stats($number, $max_digits = 4) {
return $number;
}


//------------------------------------------------------------------------------------------------
// load_configuration(): Convert structured text/xml to array
//------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 20b634b

Please sign in to comment.