컨트롤러에 소위 굴절 방식을 등록 할 수있는 레일 플러그 - 인이 i18n-inflector-rails입니다.
이러한 방법을 사용하면 I18n Inflector에 성별이나 기타 다른 종류의 정보를 투명하게 제공 할 수 있습니다.
예 : 컨트롤러에서
fr:
i18n:
inflections:
gender:
h: "hommes"
f: "femmes"
n: "neutre"
m: @h
default: n
welcome: "@{h,n:Cher|f:Chère|Bonjour}{ }{h:Monsieur|f:Dame|n:Vous|à tous}"
: 그리고
class ApplicationController < ActionController::Base
before_filter :set_gender
inflection_method :gender
# inflection method for the kind gender
def gender
@gender
end
def set_gender
if user_signed_in? # assuming Devise is in use
@gender = current_user.gender # assuming there is @gender attribute
else
@gender = nil
end
end
end
class UsersController < ApplicationController
def say_welcome
t('welcome')
# => "Cher Vous" (for empty gender or gender == :n)
# => "Chère Dame" (for gender == :f)
# etc.
end
end
나는 어떤 방식으로 국제화 지원 성별을 생각하지 않습니다. 그래서 자동으로 내장 된 솔루션은 없지만 ... 나는 틀릴 수도 있습니다! – plehoux
내가 생각했던 두 가지 아이디어는 모델에 성을 설정하고 텍스트 (일부 lamba)를 만들 때 읽거나 OR (작동하지 않는 모델의 텍스트를 덮어 쓰는 트리 구조 만들기)입니다. 나는 레일 앱을 번역 할 사람이 처음이 아니라고 생각하고 있습니다. 잘하면이 사람은 우아한 방식으로 해결되었습니다. – montrealmike