Giter Site home page Giter Site logo

i18n_factory's Introduction

I18nFactory

Installation

gem 'i18n_factory', group: :development

Usage

If you run rails g model command, an i18n file which is described for the model will be automatically created to config/locales/<model_name>/<your_locale>.yml.

e.g.)

$ bin/rails g model Post title content:text 

will also create config/locales/post/en.yml after the model files creation.

en:
  activerecord:
    models:
      post: Post  
    attributes:
      post:
        title:   Title
        content: Content

How to update i18n files

Even if you already created the model, you can generate an i18n file.

Try to run the next command. It will update or create an i18n file, which got the model columns from the database schema.

$ bin/rails g i18n_factory:update ModelName

or

$ bin/rails g i18n_factory:update_all

Warning

既存のロケールファイルがある場合はそれを壊さないよう抜けている列のみをマージするように処理していますが、もしかしたらうまく動かない場合があるかもしれません。 うまく動かないパターンがあれば、Issue で教えていただければと思います。

Configuration

i18n_factory find your application locale from I18n.locale.

If you defined locale to ja in config/application.rb.

module YourApplicationName
  class Application < Rails::Application
    # ...
    config.i18n.default_locale = :ja
  end
end

It will create i18n files as config/locales/xxx/ja.yml.

How to set multiple locales

Try to edit config/environments/development.rb

Rails.application.configure do
  # ...
  config.after_initialize do
    I18nFactory.configure do |factory|
      factory.locales = [:ja, 'zh-TW']
    end
  end
end

It will create i18n files as

  • config/locales/xxx/ja.yml
  • config/locales/xxx/zh-TW.yml

How to avoid a specific file from update_all

If you defined I18nFactory.config.ignore_paths, it will skip loading the files to create locale files when rails g i18n_factory:update_all.

I18nFactory.configure do |factory|
  factory.ignore_paths = ['app/models/foo/bar.rb']
end

License

The gem is available as open source under the terms of the MIT License.

i18n_factory's People

Contributors

tkmfujise avatar

Stargazers

NAGATA Minoru avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.