load language variables

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Meis2M
Translator
Posts: 816
Joined: Wed Mar 03, 2010 11:32 am
Location: IR.Damghan
Name: میثم نوبری
Contact:

load language variables

Post by Meis2M » Sun Jun 10, 2018 11:26 am

Hello

is main_listener.php duty load language?

i have a problem with load language variables my event/main_listener.php is

Code: Select all

<?php
/**
*
* @package phpBB Extension - AJAX Advanced Forum Stats
* @copyright (c) 2018 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace meis2m\aafs\event;
/**
* @ignore
*/
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Event listener
*/
class main_listener implements EventSubscriberInterface
{
	static public function getSubscribedEvents()
	{
		return array(
			'core.user_setup'	=> 'load_language_on_setup',
		);
	}
	/* @var \phpbb\controller\helper */
	protected $helper;
	/* @var \phpbb\template\template */
	protected $template;
	/**
	* Constructor
	*
	* @param \phpbb\controller\helper	$helper		Controller helper object
	* @param \phpbb\template\template	$template	Template object
	*/
	public function __construct(\phpbb\controller\helper $helper, \phpbb\template\template $template)
	{
		$this->helper = $helper;
		$this->template = $template;
	}
	public function load_language_on_setup($event)
	{
		$lang_set_ext = $event['lang_set_ext'];
		$lang_set_ext[] = array(
			'ext_name' => 'meis2m/aafs',
			'lang_set' => 'common',
		);
		$event['lang_set_ext'] = $lang_set_ext;
	}

}
but in .htmls files the languages variables not working yet, what is missed?

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1835
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: load language variables

Post by kinerity » Sun Jun 10, 2018 1:49 pm

Are you sure your language file has the language variables that the HTML file uses?
Kailey Truscott - Community Team

User avatar
Meis2M
Translator
Posts: 816
Joined: Wed Mar 03, 2010 11:32 am
Location: IR.Damghan
Name: میثم نوبری
Contact:

Re: load language variables

Post by Meis2M » Sun Jun 10, 2018 1:52 pm

this is my service

Code: Select all

services:
    meis2m.aafs.controller:
        class: meis2m\aafs\controller\main
        arguments:
            - '@config'
            - '@controller.helper'
            - '@template'
            - '@user'
    meis2m.aafs.listener:
        class: meis2m\aafs\event\main_listener
        arguments:
            - '@controller.helper'
            - '@template'

and it is part of my html:

Code: Select all

<tr align="top"><th colspan="2" align="left">{L_TFORUM_STATS}</th></tr>
and language file:

Code: Select all

<?php

if (!defined('IN_PHPBB'))
{
	exit;
}

if (empty($lang) || !is_array($lang))
{
	$lang = array();
}

$lang = array_merge($lang, array(
	'TFORUM_STATS'	=> 'Forum Stats',
	'TNEWEST_MEM'	=> 'Newest Member',
	'TTOP_THANKED'	=> 'Top Thanked',
	'TTOP_POSTER'	=> 'Top Poster',
	'TNEW_THREAD'	=> 'Latest Post',
	'TMOST_VIEW'	=> 'Most Viewed',
	'THOT_TOPIC'	=> 'Hotest Thread',
	 'NEWEST_TOPICS'		=> 'Newest topic',
	'ACTIVE_MEM'	=> 'Top poster',
    'NEWEST_MEM'	=> 'Newest member',
	'BY'                => 'by',
	'VIEWS'		=> 'Views',
	'REPLY'		=> 'Reply',
	'THANKED'		=> 'Thanked',
	'TOPICS'		=> 'Topic',
	'REGDATE'		=> 'Date',
	'POSTER'		=> 'Author',
	'LATEST_POSTER'		=> 'Last reply',
	'LATEST_POST_TIME'	=> 'Last post time',
	'POST_TIME'		=> 'Post time',
	'TIMES'			=> 'times',
));

?>
it seems every thing is ok

User avatar
kinerity
Community Team Member
Community Team Member
Posts: 1835
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Truscott
Contact:

Re: load language variables

Post by kinerity » Sun Jun 10, 2018 1:56 pm

You're missing the tags part for your listener. See https://github.com/kinerity/trackers/bl ... ml#L26-L33

