Development BlogReplacing core language in an extension

Post Reply
User avatar
Topic Starter
Restless Rancor
Great Britain

Site Admin
New Member
Posts: 48
Joined: October 15th, 2018, 3:14 pm
Age: 25
Location: Hampshire, England
Contact:

Replacing core language in an extension

#1

Post by Restless Rancor » October 23rd, 2018, 4:15 pm

My Attachment Shields Extension requires the change of two core language arrays:

Code: Select all

'DOWNLOAD_COUNTS'		=> array(
	0	=> 'Not downloaded yet',
	1	=> 'Downloaded %d time',
	2	=> 'Downloaded %d times',
),
...
'VIEWED_COUNTS'		=> array(
	0	=> 'Not viewed yet',
	1	=> 'Viewed %d time',
	2	=> 'Viewed %d times',
),
to:

Code: Select all

	
'DOWNLOAD_COUNTS'		=> array(
	0	=> '0',
	1	=> '%d',
	2	=> '%d',
),
...
'VIEWED_COUNTS'		=> array(
	0	=> '0',
	1	=> '%d',
	2	=> '%d',
),
This is purely a cosmetic preference for the badge outcome.

The default would look like this: Image
But I want it to look like this: Image

In the snippet you just change the core language file, but I ran into trouble trying to get the extension to ignore the core language and use my own.

It was easy enough to set the language files up and I could test some new variables, but I needed an event, specifically core.viewtopic_modify_post_row.

And then it's as simple as adding the language:

Code: Select all

public function add_language()
{
	$this->language->add_lang('common', 'restlessrancor/attachmentshields');
}
The same method can be applied elsewhere, so I'm sure this will come in handy in future projects.


These aren't the droids you're looking for.

User avatar
Topic Starter
Restless Rancor
Great Britain

Site Admin
New Member
Posts: 48
Joined: October 15th, 2018, 3:14 pm
Age: 25
Location: Hampshire, England
Contact:

#2

Post by Restless Rancor » October 25th, 2018, 4:00 pm

I was using two functions to insert the language, which was not necessary, and as it turns out my original method of using core.user_setup was what worked. I'm sure I've missed something vital somewhere (I blame the flu...) but am running with that function for now as I only need one of the two and that's the one that's working right now.

I think when I added the add_language() function I also made some changes which fixed the original language and the add_language() function wasn't what got it to work. I'll get to the bottom of this another day when I'm feeling 100% :roll:
These aren't the droids you're looking for.

User avatar
Topic Starter
Restless Rancor
Great Britain

Site Admin
New Member
Posts: 48
Joined: October 15th, 2018, 3:14 pm
Age: 25
Location: Hampshire, England
Contact:

#3

Post by Restless Rancor » October 26th, 2018, 12:42 pm

I knew I was missing something obvious. I was using the wrong event:

Code: Select all

public static function getSubscribedEvents()
{
    return array(
        'core.viewtopic_post_rowset_data' => 'add_language',
    );
}

public function add_language()
{
    $this->language->add_lang('common', 'restlessrancor/attachmentshields');
}
This works without having to use the core.user_setup event.
These aren't the droids you're looking for.

Post Reply

Topic Subscribers

1 user subscribed to this topic: Restless Rancor