2017-03-23 9 views
0

내 문의 양식 중 하나에 미리 채워진 메시지가있어서 응시자가 불량 메시지를 피할 수 있고 초기 좋은 기초가됩니다.매개 변수를 사용하여 무작위로 I18n 변환 선택

지금까지 단일 message_template을 사용하고 있었지만 무작위 목록으로 다양성을 소개하고자합니다.

내 번역 작업을 몇 가지 변수를 필요로 제대로

원래 내가 가진 이런 걸 내가 임의의 번역 문자열로 전환하려면

# locales/en.yml 
en: 
    message_template: "Hello %{name}, how are you on this %{day} !" 

# my_view.html.erb 
<%= t(:my_template, name: @user.name, day: DateTime.now.strftime('B') %> 

(즉, 목록에서 임의의 번역을 따기) 그리고 여전히 변수를 대체하십시오.

뭔가 작업 구문이 될 것입니다 무엇

# locales/en.yml 
en: 
    message_templates: 
    - "Hello %{name}, how are you on this %{day} !" 
    - "Hi %{name}, nice %{day} isn't it ? how are you ?" 

# my_view.html.erb 
<%= t('my_templates.sample'), name: @user.name, day: DateTime.now.strftime('B') %> 

같은?

는 참고 :

안녕 % {이름}, 좋은 % {일}가되지 않습니다 :

나는 <%= t('my_templates, name: @user.name, day: DateTime.now.strftime('B')).sample %>는하지만 PARAM 값으로 문자열을 대체하지 얻을 시도? 잘 지냈어요?

+0

의 콤보를 사용 –

답변

0

나는 나는 또한 내가 그 (예를 들어, 사용 카피 바라)을 테스트 할 수있는 방법 궁금 sample, tI18n.interpolate

<%= I18n.interpolate(
    t('my_templates').sample, 
    name: @user.name, 
    day: DateTime.now.strftime('B') 
%>