Skip to content

Commit

Permalink
Drupal: Trim strings in project-specific XML to help translators.
Browse files Browse the repository at this point in the history
Add custom trim function to code where the strings in the project-specific XML are aded to translation table(s).
Custom function removes whitespace from beginning and end of each line, separated by newline.

https://dev.gridrepublic.org/browse/DBOINCP-418
  • Loading branch information
Shawn Kwang committed Mar 14, 2018
1 parent bb695bb commit 9a7627c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
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) ) );
}
Original file line number Diff line number Diff line change
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 9a7627c

Please sign in to comment.