# Get an array from an I18n declaration?

**URL:** <https://www.ruby-forum.com/t/get-an-array-from-an-i18n-declaration/208929>\
**Category:** Rails I18n\
**Created:** [June 30, 2011, 4:44pm UTC](https://www.ruby-forum.com/t/get-an-array-from-an-i18n-declaration/208929 "2011-06-30T16:44:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [June 30, 2011, 4:44pm UTC](https://www.ruby-forum.com/t/get-an-array-from-an-i18n-declaration/208929/1 "2011-06-30T16:44:11Z")

</div>

Hi,

I am storing some text in a model that is separated by new lines, and  
I wanted to offer some default text in case the records in the model  
do not exist… So I tried to emulate it by doing:

en:  
foo:  
item1\r\n  
item2\r\n  
item3\r\n

… However, when I retrieve this, it shows up as item1\r\nitem2\r  
\n

where the ""s are escaped… So in order to split my string by  
new lines, I have to do:  
text.split(/\r\n|\r\n/), which I am not crazy about.

I was wondering if there is a simple way I can just make a list in  
yaml so that when I do t(:foo), i will get [“item1”, “item2”,  
“item3”] ?

thanks.

-patrick

---

<div class="post-metadata">

**Author:** ![patrick99e99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/858c86/32.png) [@patrick99e99](https://www.ruby-forum.com/u/patrick99e99)\
**Post date:** [June 30, 2011, 5:08pm UTC](https://www.ruby-forum.com/t/get-an-array-from-an-i18n-declaration/208929/2 "2011-06-30T17:08:20Z")

</div>

en:  
foo:  
- “item one”  
- “item two”  
- “item three”

I18n.translate(:foo)  
=\> [“item one”, “item two”, “item three”]

- Martin

---

<div class="post-metadata">

**Author:** ![patrick99e99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/858c86/32.png) [@patrick99e99](https://www.ruby-forum.com/u/patrick99e99)\
**Post date:** [June 30, 2011, 5:08pm UTC](https://www.ruby-forum.com/t/get-an-array-from-an-i18n-declaration/208929/3 "2011-06-30T17:08:57Z")

</div>

Did you try the YAML docs or a quick search? Pretty sure it’s  
supported and shouldn’t be hard to find.

Sent from my iPhone

---

<div class="post-metadata">

**Author:** ![patrick99e99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/858c86/32.png) [@patrick99e99](https://www.ruby-forum.com/u/patrick99e99)\
**Post date:** [June 30, 2011, 7:39pm UTC](https://www.ruby-forum.com/t/get-an-array-from-an-i18n-declaration/208929/4 "2011-06-30T19:39:47Z")

</div>

awesome… thanks!
