Translation catalog generation with Symfony2 for main app - php

I used the following command to generate the catalogs of my different Bundles and it worked well.
php app/console translation:update --dump-messages --force fr ProjectBlogBundle
But how should I do to translate the view that we can find on /app/Resources/views/* ?
Thanks,

If you check the command code, it looks like it's not possible: the bundle name is required and must be provided.
However, you can check this out.
Even though you can't automatically extract/update translation segments from those views, the runtime translation should work, provided that you use the same translation domain.

Even though this question is rather dated, I figured I might add this just for anybody else stumbling across this:
It seems that the desired functionality has been added in the meantime (Symfony 2.8+).
If you run the command like this:
$ app/console translation:update --help
Usage:
translation:update [options] [--] <locale> [<bundle>]
Arguments:
locale The locale
bundle The bundle name or directory where to load the messages, defaults to app/Resources folder
It seems the bundle name has become optionale and the command will default to app/Resources

I had the same problem, and the #Jan's answer helped me. So there is an example.
cd app/
php ./console console translation:update --dump-messages --force fr .
As . is a directory (the current directory), the translator will try to load the subdirectory /Resources, so here it will try to load app/Resources/.

Related

Generating Bundle in Symfony

Can't find a solution for this on stack.
I'm using ubuntu server,
$php app/console generate:bundle --namespace=WMDN/FirstBundle --format=yml
goes fine until :
Generating the bundle code: OK
Checking that the bundle is autoloaded: FAILED
Confirm automatic update of your Kernel [yes]? yes
Enabling the bundle inside the Kernel: OK
Confirm automatic update of the Routing [yes]? yes
Importing the bundle routing resource: OK
The command was not able to configure everything automatically.
You must do the following changes manually.
- Edit the composer.json file and register the bundle
namespace in the "autoload" section:
I thought it was permissions, and set the whole dir to 775 and made sure owner was good.
I thought it was outdated bug for symfony and deleted whole dir, and got 2.4.4
I'm following a tutorial and their bundle generates just fine and I'd like mine to do it as well.
Why can it not autoload? My Namespace should be good to use. I cannot figure it out.
I have composer installed.
Following this tutorial series : http://www.youtube.com/watch?v=GIcY5YYfZ14 and I'd really like to get my first bundle created so I may continue.
In conclusion, what are the reasons a bundle would fail autoload?
Per to comments, solution was to set the --src parameter correctly.

How to change the Symfony2 Behat Bundle default Feature context file (FeatureContext.php by default)

I use Symfony2 BehatBundle, version=v1.0.0 and I want to change the name of the main feature context file. Now when I run the behat using command:
app/console --env=test behat #NameOfMyBundle
file src/NameOfMyBundle/Features/Context/FeatureContext.php is used
I want to use custom main feature file, for example src/NameOfMyBundle/Features/Context/MyCustomContext.php but I don't know how. According to the behat documentation:
By convention, the context class should be called FeatureContext, but this could be easily changed through the cli configuration.
However, this configuration option is nowhere to be found. I tried something like:
app/console --env=test behat #NameOfMyBundle --context "MyCustomContext"
but it fails.
Does anyone know how to change this main feature context file (preferably, using cli)?
Thanks!
The context class can be changed in the configuration file: http://docs.behat.org/guides/7.config.html#context
Environment variables can be used as well: http://docs.behat.org/guides/7.config.html#environment-variable
The bundle is no longer maintained. Use the extension instead: http://docs.behat.org/en/latest/cookbooks/1.symfony2_integration.html#installing-and-enabling-symfony2-extension

i18n extract does not create directories nor files in Symfony

I am trying to set up the i18n behavior on Symfony 1.4.18. I have some i18n-friendly strings (using the two underscores) in my frontend layout. I tried to run the command below :
$ ./symfony i18n:extract frontend fr --auto-save
At first, symfony found 17 strings, but didn't build the path apps/frontend/i18n/fr/ nor the file inside : messages.xml.
I re-ran the command above, but this time Symfony did not find any string. I thought, if Symfony does not find new strings, it might save it somewhere, so I ran another command on my Linux, to find any occurrences on one of my i18n strings (Typically I have this string : ) :
$ grep "Freelance" $(find ./)
This command was launched at the root of my project, but unfortunately it didn't find any occurrences except the one in my layout.
I don't know what to do anymore to solve my problem.
PS : I hope my english isn't too bad, it's not my native language, but I try to do my best.
Try to add
messageSource: '%SF_APP_DIR%/i18n'
option to your i18n factory configuration.
And look for your messages.xml in app_dir/i18n/your_culture. Old messages.xml where at vendor/symfony/lib/plugins/sfdoctrineplugin/i18n in my case
Try to set i18n source in factories.yml
Something like this:
i18n:
class: sfI18N
param:
source: XLIFF
debug: false
untranslated_prefix: "[T]"
untranslated_suffix: "[/T]"
cache:
class: sfFileCache
param:
automatic_cleaning_factor: 0
cache_dir: %SF_I18N_CACHE_DIR%
lifetime: 31556926
prefix: %SF_APP_DIR%/i18n
here you can find more information.
Do this in your project root:
sudo find . -print | grep -i 'messages.xml'
Then delete the file (s) you found (probably within sfDoctrinePlugin/i18n in the symfony vendor files)
Use the settings from above for your factory.yml and settings.yml
Restart task:
php symfony i18n:extract frontend fr --auto-save
That's all. Now the messages.xml is generated. Missing folders are created.
(Revert the chmod changes you did before)
Your default language is fr and you're trying to get the translations to fr?
The xml files should have the source string (in french - your default language) and target string (in english or whatever).
Try ./symfony i18n:extract frontend en --auto-save (or whatever language you want, other than french) and let us know if you'll get what you need.

Symfony did not create model

I am going through symfony book and trying to do jobeet project(I use propel).. so here what book says
The ORM also generates PHP classes that map table records to objects:
$ php symfony propel:build --model
The propel:build --model task generates PHP files in the lib/model/ directory that
can be used to interact with the database.
I run that command and when i go to lib/ direcotry , there is no model folder :/
You have to write:
$ php symfony propel:build-model
Have you tried this?
sudo ./symfony project:permissions
./symfony project:cc
./symfony propel:build-all-load // this will write to your db as well
otherwise please consider pasting the output of propel:build-model and your symphony version :)

Symfony database setup: command "symfony" in ms-dos doesn't work

I am trying to do this:
c:\> php symfony configure:database "mysql:host=localhost;dbname=jobeet" root mYsEcret
This doesnt work for me because it says
Could not open input file
I thought I needed to add symfony-file located in C:\dev\sfprojects\jobeet\lib\vendor\symfony\data\bin\ to PATH, but this didn't do the trick. I tried to enter the whole path to the symfony-file like so:
c:\> php C:\dev\sfprojects\jobeet\lib\vendor\symfony\data\bin\symfony\ configure:database "mysql:host=localhost;dbname=jobeet" root mYsEcret
I get error Task configure:database not defined
What should I do in order to:
Be able to use the symfony keyword
rather than the whole path of the
file
Be able to run configure:database?
Thank you for your time.
Kind regards,
Marius
You need to be in the directory of your symfony project, in this case C:\dev\sfprojects\jobeet\.
"Because the symfony shortcut file is executable, Unix users can replace all occurrences of 'php symfony' by './symfony' from now on.
On Windows you can copy the 'symfony.bat' file to your project and use 'symfony' instead of 'php symfony":
http://www.symfony-project.org/jobeet/1_4/Doctrine/en/01#chapter_01_sub_application_creation

Categories