If you use Doctrine, then you probably know how lazy loading can hurt your performance. I carefully craft every query to everything that I need in one shot, but only what I need. One thing that evaded me at first was the i18n part.
Model Relationships
I am pleased with the way Doctrine + symfony magically creates all my models and database tables with i18n support. All my relationship names are explicitly defined in the schema.yml file. So, if I want to get all products in a transaction, I can access it via $transaction->Products. When crafting a query, I would say ->leftJoin(‘t.Products’) to make sure to load all the products at the same time as the transaction, potentially saving hundreds of queries later.
I18n
Since the i18n relationship is defined in a special way in schema.yml, without specifying a relationship name, I wasn’t sure how to write my Left Join. I looked up the Base[ClassName].class.php file but did not find anything useful. After analyzing all the parent classes, I found it: Translation. It might have seem obvious since the tables are names product_translation, but that element eluded me and I did not find anything in the documentation at the time regarding this.
Other uses
Now that I can get my product names with ->leftJoin(‘p.Translation’), I cut the number of queries in at least two. Knowing the Translation relationship can have other uses, like counting the number of translations in your code and warning the user about missing translations (no product name in French!). I can also use the Translation relationship to make my search-engine friendly URLs multilingual. I can write about this last one in another post if I get such a request.
The uses for the Translation relationship are infinite!
Most of the Web applications that I build are multilingual. Since I use the symfony framework often, I rely on the XLIFF standard.
The error
I used to ask my clients to send me a Word document with the translated text. This is the format that they are most comfortable with. An error occurred recently when I copied the text directly from the document to an XLIFF file. For some reason, I could only see the original, English values.
The cause and solution
I would have probably not found the error had I not validated the XML translation file. It gave me a parsing error right in the middle of various strings. They looked fine until I turned on the special characters. Apparently, some special, invisible characters generated a parsing error and broke my application. I sanitized my strings and voilà!
Good practices
Since that incident, I always turn on the special characters in my text editor so that I may pick up any glitches earlier. Also, I no longer ask clients to supply a Word document, but rather a plain text document created with Notepad. To some more technical clients, I even supply the XML with empty <target> tags that they may fill in. That makes less work for me, gives satisfaction to the clients, because they feel empowered, and prevents any parsing errors.
Thanks to all the participating communities, I was able to produce the following ConFoo video. It talks about what to expect from the 2010 conference. I hope you have as much fun watching it as I had making it.
Building a conference website as the conference was being organized is probably one of the biggest challenges I ever faced. It is also the project I’m the most proud of. I’d like to share that experience with you. By the way, the event is still in progress, so my work on the site is not done.
Throw away old code
The first decision was to throw away the old code base that dated back to the first PHP Quebec Conference in 2003. We decided to start from scratch with the Symfony framework and I was going to be in charge (yay!)
Priorities
The conference was moving on and I had to keep up with the programming. Developing the website was only part of my responsibilities as an organizer, which made things even more difficult time-wise. I had to prioritize and develop the strict minimum based on the immediate conference needs. There was very little time to test between deployments (I know, it’s bad practice).
1. Logo and design
I was learning the framework while another member of the team, Yann Larrivée, was building the project skeleton. At the same time, we had an organizer, Mathieu Chartier, and his partner prepare the logo and the website design. Last year I was the one doing it and you could clearly see that I’m no designer and no expert in Web standards. Read more…
Recent comments