i18n extract does not create directories nor files in Symfony - php

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.

Related

Custom configuration file for Symfony project

My goal is to add to a new Symfony 4.4 project an extra config file to define some behavior of the system. It could be anything, like, pancakes.yaml:
pancakes:
enablePancakes: false
I wish to know how can I load that config file. find a way to read its parameters and values to change some custom behavior the system might have but honestly I think I'm not smart enough to understand what the documentation says.
For now it could be anything, like printing the configuration file values, for now I only need to know how to load it.
you can update the following file :
# config/service.yaml
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
parameters:
locale: 'en'
chat_update_interval: 10000
and use service decoration in your new application to override your parameters.

No specifications found at path for a valid feature file

I am setting up automated testing with behat (note: I am using behat 3). I have the following directory structure:
project/
test/
features/
web/
login.feature
bootstrap/
Web/
LoginContext.php
behat.yml
This is the initial test of the whole approach. I'm explicitly keeping it simple.
My behat.yml contains the following (that's all there is in it - everything else will come later).
default:
suites:
web:
paths: [%paths.base%/features/web]
contexts: [Web\LoginContext]
My sole feature file contains the following:
Feature: Login to MedNav
In order to use MedNav application
As a user
I need to be able to login
Scenario: Valid login credentials
Given I am on the login page
When I enter invalid credentials
And I hit log in button
Then I should see "Loading, please wait..."
And I should navigate to Emergency List page
After I executed behat --init, it created file Web\LoginContext, into which I added the stubs for the steps.
Yet, when I try to execute it, nothing happens:
$ bin/behat
No scenarios
No steps
0m0.01s (13.16Mb)
If I specify the feature to execute, it tells me that No specifications found at path(s) 'features/web/login.feature'
$ bin/behat features/web/login.feature
No scenarios
No steps
0m0.01s (13.16Mb)
[Behat\Testwork\Tester\Exception\WrongPathsException]
No specifications found at path(s) `features/web/login.feature`.
behat [-s|--suite SUITE] [-f|--format FORMAT] [-o|--out OUT] [--format-settings FORMAT-SETTINGS] [--init] [--lang LANG] [--name NAME] [--tags TAGS] [--role ROLE] [--story-syntax] [-d|--definitions DEFINITIONS] [--append-snippets] [--no-snippets] [--strict] [--order ORDER] [--rerun] [--stop-on-failure] [--dry-run] [--] [<paths>]
I've tried moving things around, removing custom directories, suites, etc. - nothing works.
How can I get behat to recognise the feature file?
The answer turned out to be much simpler.
Notice this in the behat.yml:
filters:
tags: web
Because the corresponding context didn't have this tag, the feature didn't execute. I removed the tags for now - and the feature is now run.
Please check again your paths - in your case it should be something similar to:
default:
suites:
web:
paths: [ %paths.base%/test/features/web ]
And move behat.yml file to project root directory. I think calling now bin/behat Behat know nothing about behat.yml file.
I assume that you are running bin/behat from project/ path.
This is related to: http://docs.behat.org/en/v3.0/user_guide/configuration.html#custom-autoloading

Symfony Translation Doesn't Work In Production

I have a symfony (2.8) app (Sylius actually) and I'm overriding some parts of the translation from SyliusUserBundle in app/Resources/translations/messages.en.yml
(namely, the translation key is sylius.customer.email.unique)
It works like charm on local dev env, but gives me the key on production. I did clear the cache, multiple times, and it doesn't help.
What are other possible causes?
UPDATE
Gives the translation found in the SyliusUserBundle for English (as it exists in the original bundle) but gives the key in other languages, where the original bundle doesn't contain the translation. So as a summary, it seems that translation files app/Resources/translations/messages.<lang>.yml are not being picked up on prod for some reason.
UPDATE 2
I also have discovered that the key with the valid translation is present in this file: app/cache/prod/translations/catalogue.hu_HU.ba674f8d2fd06750dcd7ee5bb021c1b905b518ea.php
Moving the keys into separate files:
app/Resources/translations/validators.en.yml
app/Resources/translations/validators.hu.yml
has solved the problem.
(An interesting question is why did it work on my dev env..)
Did you configure the fallback locale?
# app/config/config.yml
framework:
translator: { fallbacks: [en] }
Try rename your file with messages.hu.yml
and if not work change:
sylius.locale: hu_HU
to
sylius.locale: hu

Translation catalog generation with Symfony2 for main app

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/.

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