Also, if you are not using the helper and template objects, you can remove them.
Kailey Truscott - Community Team

User avatar
Meis2M
Translator
Posts: 816
Joined: Wed Mar 03, 2010 11:32 am
Location: IR.Damghan
Name: میثم نوبری
Contact:

Re: load language variables

Post by Meis2M » Sun Jun 10, 2018 2:17 pm

Thank you...

my service is now

Code: Select all

services:
    meis2m.aafs.controller:
        class: meis2m\aafs\controller\main
        arguments:
            - '@config'
            - '@controller.helper'
            - '@template'
            - '@user'
    meis2m.aafs.listener:
        class: meis2m\aafs\event\main_listener
        arguments:
            - '@service_container'
            - '@controller.helper'
            - '@template'
        tags:
- { name: event.listener }
    
but i have this error:



phpBB encountered an error building the container due to an installed extension. For this reason, all extensions have been temporarily disabled. Please try purging your forum cache. All extensions will automatically be re-enabled once the container error is resolved. If this error continues, please visit phpBB.com for support.

Code: Select all

Exception: The file "C:\xampp\htdocs\phpbb\phpBB3\ext\meis2m\aafs\config\services.yml" does not contain valid YAML.

#0 C:\xampp\htdocs\phpbb\phpBB3\vendor\symfony\dependency-injection\Loader\YamlFileLoader.php(44): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->loadFile('C:\\xampp\\htdocs...')
#1 C:\xampp\htdocs\phpbb\phpBB3\phpbb\extension\di\extension_base.php(99): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->load('services.yml')
#2 C:\xampp\htdocs\phpbb\phpBB3\phpbb\extension\di\extension_base.php(63): phpbb\extension\di\extension_base->load_services(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#3 C:\xampp\htdocs\phpbb\phpBB3\vendor\symfony\dependency-injection\Compiler\MergeExtensionConfigurationPass.php(59): phpbb\extension\di\extension_base->load(Array, Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#4 C:\xampp\htdocs\phpbb\phpBB3\vendor\symfony\http-kernel\DependencyInjection\MergeExtensionConfigurationPass.php(39): Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationPass->process(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#5 C:\xampp\htdocs\phpbb\phpBB3\vendor\symfony\dependency-injection\Compiler\Compiler.php(102): Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass->process(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#6 C:\xampp\htdocs\phpbb\phpBB3\vendor\symfony\dependency-injection\ContainerBuilder.php(583): Symfony\Component\DependencyInjection\Compiler\Compiler->compile(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#7 C:\xampp\htdocs\phpbb\phpBB3\phpbb\di\container_builder.php(191): Symfony\Component\DependencyInjection\ContainerBuilder->compile()
#8 C:\xampp\htdocs\phpbb\phpBB3\common.php(115): phpbb\di\container_builder->get_container()
#9 C:\xampp\htdocs\phpbb\phpBB3\adm\index.php(23): require('C:\\xampp\\htdocs...')
#10 {main}

User avatar
david63
Jr. Extension Validator
Posts: 14645
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: load language variables

Post by david63 » Sun Jun 10, 2018 2:21 pm

The answer is in the first line
Exception: The file "C:\xampp\htdocs\phpbb\phpBB3\ext\meis2m\aafs\config\services.yml" does not contain valid YAML.

Google yml format checker and use it to check your services file.

You may have tab, or a space in the wrong place.

.yml files are very precise in their formatting, get one character wrong and it will not work.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
Meis2M
Translator
Posts: 816
Joined: Wed Mar 03, 2010 11:32 am
Location: IR.Damghan
Name: میثم نوبری
Contact:

Re: load language variables

Post by Meis2M » Sun Jun 10, 2018 2:34 pm

Thank you... new error

what is that?

Code: Select all

Exception: The definition for "tags" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an abstract definition solely used by child definitions, please add abstract=true, otherwise specify a class to get rid of this error.

User avatar
Meis2M
Translator
Posts: 816
Joined: Wed Mar 03, 2010 11:32 am
Location: IR.Damghan
Name: میثم نوبری
Contact:

Re: load language variables

Post by Meis2M » Sun Jun 10, 2018 2:52 pm

i fixed it..
thank you... now languages is working perfectly

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: Crizzo and 4 guests