Best Practices / Rails Internationalization App

I am new to rubies and rails and started building the app.

My goal is to create this so that I can easily translate the contents of the rails application and display the contents of the website in the locale preferred by the registered user.

Evaluate any entries from some of the best practices or links to any readable documentation to create a web application that can be easily translated?

Thank you Krish.

+3
source share
6 answers

Check out the Rails Internationalization API (I18n) . He does everything that you described.

+4
source
+3

ready_for_i18n , erb . .

+3

, Rails. (, ).

, :

:

. , ( ) .

:

  • : .

  • : / .

. ( ) ( ).

Globalize .

/:

, , Rails + Globalize, ... , .

  • I18n.locale . Globalize, Globalize.locale /.

  • I18n.locale, Globalize.locale . Thread, .

  • Globalize.locale I18n.locale I18n.locale. . ( , -, ).

  • Globalize.locale ( I18n.locale), .

  • Reset I18n.locale Globalize.locale . rspec

    RSpec.configure do |config|
      config.after(:each) do 
        I18n.locale = :en
        Globalize.locale = :en
      end
    end
    
  • , URL-, .

  • , .

  • When you are working in your rails application, you are probably using default_url_optionsto use the I18n.localedefault locales for your route / path helpers as a parameter. However, this does not work in tests. I chose a solution from this github issue on rspec-rails.

    Monkey patch I ActionDispatch::Routing::RouteSetlike this:

    class ActionDispatch::Routing::RouteSet
      def url_for_with_locale_fix(options={})
        url_for_without_locale_fix(options.merge(:locale => I18n.locale))
      end
    
      alias_method_chain :url_for, :locale_fix
    end
    
  • Set the translation helper tas a wrapper around the I18n.t method

    module I18nHelper
      def t string, options = {}
        I18n.t string, options
      end
    end
    
    RSpec.configure do |config|
      config.include I18nHelper
    end
    
0
source

Source: https://habr.com/ru/post/1786629/


All Articles