Great Screencast, thanks Ryan.
I've been doing apps in multiple languages for quite some time now. I started with ruby-gettext about 2 years ago and just switched to Rails i18n in a recent app. It's really great to have an API for i18n included in Rails.
For those who are interested in i18n - I'm posting thoughts, ideas and experiences with Rails i18n to my blog from time to time.
Btw, I modified the rails-i18n repository with many core translations you mentioned and made it a plugin. I found it a bit easier and more maintanable to simply update a plugin instead of copy&pasting the core translations into my own .yml files every time.
The plugin can be found at http://github.com/zargony/rails-i18n
Another great Railscast! Sorry that this is off topic, but I've been using the instance variable @current_user in my Rails app. Would switching to the local variable reap any benefits (like speed improvements?) Thanks!
Any decent web application need to have localisation sooner or latter. Now this task is much easer and this screen cast is great first step in localisation process.
@Ben, I may cover model translation after this series on Rails 2.2 is done, thanks for the suggestion.
@Andrew, the "current_user" in my case is actually a method call. I prefer this over a before_filter which sets a @current_user because it will only load the current user if it needs access to it, not on every page all the time.
Translating the text and formats has always been important but it's half the battle when it comes to internationalization.
The other half is letting the user choose the language and having those pages being indexed in their specific languages.
I personally like to have the language as part of the URL because it makes for a very simple selection mechanism (and it makes every entities distinct one even for the search engines).
@Jean, you could do this fairly easily with subdomains. Since the language is set in a before filter you could combine this episode with #123 on subdomains.
http://railscasts.com/episodes/123-subdomains
Great screencast...the only thing missing is database translations.
Also, once you start translating the units of currency, you'll have to start converting prices from say "dollars to euros". Either dynamically based on the current exchange rate, or hard coded somewhere.
What if Wookie would like to enter some number in the form? The application needs to convert this number and probably save it to db. What are best practices to achive that?
using the browser settings is one of the step toward presenting the correct language... at the same time limiting yourself to the preferred language of the browser would detract some of your users (for example, my browser here has a french default but I still prefer to view some sites in english, even when french is offered).
At the same time, you have to take in account that browsers are not the only client your website will have (I can still recall one website I was asked to look into, they were indexed in one of the three languages the site was available into... the reasons... language selection was done through cookies and search engines don't understand cookies).
The language selection process is important. I usually take an approach similar to the ibm.com website (having the locale being part of the url)... as Ryan suggests, sub-domains can achieve the same trick.
Thanks again Ryan for this great tutorial. In the past, I have used Globalize to translate UI content. Sometimes when the layout was a little bit different from english to french, it was more easy just to create an other view to handle the job. Something like index.fr.html.erb. Can we do so in 2.2?
Thanks! Great episode! But what about models and validation translation? Is possibile with I18n? If so maybe you could show us how to with an advanced episode xD
@Andrea: Yes, models, attributes and validation messages can be translated as well as time/date formats or e.g. output of distance_of_time_in_words. You might want to have a look at the various "localized_dates" and "rails-i18n" repositories on github.
Josh: I think Ryan uses iShowU for his screencasts, but I expect he has a decent-ish microphone and setup because it sounds very clear and is well edited.
This is cool I even created a Textmate command to help when localizing an existing app. Just select some text, and run it, it will ask for a desired translation name, and insert the appropriate <%=t 'name' %> for you. The translation line that you can insert into a yaml file is copied to the clipboard, ready for pasting ;) That makes it so much faster.
You can find it here if you're interested:
http://gist.github.com/31133
Hello,
nice screencast.
As I require full customization functions via the admin webinterface of my Rails app, I cannot afford restarting the server everytime a locale is changed/added. Do you know of a way to disable that or flush the cache at runtime?
Hey i would like to know if someone has approach I18n for the active merchant plugin
because i'm trying to do it but i can't make it work properly. I
receive the errors messages only in english, i can't get'em translated.
Thanks in advance!
Is there a preferred method for translations of large amounts of copy? For example, if there is a "terms of service" or "privacy policy" page, what is the best way to handle the large amount of copy in multiple languages? Thanks so much for your help.
I want to put the i18n variables into global.inc, but only apply them if i18n is enabled. I've put the following code into global.inc: if (module_exists('i18n'))
Yeah, that's what I need!
And now I can remove Globalite for sure 8-)
Thanks, Ryan!
Nice Screencast!
All we need now is a good way to do model translation... :)
Great Screencast, thanks Ryan.
I've been doing apps in multiple languages for quite some time now. I started with ruby-gettext about 2 years ago and just switched to Rails i18n in a recent app. It's really great to have an API for i18n included in Rails.
For those who are interested in i18n - I'm posting thoughts, ideas and experiences with Rails i18n to my blog from time to time.
Wookie wookie ^^ ...
or in other words ^^ ... just great.
Btw, I modified the rails-i18n repository with many core translations you mentioned and made it a plugin. I found it a bit easier and more maintanable to simply update a plugin instead of copy&pasting the core translations into my own .yml files every time.
The plugin can be found at http://github.com/zargony/rails-i18n
Another great Railscast! Sorry that this is off topic, but I've been using the instance variable @current_user in my Rails app. Would switching to the local variable reap any benefits (like speed improvements?) Thanks!
Awsome!
Does anyone know if it will be possible to have some specific locale strings into engines?
Any decent web application need to have localisation sooner or latter. Now this task is much easer and this screen cast is great first step in localisation process.
Woohoo!
Have been waiting for this screencast. Will have to watch it when i'm back at home...
Thanks for this screencast!!
@Ben:
For the model translation there is Globalize2 http://github.com/joshmh/globalize2/tree/master
@Ben, I may cover model translation after this series on Rails 2.2 is done, thanks for the suggestion.
@Andrew, the "current_user" in my case is actually a method call. I prefer this over a before_filter which sets a @current_user because it will only load the current user if it needs access to it, not on every page all the time.
@David, thanks, marked.
Translating the text and formats has always been important but it's half the battle when it comes to internationalization.
The other half is letting the user choose the language and having those pages being indexed in their specific languages.
I personally like to have the language as part of the URL because it makes for a very simple selection mechanism (and it makes every entities distinct one even for the search engines).
You have any thoughts on that level??
@Jean, you could do this fairly easily with subdomains. Since the language is set in a before filter you could combine this episode with #123 on subdomains.
http://railscasts.com/episodes/123-subdomains
Great screencast...the only thing missing is database translations.
Also, once you start translating the units of currency, you'll have to start converting prices from say "dollars to euros". Either dynamically based on the current exchange rate, or hard coded somewhere.
Good work Ryan, like always. ;-)
i18n is very important and this screencast is a good start to start with internationalization.
Locale is pronounced "loh-CAL".
@Jean-Marc: that should be easy. You could e.g. use a (configurable) constant hash as a tld=>locale lookup, e.g.
TLD_LANGS = { 'com' => 'en', 'de' => 'de' }
and use a before_filter in ApplicationController to set the locale based on the current request host like
I18n.locale = TLD_LANGS[request.host.split('.').last] || 'en'
Is there any reason an application shouldn't display the preferred locale set in the browser? Is there an easy way to access this locale?
Nice Screencast!
Maybe it is nice to add something like routes translations? Is that even possible?
Nice screencast, as always, thanks!
What if Wookie would like to enter some number in the form? The application needs to convert this number and probably save it to db. What are best practices to achive that?
@Steve,
using the browser settings is one of the step toward presenting the correct language... at the same time limiting yourself to the preferred language of the browser would detract some of your users (for example, my browser here has a french default but I still prefer to view some sites in english, even when french is offered).
At the same time, you have to take in account that browsers are not the only client your website will have (I can still recall one website I was asked to look into, they were indexed in one of the three languages the site was available into... the reasons... language selection was done through cookies and search engines don't understand cookies).
The language selection process is important. I usually take an approach similar to the ibm.com website (having the locale being part of the url)... as Ryan suggests, sub-domains can achieve the same trick.
Jean-Marc
Thanks again Ryan for this great tutorial. In the past, I have used Globalize to translate UI content. Sometimes when the layout was a little bit different from english to french, it was more easy just to create an other view to handle the job. Something like index.fr.html.erb. Can we do so in 2.2?
Thanks
Marc
Power Pack Performance of rails 2.2 !!!!
Thanks! Great episode! But what about models and validation translation? Is possibile with I18n? If so maybe you could show us how to with an advanced episode xD
@Andrea: Yes, models, attributes and validation messages can be translated as well as time/date formats or e.g. output of distance_of_time_in_words. You might want to have a look at the various "localized_dates" and "rails-i18n" repositories on github.
Woohoo!
Thank you, thank you, thank you!
Great screencast and exactly what I needed.
Awesome screencasts... I've been a long-time fan.
Can you maybe give me a tip on what software you use to create these screencasts?
I'd like to produce some of my own, and yours are always very high quality. Any hints you can offer would be great!
Make sure you check the plugin Localized Templates... translating long texts can be hard, so I prefer to have templates fully translated.
http://github.com/josevalim/localized_templates/
Thanks again Ryan- great cast.
Josh: I think Ryan uses iShowU for his screencasts, but I expect he has a decent-ish microphone and setup because it sounds very clear and is well edited.
Gav
@Gavin: Thanks for the tip!
I'll check out iShowU...
@Mark Wilden
'Locale is pronounced "loh-CAL".'
It's not in my "loh-cAIL". ;-)
This is cool I even created a Textmate command to help when localizing an existing app. Just select some text, and run it, it will ask for a desired translation name, and insert the appropriate <%=t 'name' %> for you. The translation line that you can insert into a yaml file is copied to the clipboard, ready for pasting ;) That makes it so much faster.
You can find it here if you're interested:
http://gist.github.com/31133
My site is very language centric, and recently i used some fragment caching to speed up page loads. Has anyone tried I18n with fragment caching?
Hurray! My voice has been heard!
Thank you so much Ryan for this screencast!!
Why do I get ActionView::TemplateError (undefined method `each' for false:FalseClass) when I use <%= t 'hello' %> in a view??
Great RailsCast, thanks!
[pt] Grande Railscast, obrigado!
Hello,
nice screencast.
As I require full customization functions via the admin webinterface of my Rails app, I cannot afford restarting the server everytime a locale is changed/added. Do you know of a way to disable that or flush the cache at runtime?
Found it:
I18n.reload!
<% title t('welcome.title') %>
does this mean we can no longer do:
<%= title t('welcome.title') %>
I have tried it and it displays the entire :title in the browser.
Hey i would like to know if someone has approach I18n for the active merchant plugin
because i'm trying to do it but i can't make it work properly. I
receive the errors messages only in english, i can't get'em translated.
Thanks in advance!
Hi,
as the error messages are hardcoded in ActiveMerchant, there's no elegant way to translate them.
Anyone have any suggestions for key names and organization of translation files?
Why the locale files are not included within rails ? It's would be easier to update. And every rails version will have the same locales files.
Excellent railcast, Ryan! Thank you very much. It answered all questions that I had about Rails 2.3 I18n features :)
Is there a preferred method for translations of large amounts of copy? For example, if there is a "terms of service" or "privacy policy" page, what is the best way to handle the large amount of copy in multiple languages? Thanks so much for your help.
Wookie! ha!
This was just the Railscast that I needed---I was going to implement I18N in a different way. Short and right to the point. Thanks, Ryan!
I noticed you used a 'ss' shortcut/alias to start your server. How might you do that Ryan?
Great episode! Arigato Ryan :)
I want to put the i18n variables into global.inc, but only apply them if i18n is enabled. I've put the following code into global.inc: if (module_exists('i18n'))