Jackdaw's Nest A Web Log

[ Log ] [ Projects ] [ About ]

Posts tagged with Symfony

# Easy Trick to Show Translation only if it Exists in Symfony 2017/03/07

I had a problem. I needed to show a translated piece of text based on a route parameter. For instance, I wanted route /category/symfony to show a translated description of symfony.

What I tried was to create translations like this

category:
	  symfony: Symfony is a framework and...
	

Now the problem I had is that I don't want to write descriptions to all of the categories. For instance, if I tried to access route /category/twig I would only see category.twig because the translation is missing.

I was a bit surprised that I couldn't find a way to show an empty string if the translation key is not defined. I came up with a simple solution like this inside the twig template

{# Set the translation key #}
{% set translationKey = "category." ~ category %}

{% if (translationKey | trans) != translationKey %}
   <p>{{ translationKey | trans }}</p>
{% endif %}

That does the trick. This piece of code will show the translation only if the trans filter returns something else than the translation key itself. Probably not the most elegant solution but it works for this use case.

# JavaScript Frustration 2016/10/05

I'm starting to get frustrated with all the front-end development kits. I'm more of a back-end guy and I've been spoiled by Symfony's long term support, excellent documentation and punctual release cycle. I wish some JS frameworks would offer the same kind of enterpriseyness.

# Symfony 3.0.0 released 2015/12/01

Wow, Symfony 3.0 has been released.

I have to say I'm a big fan of the Symfony release process. It's very professional and perfect for projects that need years of support.

I realise that talking about Symfony 3 makes people nervous and this post is going to explain the Symfony 3 strategy and the reasons why you should not panic.

Fabien Potencier / Symfony Blog

So, don't panic. Actually, 3.0 is not really that big a leap forward. It's nothing compared to the leap from Symfony 1 to Symfony 2. Just look at the upgrade guide. Of course, there are changes that you need to make, but most of the changes are in methods that have already been deprecated in previous versions.

I haven't tried updating yet but I will try it soon.

# Playing Around With Symfony Service Container 2015/11/30

Lately, I've been playing around with the Symfony Service Container. For some reason, I've never really liked it that much and I've prefered Pimple that comes with Silex framework. Defining services in YML files instead of plain PHP always felt odd.

But I think I've changed my mind now. I've just created a largish project in Symfony and now I quite like the Symfony way of defining the services. It gives you a nice distinction between configuration and your business logic. Defining the services in YML is just the configuration part, and PHP is only used for real code. That's actually pretty nice and feels good after you get used to it.

# Friday Afternoon 2015/10/16

Pretty productive week, I learned a lot about

Not bad at all.