Using plugin built-in translations in a CakePHP application - cakephp

I am using a couple of plugins in a CakePHP application that come with predefined translations in their Locale directories.
However, despite I have set the language setting, messages from these plugins are not being translated.
First question: can CakePHP retrieve those plugin translations by default or do I have to create my own translation files every time I use a plugin in a different application?
If CakePHP should retrieve the translations in plugin's Locale directory, is there something else I have to do besides setting Configure::write('Config.language', 'spa')?
Thank you!!
UPDATE: I am using CakePHP 2.1

Related

extract i18n validation messages in Cakephp 2 plugin

I am developing a plugin in CakePHP 2.x, and I want to translate the error messages from the models.
I was reading the documentation, but its no clear about how extract exactly.
I changed the domain for my models with:
$validationDomain = 'validation_errors';
so cakephp made a validation_errors.pot file.
I have two folders, 'spa' and 'eng', with 'LC_MESSAGES' into them, and 'manager.po' file where I put the translations for my plugin (with the same name).
Where I have to make the .po file from validation_errors.pot? and how I have to name it?
Thanks!

use croogo as plugin in main cakephp app

Im working with cakephp for few months and recently I came across croogo, a cakephp cms system. I've tried it and I should say its an awesome system.
Is it possible to use it as a plugin in my main site. I want to use it just for the admin part and rest of my application unattached to it. Ive tried loading its bootstrap file from my main app and also by linking routes to it. I always get errors.
Can someone have any idea if croogo is meant to be used like a plugin or does it have to be used seperately?
"Beginning version 1.6.x, Croogo has been updated to be installed as a vendor package"
=> So yes, it is possible to use it in your code - just not as plugin, but vendor.
See
https://github.com/croogo/croogo/tree/3.0#installation-using-git

How to use correctly a CakePHP plugin

I've developed a bug tracker using CakePHP 2.4.4. I made this as a standalone cakephp app but now I wanna transfer it to a plugin, in order to reuse it in other projects.
As I already read at the docs (http://book.cakephp.org/2.0/en/plugins.html), I have followed the instructions from there and created the correct folder and files structure. This is what i've done so far: https://github.com/lubbleup/BugCake/tree/plugin
But now,when i try to use the plugin in a separate cakephp installation, I cannot understand how to make of the plugin and, for example, use it's controllers and functionality etc.
can anyone help me out here?
ps:this is my first time trying to create a cakephp plugin
Thank you in advance!
You have to load the plugins your parent app in APP/Config/bootstrap.php
CakePlugin::loadAll();
You do not need AppModel or AppController in your plugin. Your plugin has an own AppController/-Model named PluginNameAppController/PluginNameAppModel.
You can call your plugin at http://host/plugin_name/controller/action/[...]. In your case http://host/bug_cake/issues/view/1 for instance.
But you can also use custom routes in your plugin with plenty of options.
Hope that answers your question—if not, comment.

CakePHP Get translated data from the model

I am using cakephp 2.x to make one site multilingual and I am using the i18n extract and the TranslateBehavior Core Library.
The i18n works fine and the TranslateBehavior Core Library works fine when I try to save data. But when I want to read it I have to say to the controller the specific locale with:
$this->Home->locale = 'spa';
or
$this->Home->locale = 'eng';
Instead the core library makes it automatically by me. I have to specify all the times the locale? Or does exist something that do it automatically?
Thank you very much
There is a detailed article about i18n on Cakephp 1.3, I hope your 2.x will also work on this say theory so you can have a try with that http://codeatomic.com/developing-cakephp-multilingual-website/

CakePHP Plugins - Best way to implement a config file for the plugin?

I am developing a plugin and I'm trying to find the best way to have a set of default config options for it which are automatically used when the plugin is loaded, but also have the ability to customise them for a specific app.
I am struggling to find any good documentation about this for Cake 2.0+
Most of the solutions seem to involve configuring something in the main app bootstrap or making a config file in the main app, which seems like a bad idea because if you forget to do any of those things or don't do them correctly, the plugin won't work and it's relying on the 'outside' app, which doesn't seem right.
At the same time, it also seems like a bad idea to have the user edit some sort of config file within the plugin, as they are then tampering with the plugin itself.
What is the best way to do this (or what does everyone normally do)?
Take a look at this
http://api.cakephp.org/2.4/class-Configure.html
I was trying to figure out the same thing, then I saw it in a Twitter plugin. They have their own configure file in the plugin folder
You need to put a $config variable in the file. it doesn't do anything, but if you don't, Cake will complain.
This setup works the for plugin I am developing at the moment.
Example:
/Plugin/CakeCommerce/config/config.php
$config = '';
Configure::write('CC.default_email' , array('admin#server.com'=>'Server Admin'));
To load the config file. Do that in your __construct call in your plugin AppController.
class CakeCommerceAppController extends AppController {
public function __construct($request = null, $response = null)
{
parent::__construct($request, $response);
Configure::load('CakeCommerce.config' , 'default' , false);
}
}
What you should do is put your configuration settings in the plugins bootstrap file in Plugins/PluginDirectory/Config/bootstrap.php.
Then when loading the plugin the user has the option of whether to use the plugin's bootstrap file (See the CookBook). This appears to be all or nothing though, but you do have the advantage that your default configuration settings could always be used and so the user wouldn't have to create any config settings themselves.
I have found a plugin development article on the bakery and found this note:
Notice: be careful with configuration settings because plugin config files will override matching app settings, it is better to name settings with a plugin prefix
This to me suggests that you can't overwrite individual plugin settings from the application's bootstrap file. The user would have to modify the plugin's bootstrap file instead.
(The article is quite old and appears to be for an older version of cake so I don't know if things changed in more recent versions. Like you I am having a hard time finding much information on this subject)

Resources