Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Ruby, translate a helper.

Hi im working on "Build a simple ruby on rails application". In the video "updating the index page". The guy used the helper "time_ago_in_words" but i trying to make a spanish website so, is there a possible to change this helper to spanish?. I have tried to create another and copy and paste the file from github and change some words(e .g "x_days" to "x_dias") but i get errors.

Thanks.

Check this out. I did a google search and this blog came up. http://jorgebernal.info/2007/01/17/translating-dates-in-ruby-on-rails/

4 Answers

With all languages, the actual commands and such are in the original language that it was written in. You can create variables, methods, callbacks, and functions in whatever language you want. But the internal commands are set and unchangeable.

For example, in JavaScript;

var test=function(arg1,arg2) {
       return "fjdklafjkdsajkfldskla";
}

The variable "test" can be called whatever I want it to be called, but the command "function" can only be called "function".

Also, in this example, the commands "var" and "return" are static and immutable, but "arg1", "arg2" and "fjdklafjkdsajkfldskla" can be anything at all (within specific guidelines, as to not conflict with internal command names).

In conclusion, if you'd like to make your variable names and function NAMES in Spanish, you are welcome and encouraged to do so, especially if it will help fellow collaborators. But commands are usually in English (or using a specific unique name) for most programming languages.

In the case of helpers, if you like, you can find the source code and change the names of the variables and functions and nearly any "Nameable" instance. But I'd be reluctant to do that, because you'd have to change every instance of each, and any mistakes will make for a broken helper.

Hi, Thank you for your response. Actually my objetive is not change the functions names, instead i want to change their output. If you know anything like this. Please let me now. If not, well im going to use english.

link:https://github.com/rails/rails/blob/97f2c4129ae23ee074986a588628acc689a86462/actionview/lib/action_view/helpers/date_helper.rb#L156

Well, you can still go into the helper code and change the output.... by finding where the output comes from and translating it in the code, before it's output.

Yeah, but i can't find where is it, because there is a lot of functions

Hi, i think that http://jorgebernal.info/2007/01/17/translating-dates-in-ruby-on-rails/, could be useful on the future for me, but I have installed :

gem 'devise-i18n' gem 'rails-i18n'

And change the language on application.rb and everything is now in spanish. I should have know about I18n before. Joel thank you for your interest, hope to talk you again.