trans_default_domain Symfony2 - php

I change my translation file name (messages.en.yml => ProjectMainBundle.en.yml)
Is there a way to change the default translation domain for all the project and not add trans_default_domain in all my twig pages ?
Thanks for your help

I think you would need to override
vendor\symfony\symfony\src\Symfony\Component\Translation\MessageCatalogue
vendor\symfony\symfony\src\Symfony\Component\Translation\MessageCatalogueInterface
The default translation domain messages is hardcoded in there.

Related

Shopware 6: How to Access Config Parameters in Twig Template of the Admin Module

I'm looking for a way to access configuration parameters in twig template of the admin module. I tried to access it by:
{{ shopware.config.pluginName.config.fieldName }}
The problem is that in the twig template of the admin module {{ shopware.config }} isn't available. I tried to access it by {{ dump(shopware.config) }} but it returns nothing.
Am I doing something wrong?
Is there alternative to access plugin's configuration parameters in the admin module?
Is there a way to pass php variables to twig template of the admin module?
Thanks in advance,
Cheers!
Try to use following service:
this.systemConfigApiService.getValues('domain', this.selectedSalesChannelId)
where domain is the Plugin name.
Of course, you should inject that service first
inject: ['systemConfigApiService']
Using that service you can provide config value to twig template.

SonataAdminBundle overwrite date template

I use sonata admin bundle and my question
How o overwtite this template ?
vendor/sonata-project/admin-bundle/src/Resources/views/CRUD/list_date.html.twig
'date' => '#SonataAdmin/CRUD/list_date.html.twig',
maybe some approach in config ?
sonata_admin:
templates:
date => '#SonataAdmin/CRUD/list_date.html.twig',
but it's not work's.
I tried created templates/bundles/SonataAdmin/CRUD/list_date.html.twig but still sonata render data in vendor/sonata-project/admin-bundle/src/Resources/views/CRUD/list_date.html.twig
How to corect create overwrite template ?
I tried create like in cookbook templates/bundles/SonataAdminBundle/Resources/views/CRUD/list_date.html.twig and clear cache but still data rendered in old template. I using Symfony 4
You can use standard template override from Symfony. Means it should work with file: templates/bundles/SonataAdminBundle/CRUD/list_date.html.twig.

Perform merge between views of two or more modules

I have a Phalcon PHP modular application. I am making an administrative interface to control which modules should be used in the system.
One module controls the application's default interface, while the other modules add functionalities.
I have the problem: when another module to enabled, it can add the HTML content to the other interface control module. In this way I would like to merge two or more views. I am using Volt as template engine.
Is this possible in Phalcon?
Note: This was asked on the official Phalcon forums. I answered it over there and it got accepted. I am just mirroring my answer so future readers can get an answer here without being redirected from StackOverflow. Phalcon forum mirror: https://forum.phalconphp.com/discussion/15891/perform-merge-between-views-of-two-or-more-modules
config.php
You will need to define your modules in the app/config/config.php file like so;
return new \Phalcon\Config([
// ...
'modules' => [
'module01',
'module02',
...
'moduleN',
],
// ...
]);
*Controller.php
Then, in your controller, you'd set a view property to store the active modules like so;
$this->view->modules_enabled = $this->di->get("config")->modules;
*.volt
And finally in your volt file, just check the module is in the array holding active modules, and if so, display the view using partials.
{% if module01 in modules_enabled %}
<div id="module">{{ partial("partials/module01") }}</div>
{% endif %}

How to add a new domain for translations in Symfony

I'm using symfony and in my bundle I need to create some translations, but I rather do it in a different domain than "messages", like FOS User Bundle does (they use the FOSUserBundle domain).
So I created a MyBundle.en.yml file with my translations, but they are not loaded. I've read in the documentation I need to do this:
$translator->addLoader('xlf', new XliffFileLoader());
$translator->addResource('xlf', 'messages.fr.xlf', 'fr_FR');
$translator->addResource('xlf', 'admin.fr.xlf', 'fr_FR', 'admin');
$translator->addResource(
'xlf',
'navigation.fr.xlf',
'fr_FR',
'navigation'
);
http://symfony.com/doc/current/components/translation.html#using-message-domains
But where should I do that?
Update
After some investigation, if I run the debug for the translations it says that all the translation I'm using for my domain in the template are missing.
My translation file is located at
src/Acme/Bundle/MyBundle/resources/translations/MyDomain.yml
I tried to located in app/Resources/translation/MyDomain.yml but same result.
I also tried to delete the cache (rm -rf app/cache) but still not working
Symfony will automatically do this for you if you place your files in the correct location(s). You can find a full description of the conventions assumed by Symfony in the documentation: https://symfony.com/doc/current/translation.html#translation-resource-file-names-and-locations
The Best Practices-guide recommends storing them in app/Resources/translations/. Alternatively you can put them in your bundle's translations folder: src/MyBundle/Resources/translations.
Please be aware that you have to specify your domain when using the translator, e.g. in your twig templates. See:
https://symfony.com/doc/current/components/translation.html#using-message-domains
https://symfony.com/doc/current/translation.html#twig-templates
you have to specify the domain name. for example in twig:
{{ some_things | trans({}, 'my_domaine_name') }}
If you have something like x.en.yaml and you want to use it inside a twing template you can do something like this:
{% trans from 'x' %}word_to_translate{% endtrans %}

Symfony2 Translation using trans_default_domain

I'd like to translate a part of my twig template which is not in my trans_default_domain
For exemple:
{% trans_default_domain 'FOSUserBundle' %}
{{ 'test.trans'|trans({}, 'ProjectMainBundle') }}
So test.trans is translated in ProjectMainBundle but I always have test.trans in my text.
Edit:
test.trans is in src/Project/MainBundle/Resources/translations/messages.en
It works everywhere but it doesn't work when I am trying to get my trans with a trans_default_domain
You are storing the translation in a file called messages.en.yml which means according to the naming conventions for translations these translations have the domain messages and not ProjectMainBundle.
Therefore the translator doesn't find a translation if you're trying to use the domain ProjectMainBundle and returns the string itself.
Each message file must be named according to the following path:
domain.locale.loader
Your translations should be stored in #AcmeYourBundle/Resources/translations/<domain>.<locale>.yml ( or php, xliff, ... ).
Remember to clear your cache after renaming.

Categories