2009-08-10 3 views

답변

23

일반적으로 모든 경로 또는 이미지 이름에 로캘 이름을 삽입합니다. 첫 번째 경우, 다른 로케일이 내가 지역화 할 필요가 없습니다 많은 자산이 나는 때문에

/public/images/file.it.png 
/public/images/file.en.png 

image_tag("file.#{I18n.locale}.png") 

내가 일반적으로 두 번째 솔루션을 선호하는 두 번째 경우

/public/images/en/file.png 
/public/images/it/file.png 

image_tag("#{I18n.locale}/file.png") 

에 대해 서로 다른 폴더를 생성 종종 동일한 폴더에 번역 된/공통 자산을 유지하여 컨 피규 레이션 오버 패턴을 활용해야합니다.

-3

최근 응용 프로그램에서 코드가 약간 지저분 할 수는 있지만 약간의 성공으로 처음으로 i18n 번역을 시도했습니다. application_controller에서

나는이 :

class ApplicationController < ActionController::Base 

    before_filter :set_locale 

    AVAILABLE_LOCALES = I18n.backend.available_locales 

    private 

########## 
    # Internationalisation 
    # For more information see http://guides.rubyonrails.org/i18n.html 
    # Additional locale starting points can be found here http://github.com/svenfuchs/rails-i18n/tree/a0be8dd219ccce6716955566ee557cc75122cb33/rails/locale 

    def tld 
    domain_array = request.subdomains.split(".") 
    domain_array[0] == "www" ? domain_array[1].to_s : domain_array[0].to_s 
    end 

    def available_locales 
    AVAILABLE_LOCALES 
    end 

    def set_locale 
    I18n.locale = extract_locale_from_subdomain 
    end 

    def extract_locale_from_subdomain 
    (available_locales.include? tld.to_sym) ? tld : nil unless tld.blank? 
    end 

end 

이 기본적으로 지정된 하위 도메인에서 해당 언어를 조회, 그래서 http://en.mysite.com는 영어이며 http://it.mysite.com 이탈리아에 있습니다.

다음은 간단하게 사용 귀하의 의견입니다 :

<%= t(:click_to_edit) %> 
마지막으로는, 설정에/로케일이 필요한 번역과 en.yml 파일 생성

:

en: 
    admin_menu: "Admin Menu" 
    Arabic: "Arabic" 
    back: "Back" 
    Basque: "Basque" 
    blogs: "Blogs" 
    blog_list: "Blog List" 
    blogroll: "Blogroll" 

이탈리아의 파일이 포함를 :

it:  
    admin_menu: "Menu Amministrazione" 
    Arabic: "Italian Arabic" 
    back: "Indietro" 
    Basque: "Italian Basque" 
+2

질문은 텍스트 콘텐츠가 아닌 이미지를 나타냅니다. –

3

이 오래된 질문에 2 센트 씁니다.

나는 도우미 메서드 접근 방식을 선호하고 기본 로케일을 무시, 그래서처럼 사용할 내 모든 자산

def localize(image_path, type = :svg) image_path.concat('.').concat(I18n.locale.to_s) if I18n.locale != I18n.default_locale image_path.concat('.').concat(type.to_s) if type image_path end

.en를 추가 할 필요가 없습니다 :

= image_tag localize('svg/feature-one-bubble-copy')

관련 문제