[glotpress-updates] [GlotPress] #97: Glossary
GlotPress
noreply at wordpress.org
Tue Feb 18 14:02:33 UTC 2014
#97: Glossary
--------------------------+----------------------
Reporter: nbachiyski | Owner: yoavf
Type: enhancement | Status: assigned
Priority: minor | Milestone: 1.0
Component: general | Version:
Resolution: | Keywords:
--------------------------+----------------------
Comment (by yoavf):
Here's the bulk of the (in progress) code responsible for the above
screenshot:
{{{
function map_glossary_entries_to_translations_originals( $translations,
$glossary ) {
$glossary_entries = GP::$glossary_entry->by_glossary_id(
$glossary->id );
$glossary_entries_terms = array();
foreach ( $glossary_entries as $key => $value ) {
$glossary_entries_terms[ $key ] = mb_strtolower(
$value->term );
}
// Longer strings first
uasort( $glossary_entries_terms, function ($a, $b){ return
mb_strlen($a) < mb_strlen($b); } );
foreach ( $translations as $key => $t ) {
$translations[$key]->singular_glossary_markup =
esc_translation( $t->singular );
if ( $t->plural ) {
$translations[$key]->plural_glossary_markup =
esc_translation( $t->plural );
}
foreach( $glossary_entries_terms as $i => $term ) {
$glossary_entry = $glossary_entries[ $i ];
$replacement = '<span class="glossary-word" data-
translation="' . esc_js( $glossary_entry->translation ) . '" data-
comment="' . esc_attr( $glossary_entry->comment ) . '">$1</span>';
$translations[$key]->singular_glossary_markup =
preg_replace( '/\b(' . $term . ')(?![^<]*<\/span>)/iu', $replacement,
$translations[$key]->singular_glossary_markup );
if ( $t->plural ) {
$translations[$key]->plural_glossary_markup = preg_replace( '/\b(' . $term
. ')(?![^<]*<\/span>)/iu', $replacement,
$translations[$key]->plural_glossary_markup );
}
}
}
return $translations;
}
}}}
--
Ticket URL: <https://glotpress.trac.wordpress.org/ticket/97#comment:39>
GlotPress <https://glotpress.trac.wordpress.org>
Easy comin', easy goin'
More information about the glotpress-updates
mailing list