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
Related
I'm a long time Zend Framework user (now renamed Laminas). But I decided to give a try to last Symfony version. So I just installed it in 5.1.2.
I'm facing a question regarding the multiple environments deployments. In my compay, we have :
Local environment which is developer pc.
Development.
Staging.
Production.
In ZF-Laminas, we have a global.php file which is located in config directory.
For those of you who are not familiar with this framework, you can override key set in global.php file by creating local.php file.
In this global file, I use to put standard configuration for my application.
For example (prod) :
'open_id' => [
'client_id' => 1234
]
Then, I have development and staging files which car override those values for every environmenet. During the deployment, the file corresponding to the environment is copied to local.php.
Let's say staging.local.php.dist becomes local.php with :
'open_id' => [
'client_id' => 5678
]
Which is fine because value is overriding the one from global file.
I would like the same behavior in Symfony but I don't see something similar in Symfony 5.
So far, I only found two possibilities
Create a bundle which will allow me to have a <bundle_name>.yaml file in config/packages directory. According to the documentation (https://symfony.com/doc/current/configuration.html#configuration-files), I will be able to have dev, prod and staging overrides. But it forces me to create a bundle to handle just some standard configurations, which is huge.
Use .env files. But .env files only allow string data, not complex data like arrays.
What do I miss ? Or is it my "zend" way of doing things that is wrong ?
Thanks.
You can also create services_%env%.yaml (services_dev.yaml, services_test.yaml) files for each environment. It will allow you to define different parameters and override/define services for each environment.
Example:
config/services_dev.yaml
parameters:
hello: 'world'
From what I understand from your post, your goal is to have different config values based on the server you are on. If this is the case, you can use environment variables (in the .env file or .env.local for server specific config). You can then use these values in your applications by binding the env var to a parameter. This parameter will then be available within the configuration by using %parameter_name% as value or within the container. You can also pas parameters to services (service definitions are handled the same way as any other config). For more information you can checkout these sources:
https://symfony.com/doc/current/configuration/env_var_processors.html
https://symfony.com/doc/current/configuration.html
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.
I want to access the base_path (base_url registered) of a specific Asset component directory from a controller in order to store my reports to a specific path preconfigured in config.yml.
I started changing my configuration, after upgrading to Symfony 2.7, like the following:
app/config/config.yml
framework:
assets:
version: 'v5'
version_format: '%%s?version=%%s'
base_path: ~
base_urls: ['http://cdn.example.com', 'https://secure.example.com']
packages:
reports:
base_path: bundles/mybundle
So, when I request a specific route, with the correct request parameters my controller generate the HTML from a particular Twig template and, at the end, it will be converted to PDF using KnpSnappyBundle.
At last, my purpose is to build a list of generated PDF reports accessible from a public assets directory.
$kernel->locateResource()
However, I can access the complete path using a workaround like the following:
$this->container->get('kernel')->locateResource('#MyBundle/Resources/public/reports')
Using parameters.yml
I have also asked for some hints and it seems legit to use the parameters.yml in order to manage the Asset component configuration. So, from the controller, they would be accessed using $this->getParameter() and, at the same time, as a configuration value for Asset.
The simplest way to deal with that is to define it as a parameter in parameters.yml, as you suggested yourself.
It's really easy to get it and it totally makes sense.
Update
I wanted to provide a bit more reasoning for my answer, so I will cite http://symfony.com/doc/current/best_practices/configuration.html as a reference.
Reading there, it seems that you should put into "parameters.yml" all infrastructure parameters which do not really change your application behaviours. I think this applies to your case as well: your application does not change its behaviour according to assets paths, it only needs to know where they are.
So, again, I'd say that putting them in parameters.yml not only provides you an easy solution but also it's a "good practice".
I could not manage to find a way to include different security.yml files that would be included depending on Symfony2`s environment. For example I wanted to have an in-memory user provider for my acceptance tests, cause I don't really need to test my entities and stuff here, I only want to make an acceptance test for my views.
But, as it turned out, it's not an easy thing to do. I removed security.yml from includes in my config.yml, renamed it to security_prod.yml and created a security_test.yml which has the in_memory user provider. Then I've included security_prod.yml and security_test.yml in my production and testing configs respectively.
Yet it does not seem to work at all:
$ SYMFONY_ENV=test app/console cache:clear
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
You are not allowed to define new elements for path "security.providers". Please define all elements for this path in one config file.
$ SYMFONY_ENV=prod app/console cache:clear
[Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException]
Configuration path "security.access_control" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one
configuration section.
It appeared to me like the security.yml filename was hardcoded (which would be way too weird for Symfony), and it wasn't.
So the question is: how do I get multiple security.ymls with Symfony? And what could be causing this behaviour?
Instruction for those, who is looking for it (and do not red comments):
Create different config files for different environments: config_test.yml, config_dev.yml, config_prod.yml
Create different security files: security_test.yml, security_dev.yml, security_prod.yml
Import security_test.yml in config_test.yml and so on for other environments. Example for config_test.yml:
imports:
- { resource: security_test.yml }
Make sure you included security_*.yml only once (basically author did this mistake)
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.