How to use translations in Yii console application? - internationalization

I have created a console Yii application that works as a background worker for a web app - it sends out emails and it needs to send them with translated messages.
For some reason however, the messages are not translated when using Yii::t
If I set the language to something else than english with Yii::app->setLanguage('et_ee'), and check that it is really changed with Yii::app->getLanguage() the texts are always in english.
When I run this same command from web, the texts are correctly translated.
I guess there must be something special I have to do for the translatiosn to work in a console application?

I have this error to. I dont know how is fix it. I am get lang array trow require('path/to/message/ru/message.php') in to var and use it. It is wrong, but it is work for me.

You need to specify the messages component in your console.php configuration
'messages' => array(
'class' => 'CDbMessageSource',
'forceTranslation'=>true,
'sourceMessageTable' => 'source_message',
'translatedMessageTable' => 'translated_message',
),

Just add string (For example - russian languages):
'language' => 'ru'
in config/console.php.

Related

How to use asterisk Include statement the right way?

I'm new to asterisk, and I have an issue about using include statement.
I have a context named "app-calltrace-perform" from FreePBX, used when people press *69 to trace their call.
[app-calltrace-perform]
include => app-calltrace-perform-custom
exten => s,1,Answer
...
exten => t,n,Macro(hangupcall,)
The "app-calltrace-perform" written in extensions_additional.conf which will be overwritten when users submit something about dialplan on the Web gui. So I have to write my own context "app-calltrace-perform-custom" on another file called extensions_custom.conf
[app-calltrace-perform-custom]
exten => s,1,Answer()
same => n,VERBOSE("Something here")
same => n,Playback(hello-world)
same => n,Hangup()
Note that extensions_additional.conf and extensions_custom.conf was already included from extensions.conf
Then I do dialplan reload and try again, but dialplan do not play my context at all (no verbose, no play hello-world).
I've found something useful in https://wiki.asterisk.org/wiki/display/AST/Include+Statements+Basics
Asterisk will always try to find a matching extension in the current context first, and only follow the include statement to a new context if there isn't anything that matches in the current context.
So now I dont know how to use my custom context for stuffs like this. Sorry if this a dumb question, but if you have any idea, pleas guide me through.
Edit
This is where app-calltrace-perform called from
[app-calltrace]
include => app-calltrace-custom
exten => *69,1,Goto(app-calltrace-perform,s,1)
Now i'm using another extension (*12345) defined in context app-calltrace-custom, It works well but is hard coded so cannot modified by the Web Gui
End Edit
Thanks in advance
Loi Dang
Asterisk dialplan matching work this way
[context1]
exten => 1,1,Noop(1)
include =>context2
include =>context3
exten => i,1,Noop(invalid extension)
[context2]
exten => 1,1,Noop(2)
exten => 2,1,Noop(3)
[context3]
exten => 1,1,Noop(4)
exten => 2,1,Noop(5)
exten => _X,1,Noop(other)
Let's say you call context1
when called 1 will be selected command from context1, becuase it EXIST in context. Same if you use wildcard.
When called 2 will be selected 2 from context2, first included context
When called any other number (for example 3) will be selected "other" in context3(becuase it not presented in context nor in prevous included context)
If called 12 which not present in any contextes, will be execute "invalid" extension
You'll need to have something that's distinguishing in your included context in order for the dialplan to know to use it. Since you've used the s extension in both, it uses the matching extension in the current context, first. As you've found in the documentation.
The s extension is the "start" extension, and used when there's no known dialed extension.
First, double check your file include is in the [globals] context in extensions.conf
[globals]
#include extensions_custom.conf
Then, include as you have done:
[app-calltrace-perform]
include => app-calltrace-perform-custom
exten => s,1,Answer
same => n,Noop(Testing 1234)
same => n,Hangup()
But, you need something differentiating in your included context. So for example:
[app-calltrace-perform-custom]
exten => *69,1,Answer()
same => n,Playback(hello-world)
same => n,Hangup()
So if you have a device that uses the [app-calltrace-perform] and they dial *69, they'll be subject to the [app-calltrace-perform-custom] extension.
Also, it's considered good practice to have a Hangup() ending each included context as you've done (good job). In order to prevent a possible mistake resulting in toll-fraud. Just wanted to note that for future stackoverflowers.

How to increase CakePHP Debugger maximum depth

