Troubles adding new languages with Symfony 1.4 - symfony-1.4

I'm new to Symfony trying to add another language version to site.
I was trying to add language version in .htaccess and locales.
I've added this strings to routing.yml:
contacts:
param: { module: homepage, action: contacts }
prefix_path: /:sf_culture/contacts
But everytime I got 404 when I go to the /en/contacts.
I need to move english version to the /en and another language keep on /
What am I doing wrong and how can I add language version to the site correctly?

Related

Sonata Admin (4.17 or higher) Override list__action_delete.html.twig globally

I want to do exactly this (see link below) - override the list__action_delete.html.twig template globally for the entire project.
But with the newer sonata-admin and symfony version (without the app-directory) I have no clue where to place the list__action_xxx.html.twig files
See:
SonataAdminBundle - rewrite action button teplates in config.yml

Symfony routing configuration I can't find documentation about used to work but now it doesn't

I usually see resource: contain a file path, but here I have a multiline string with yaml instead:
shop_admin_taxon:
resource: |
alias: sylius.taxon
section: shop
templates: AdminBundle:Taxon/Crud
except: ['show', 'index']
redirect: update
grid: shop_admin_taxon
type: sylius.resource
prefix: /
I didn't get any error messagaes about this code when it worked on Symfony 3.2.7 in another project. But now Symfony 3.4 gives me the following error when trying to read this configuration:
The file "alias: sylius.taxon section: shop templates: AdminBundle:Taxon" does not exist.
That's actually expected (since as far as I know you pass a resource locator to resource: and not the actual resource configuration), but why did it work?
Symfony is complex beast and allows a lot of tinkering with it's internals. The routing component is no exception of this and you can see usages which modify or even dynamically create routes on the fly.
This in particular looks like a Sylius extension to routing. If you are curious how precisely it works have a look at the relevant Symfony documentation page. The functionality is being provided by the SyliusResourceBundle with a custom loader.
With all this in mind it looks like you have a broken Sylius install as the custom routing loader is not working. It could be some version mismatch introduced by composer update (e.g. remove component A due to incompatibility with newer version of component B), or bundles not being enabled, or something similar. Make sure all Sylius bundles are installed and enabled

Symfony 1.4 - Disable deafult language from url

I use http://www.symfony-project.org/plugins/tmcI18nPlugin plugin for internationalization.
Is there a way do not show the default language in url?
for example if i have
faq:
url: :sf_culture/faq
param: { module: faq, action: index}
English culture must miss for default language.

Change default path on Symfony CMF

I installed Symfony CMF structure bundles on my project, but default route is on
localhost/project/web/app_dev.php/
and i want to show it on
localhost/project/web/app_dev.php/cms
Thank you!!
So you do want to install symfony at the webroot, right? If that is the case, your best bet is to add a route /cms and add everything else under that route, instead of directly to the root. When using the RoutingAutoBundle, this should be no problem to configure. If your editors create routes themselves, you would need to work with the widget for selecting the parent of the routes to only propose the cms/ route you created - unless you think it could make sense for them to occasionally place a route outside of /cms.
If you want to be more strict, i think your best bet is the upcoming ResourceBundle. Discuss this with Dan over at https://groups.google.com/forum/#!topic/symfony-cmf-devs/6Wha2o3qHPE
Not sure if I understood your question. If you want your default home page at localhost/project/web/app_dev.php/ pointing to your cmf bundle, just add this at the begining of app/config/routing.yml
homepage:
pattern: /
defaults: { _controller: YourCMFBundle:Welcome:index }
Where Welcome is the name of your CMF default controller.

Symfony translations not working

