using rb files for locales

29 views
Skip to first unread message

fugee ohu

unread,
Aug 24, 2017, 7:33:56 PM8/24/17
to Ruby on Rails: Talk
config/locales/en.rb

en:
   hello: "Hello world"

Rails complains unexpected : expecting end of input at the first :

Antônio Augusto Sousa Britto

unread,
Aug 24, 2017, 8:57:09 PM8/24/17
to rubyonra...@googlegroups.com
en.yml

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/bb956f27-c699-4039-9cea-ebc93ab6da41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

fugee ohu

unread,
Aug 25, 2017, 3:12:41 AM8/25/17
to Ruby on Rails: Talk


On Thursday, August 24, 2017 at 8:57:09 PM UTC-4, Antônio Augusto Sousa Britto wrote:
en.yml
2017-08-24 20:33 GMT-03:00 fugee ohu <fuge...@gmail.com>:
config/locales/en.rb

en:
   hello: "Hello world"

Rails complains unexpected : expecting end of input at the first :

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.


That's not a valid answer Moderator please remove his answer

Norbert Melzer

unread,
Aug 25, 2017, 3:30:10 AM8/25/17
to rubyonra...@googlegroups.com
fugee ohu <fuge...@gmail.com> schrieb am Fr., 25. Aug. 2017 um 09:12 Uhr:

That's not a valid answer Moderator please remove his answer


The answer that was given to you was more than valid, but you weren't able to read it correctly. The code you showed us was obviously YAML, therefore the file ending should have been yml, as pointed out. Of course, as far as I remember there are ways to use ruby files for localisation, but then you have to use ruby syntax, not YAML.

Also this is a mailinglist, and the mods do not have access to my personal mailbox, I hope at least ;) Therefore deletion is rather useless. But you are free to delete the mails you received in your personal mailbox.
 
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

fugee ohu

unread,
Aug 25, 2017, 6:13:16 AM8/25/17
to Ruby on Rails: Talk

The rails docs say i can use rb or yml but they don't say what the syntax for rb should be They do say rb is preferable because it'll break with errors where yml will leave you guessing why things aren't being displayed as you expected, so I wanted to know the right rb syntax

Norbert Melzer

unread,
Aug 25, 2017, 7:27:33 AM8/25/17
to Ruby on Rails: Talk

So not the answer has been a bad one but your question was.

I've never used I18N and L21N in rails. So I can't help you with that.


Norbert Melzer

unread,
Aug 25, 2017, 7:32:15 AM8/25/17
to Ruby on Rails: Talk

Rails guides say this

> You may use YAML (.yml) or plain Ruby (.rb) files for storing your translations in SimpleStore

So it seems as if you just need to write a script that modifies some simple store called thing, you might try to find documentation about that.

The very same guides do also state that yaml is preferred but has downsides...

Hassan Schroeder

unread,
Aug 25, 2017, 10:30:03 AM8/25/17
to rubyonrails-talk
On Fri, Aug 25, 2017 at 3:13 AM, fugee ohu <fuge...@gmail.com> wrote:

> The rails docs say i can use rb or yml but they don't say what the syntax
> for rb should be They do say rb is preferable

What doc says that? Certainly not this one:

http://guides.rubyonrails.org/i18n.html

which also includes an example of using Ruby rather than YAML

http://guides.rubyonrails.org/i18n.html#how-to-store-your-custom-translations

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

fugee ohu

unread,
Aug 25, 2017, 11:30:11 AM8/25/17
to Ruby on Rails: Talk


http://guides.rubyonrails.org/i18n.html:

You may use YAML (.yml) or plain Ruby (.rb) files for storing your translations in SimpleStore. YAML is the preferred option among Rails developers. However, it has one big disadvantage. YAML is very sensitive to whitespace and special characters, so the application may not load your dictionary properly. Ruby files will crash your application on first request, so you may easily find what's wrong. (If you encounter any "weird issues" with YAML dictionaries, try putting the relevant portion of your dictionary into a Ruby file.)

If your translations are stored in YAML files, certain keys must be escaped. They are:

  • true, on, yes
  • false, off, no
 
Reply all
Reply to author
Forward
0 new messages