I'm trying to debug my program by logging information from an ajax call. This is something that doesn't render a view, just runs asynchronously. The log will only display arrays to a depth of 3, and the documentation doesn't seem to have any notion that someone might want more information than that.
Please, how do I increase this depth so I can have access to this information without finding weird ways to render my ajax call? Or, if doing this isn't the "Cake" way, is there a better way to output info to a log or console for debugging?
I think this is not the case of CakePHP but an issue with XDebug or PHP configuration itself. You can try to add this line to your php.ini
xdebug.var_display_max_depth = 5
It works if you debug with var_dump(). You should write how do you try to debug, bacause different methods depends on different mechanisms.
If it doesn't work you can try to make the Cake to display original PHP error messages instead of its own error handler messages. In your core.php find code like this:
Configure::write('Error', array(
'handler' => 'displayErrorWithoutCrap',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
And change it into this:
Configure::write('Error', array(
//'handler' => 'ErrorHandler::handleError',
'handler' => 'displayErrorWithoutCrap',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
and add this line at the end of bootstrap.php :
function displayErrorWithoutCrap() {
return false;
}
I ended up submitting a ticket to the Git project for CakePHP and it was confirmed that the debug depth for arrays is hard-coded for log files. The response indicated that it would be considered for a change in the next version.
I ended up finding the number in the Debug class and changed it to a larger number which gave me more depth. Not the best fix, but it works for now until support is added to the next version.

how to use fireAnbu in laravel 3?

I've installed the bundle fireAnbu in my local laravel 3 app, but I can't figure out how to use it! (feeling silly)
I've got 'fireanbu' => array('auto' => true), in bundles.php and 'profiler' => true, in fireanbu/config/fireanbu.php, and I've tried:
fireanbu::log('something');
$fireanbu->log('something');
FirePHP::log('something');
$FirePHP->log('something');
FB::log('something');
$fb->log('something');
I've had a look in fireanbu/start.php for clues, but I'm guessing :(
The best clue I've had so far is:
Non-static method FirePHP::log() should not be called statically, assuming $this from incompatible context
I've looked at http://www.firephp.org/HQ/Use.htm and it looks like fireanbu is using the OO API..
What am I doing wrong / how should I call it within my controllers?
I also created a Laravel 4 version for this if anyone finds this thread looking for a L4 version (like I did, and in the absence of finding one created my own):
https://packagist.org/packages/p3in/firephp
There no need to do anything. It would listen to event from Laravel's own Log class and attach it to FirePHP.
Log::info('foo'); would just work nicely.

Cant get codeigniter hooks working

I have spent several hours now, trying to figure out why i can't get a simple hook working in codeigniter.
I have enabled hooks in config.
i tripplechecked spelling and case.
I wrote the code below in config/hooks.php:
$hook['pre_controller'] = array(
'class' => '',
'function' => 'set_previous_page',
'filename' => 'previous_page',
'filepath' => 'hooks'
);
And then my previous_page.php file which is located in hooks folder:
function set_previous_page()
{
echo "Hi!"; die;
}
Obviously the purpose is not to echo Hi! and then stop the script execution, but it's just to get it working. And i did try several hook points. But pre_controller i should be able to output hi and kill the script, and then have hi as the only output.
But when i load my pages, it just loads as normal.
I tried on purpose, to mess up the syntax in the hook array, and it did give me an error, and the rest of the page was not loaded. That just tells me that, at least it does recognize that i have turned hooks on.
But from here on i am just lost. Dont know what to do?
Do you have any ideas? I'll try and sleep on it now, and hope that some smart fella in here has the answer! Thankyou in advance!
EDIT: By the way, i am using MX (modular extensions), phil sturgeons template library and Ion auth. Dont really think they should have an impact.
Your code doesn't look like the code in the manual. Did you check it?
http://www.codeigniter.com/user_guide/general/hooks.html
I just tried it locally, and it works fine.
application/config/hooks.php:
$hook['pre_controller'] = array(
'class' => '',
'function' => 'Myfunction',
'filename' => 'Myclass.php',
'filepath' => 'hooks',
'params' => ''
);
application/hooks/Myclass.php:
<?php
function Myfunction(){
echo "wut wut";
die;
}
With this all set, I visit the page and get a wut wut.
You're missing the php extension in the filename, but that'd throw an unexpected end of input exception if everything else was working.
This maybe very late respond, just incase someone encounter this kind of issue same as me using CI 3.x. Just make sure you enable hooks in config/config.php file $config['enable_hooks'] = TRUE; before you put entry in the config/hooks.php

How to do atomic update in Mongo/Mongomatic?

I'm having an awfully difficult time figuring out how to update a MongoDB document, using the atomic '$set' operator with Mongomatic. I'm pretty sure it's Mongo's criteria/update language I'm having troubles with, not Mongomatic, but I'm willing to be proven wrong.
The link to a gist with a standalone, runnable script is here: https://gist.github.com/3835672
I'm starting out by creating a document that looks like this:
{"videos":[{"video_id":"video1"},{"video_id":"video2"}],"_id":{"$oid": "506ddd53a114604ce3000001"}}
I can get that document using a model instantiated using Mongomatic:
video_group = VideoGroup.find_one('videos.video_id' => 'video1')
Then I'm trying to set a 'views' field, by doing this:
video_group.update!({ 'videos.video_id' => 'video1' }, '$set' => { 'videos.$.views' => 123 })
That's where Mongo blows up, with the following error:
can't append to array using string field name [$]
I know this is a very common question on StackOverflow. I understand generally that the problem is that the positional operator isn't getting any matches. But even reading through dozens of responses, I still can't figure out how to express this statement in a way that works.
Am I just starting out with the wrong data structure?
It is, in fact, a mongomatic problem. You need to pass the underlying mongo ruby driver the option {:multi => true}, as well as including your criteria with the specific _id for the update sent to mongodb instead of as part of the optional parameters. Looks like a bug in mongomatic. Here is the ruby debugger transcript that I used to find it: https://gist.github.com/3836797
Note that I made a change to the file you posted, adding the line debugger before line #41, and changing line #42-44 to this:
video_group.update!({ 'videos.video_id' => 'video1', :multi => true }, '$set' => {
'videos.$.views' => 123,
})

Resources