0

나는 레일스에 처음 왔고, 나는 RTL 웹 사이트에서 일하고있다! comment.count 및 get_upvotes.size의 복수형을 수정하여 다른 언어 단어로 대체하려고합니다. Rails Internationalization (I18n)으로 할 수 있다고 들었지만 제 질문에 대한 명확한 답을 찾을 수 없었습니다.레일에서 덧글 및 좋아하는 것에 대한 복수화를 제거하거나 편집하는 방법

#post_show 
    %h1= @post.title 
    %p.username 
     before 
     = time_ago_in_words(@post.created_at) 
    .clearfix 
     .post_image_description 
      = image_tag @post.image.url(:medium) 
      .description= simple_format(@post.description) 
     .post_data 
      = link_to "Project link", @post.link, class: "btn btn-warning btn-block" 
      = link_to like_post_path(@post), method: :get, class: "data" do 
       %i.fa.fa-check 
       = pluralize(@post.get_upvotes.size, "Like") 
      %p.data 
       %i.fa.fa-comments.o 
       = pluralize(@post.comments.count, "Comment") 
      - if @post.user == current_user 
       = link_to "Edit", edit_post_path(@post), class: "data" 
       = link_to "Delete", post_path(@post), method: :delete, data: { confirm: "Sure?" },class: "data" 

지금 필요한 건 그래서 복수화을 취소 할 경우 2 개의 댓글거나 복수형과 의견 변경되지 않습니다까지 더 쇼 :

다음은 show.html.erb 페이지 내 코드입니다. 대신 댓글과 동일하게 유지됩니다.

도움을 주시면 감사하겠습니다. 더 많은 정보가 필요하면 알려주세요! 감사합니다

+0

pluralize 메서드를 사용하지 마십시오. '= "#{@post.comments.count} Comment"' – Swards

+0

대체 할 대상은 무엇입니까? – hekmat

답변

1

정확하게 이해한다면 복수화를 유지하면서과 Comment을 I18n을 사용하여 번역하고 싶습니까? 그런 다음

pluralize(@post.get_upvotes.size, t('models.posts.votes')) pluralize(@post.comments.count, t('models.posts.comments'))

을 다음 config/locales/en.yml

en: 
    models: 
    posts: 
     votes: Like 
     comments: Comment 

에 w config/locales/ro.yml

ro: 
    models: 
    posts: 
     votes: Aprecieri 
     comments: Comentarii 

레일에 : 귀하의 의견에

, 당신은 변경해야 당신이 설정 한 변수에 따라 적절한 언어 팩을 자동으로 선택합니다.

예를 들어, URL에 다음과 같이 전달하고자한다면 : www.myapp.com?lang=en 레일스는 en.yml 로케일을 사용합니다. www.myapp.com?lang=roro.yml 로케일을 사용합니다.

언어 선택 방법은 사용자에게 달려 있습니다.

+0

대단한데요! 그러나, 내가 사용하고있는 언어는 아랍어입니다. 0 또는 2 이상의 주석이있을 때 단어 끝에는 복수형을 나타내는 S가 여전히 있습니다. 예를 들어. 저는 S가 아랍어로 나타나길 원치 않습니다. – hekmat

+0

상자 밖에서는 그렇게 생각하지 않습니다. 언어가 아랍어 인 경우 문자열을 복수화하지 않는 도우미를 만들어야 할 가능성이 큽니다. – Vlad

+0

확인. 어떻게'{post.comments.count} Comment'의 복수화자를 사용하지 않고 문자열을 사용하면 어떨까요? – hekmat

관련 문제