Missing Frame
New release after some time. This is one of the first works that implements synthesiser programming. Well, not real programming actually, only build presets on the synth and set the proper effects. A bit simple, bit it deserves a hear. Hope you like it.
Remember that anytning posted here is mine property, excepts the corresponding credits to quoted works. This tune in particular it totally original and was released under Creative Commons Attribution-Share Alike 3.0 Unported License. So don't mess up with this tune.
http://www.chimeramusic.net/files/Chimera_020_-_Rayko_-_Missing_Frame.zip
Posted in Music | no comments |
Rails ActionMailer I18n template Trick
Introduction
Rails calims that it has support for I18n internacionalization. That's true, you can build up dictionaries and use them in your views, so you don't have to write static text. The good thing, is that in Rails 2.3.4, the template engine parses the template names and including internationals templates. That is, if you use ".es", ."en" or any other language on the template name, then you can use the I18n.locale to grab templates in one language or in another.So this way, I18n.locale saves the language for the whole site in a session. There are two ways to get text in the language you want. You can use a dictionarie (or a dictionary tree, see I18n documentation), where you save traductions on tokens you create. Then in your view you call for theese tokens and get the translated text. The other way is to write the whole view in a language and then save it with a nema like "template.html.en.erb". That ".en" means that when the I18n.locale is set to "en" that view will be called. This way you can have different views for diferent languages that will be automatically fetched depending on the locale.
The problem
Now, I18n is supported in the whole Rails application, including ActionMailer. The problem is when you have to send mails in diferent languages. You may think "What's the problem with that, just set a locale and it's done", but that is not a good solution. Think that mails can be sent at anytime, the user that will receive mail may not be logged in, so the locale may no be rigth, a different user with different locale can be logued in and just using the locale in ActionMailer will result in incorrect language for users on their mails. Also, changing I18n on the go may do weird things, because I18n is for the whole site, a user that is logued in can experence problems because you're sending a mail with a different locale.
My recommendation to use a safe mailer that doesn't use locale from I18n is this: first save the users locale on the database. When sendind mail you have to fetch this attribute to you can get a template localized. Then create your templates and save them with the localized extention. Finally, on the mailer method, use the users language to fetch a template to render. Now is the tricky part. You can use render on the ActionMailr, so how to render the template we fetched? Use the @template instance variable to load the template path, see an example:
@template = "#{ActionMailer::Base::template_root}/user_mailer/signup_notification.#{user.language || 'en'}.erb"
ActionMailer::Base:tempate_root is the path to templates root to look for. Then just insert the path of your template, add the extension language from the users attribute and complete the extension. Im this example, the users atribute stores a string with short locale like "en" or "es", so you can use it directrly.
That way you specify the template you need and you don't need to use I18n. It's tricky but it may help while using ActionMailer on the same rails application.
Sources:
- http://blog.flvorful.com/articles/2009/11/22/deep-in-rails-actionmailer-deliver-part-ii
Posted in Programming | 1 comment |