I have done the following checklist:
created translation file respecting format domain.lang.loader
cleared cache
checked that language catalogue is created in cache folder
Though in my twig template file,
{{ 'message'|trans }}
never translates.
Where can I look next in order to make translations work?
Is there any chance that Doctrine Translatable Extension that I am using generates some kind of conflicts?
In Symfony 3.0 I had to clear the cache:
php bin/console cache:clear
I see you already did that, maybe it helps other like me.
Have you enabled the Translator service in your config file?
framework:
translator: { fallbacks: en }
The language catalogue is created in your cache folder irrespective of whether your translator is enabled or not.
Did you try translating in your controller?
$trans = $this->get('translator')->trans('message');
Try to specify domain. If you not specify domain by default it a messages.
{{ 'message'|trans({}, 'some_domain') }}
Then translations can be found in
the kernel root directory/Resources/translations directory;
the kernel root directory/Resources/bundle name/translations
directory;
the Resources/translations/ directory of the bundle.
For example some_domain.fr.yml. Last step is to configure your locale. You can get current locale from request with $request->getLocale()
P.S. try to rm -r app/cache to make sure that the cache is deleted
I could use one of the translations, but not the other and didn't know why. If you have troubles with translations also, read this.
First, standard checklist:
Make sure you enabled and configured translator.
Make sure translation is in proper place and follows proper naming convenction ( domain(messages by default).lang_code.file_format ).
Clear cache using php app/console cache:clear command.
Try to manually call $this->getRequest()->setLocale('en'); in Controller, also you may try to use $this->get('translator')->trans('Some message'); directly in your Controller.
If it still doesn't work, make sure BOM isn't in your translated file. That was my case.
Watch out for BOM in the translated file. The translator who translates the yml file used UTF8 which is OK, but editor he used leaved BOM at the beginning of the file. This is dangerous probably because of PHP's UTF8 BOM bug as it adds few invisible characters to first section of your file.
Btw, debugging your translations may be very helpful, too.
According to the Symfony Translations Documentation page, if you are not using a Service Container for your translation purpose, these are simple steps to go:
Enable and configure Symfony's translation service.
YAML
framework:
translator: { fallbacks: [en] }
PHP
$container->loadFromExtension('framework', array(
'translator' => array('fallbacks' => array('en')),
));
Abstract strings (i.e. "messages") by wrapping them in calls to the Translator ("Basic Translation").
public function indexAction()
{
$translated = $this->get('translator')->trans('Symfony is great');
return new Response($translated);
}
Create translation resources/files for each supported locale that translate each message in the application.
Symfony looks for message files (i.e. translations) in the following default locations:
the app/Resources/translations directory;
the app/Resources/<bundle name>/translations directory;
the Resources/translations/ directory inside of any bundle.
Translation File Name
The filename of the translation files is also important: each message file must be named according to the following path: domain.locale.loader (e.g. filename: navigation.en.xlf):
domain: An optional way to organize messages into groups (e.g. admin, navigation or the default messages) - see Using Message Domains;
locale: The locale that the translations are for (e.g. en_GB, en, etc);
loader: How Symfony should load and parse the file (e.g. xlf, php, yml, etc).
The loader can be the name of any registered loader. By default, Symfony provides many loaders, including:
xlf: XLIFF file;
php: PHP file;
yml: YAML file.
The choice of which loader to use is entirely up to you and is a matter of taste. The recommended option is to use xlf for translations.
Determine, set and manage the user's locale for the request and optionally on the user's entire session.
Clear the cache:
php bin/console c:c
The Translation Process
To actually translate the message, Symfony uses a simple process:
The locale of the current user, which is stored on the request is determined;
A catalog (e.g. big collection) of translated messages is loaded from translation resources defined for the locale (e.g. fr_FR). Messages from the fallback locale are also loaded and added to the catalog if they don't already exist. The end result is a large "dictionary" of translations.
If the message is located in the catalog, the translation is returned. If not, the translator returns the original message.
This helped me to get it worked, since clearing the cache also didn't help.
Symfony 4.6.2:
Try this command to update translation files:
php bin/console translation:update --dump-messages --force de
(Source: https://symfony.com/doc/current/translation.html#configuration)
I can already answer your 2 questions:
1: you can look at
https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php#L97
https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Translation/Translator.php#L174
2: If you're talking about gedmo doctrine extensions, or Knplabs DoctrineBehaviors, no, there is no way it conflicts with symfonys's translator. These are 2 independant pieces.
Just faced the same issue and fixed it by $this->get('translator')->setLocale('fr'); in the controller action. I fixed it by adding {_locale} in the route path.

Resources