Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Any way to modify a definition in the locale on the fly?

peregrineperegrine MVP
edited March 2012 in Vanilla 2.0 - 2.8

I've got a plugin where I am rewriting the line on the discussions page, it works fine but:

public function DiscussionsController_AfterCountMeta_Handler(&$Sender) {
    $Discussion = $Sender->EventArguments['Discussion'];
    $First = UserBuilder($Discussion, 'First');
    $Last = UserBuilder($Discussion, 'Last');

    if ($Discussion->LastCommentID != '') {
        echo '<span class="LastCommentBy">'.sprintf(T(' %1$s'), UserAnchor($First)).'</span>';
        echo '<span class="AuthorDate">'.Gdn_Format::Date($Discussion->FirstDate).'</span>';
        echo '<span class="LastCommentBy">'.sprintf(T('| Recent %1$s'), UserAnchor($Last)).'</span>';

    } else {
        echo '<span class="LastCommentBy">'.sprintf(T(' Started by %1$s'), UserAnchor($First)).'</span>';
    }
    return;
}

public function CategoriesController_DiscussionMeta_Handler(&$Sender) {
    $this->DiscussionsController_DiscussionMeta_Handler($Sender);
}

e.g.
 5 comments Most recent by Lincoln March 7

to: 
4 comments  Peregrine  February 18| Recent Lincoln March 7

where
"Peregrine and February 18" are the original author of discussion and start date of discussion
and "Recent Lincoln" replaces "Most recent by Lincoln".

I've manged to do this by creating a new locale that changes the definitions like so,
to remove the old definitions.

$Definition['Most recent by %1$s']='';
$Definition['Started by %1$s']='';

My question is there a way to do one of two things
1) change the definitions from the plugin on the fly.
or
2) write the definitions from the plugin itself without having to create a new locale just for two definitions.

Currently it is a two step processor.

Another entirely different option - I could also do some improvisation with jquery and change the text and html in the class, but it doesn't seem like the ideal way to go.

I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Best Answer

  • Options
    LincLinc Detroit Admin
    Answer ✓

    You can drop those $Definitions into a new file named /conf/locale.php and it will automatically override whatever locale you're using. That's how I hack definitions on the fly. :)

Answers

  • Options
    jspautschjspautsch Themester ✭✭✭

    Try this:

    Gdn::Locale()->SetTranslation('Old text', T('New text'));
  • Options
    LincLinc Detroit Admin
    Answer ✓

    You can drop those $Definitions into a new file named /conf/locale.php and it will automatically override whatever locale you're using. That's how I hack definitions on the fly. :)

  • Options

    Thanks much. I gave Lincoln's mod a try and worked great. Will try jspautsch's mod later, may prove useful for some other things I am trying.

    Would it be worth posting this as a plugin add-on and if I don't want to have an e-mail associated with the plugin can you do that.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.