README.md in i18n-js-4.0.0 vs README.md in i18n-js-4.0.1

- old
+ new

@@ -1,7 +1,7 @@ <p align="center"> - <img width="250" height="58" src="https://github.com/fnando/i18n-js/raw/main/i18njs.png" alt="i18n.js"> + <img width="250" height="58" src="https://github.com/fnando/i18n-js/raw/main/images/i18njs.png" alt="i18n.js"> </p> <p align="center"> Export <a href="https://rubygems.org/gems/i18n">i18n</a> translations to JSON. <br> @@ -10,18 +10,18 @@ <p align="center"> <small> Oh, you don't use Ruby? No problem! You can still use i18n-js <br> - and the - <a href="https://www.npmjs.com/package/i18n-js/v/next">companion JavaScript package</a>. + and the + <a href="https://www.npmjs.com/package/i18n-js/v/latest">companion JavaScript package</a>. </small> </p> <p align="center"> <a href="https://github.com/fnando/i18n-js"><img src="https://github.com/fnando/i18n-js/workflows/ruby-tests/badge.svg" alt="Tests"></a> - <a href="https://rubygems.org/gems/i18n-js"><img src="https://img.shields.io/gem/v/i18n-js.svg?include_prereleases" alt="Gem"></a> + <a href="https://rubygems.org/gems/i18n-js"><img src="https://img.shields.io/gem/v/i18n-js.svg" alt="Gem"></a> <a href="https://rubygems.org/gems/i18n-js"><img src="https://img.shields.io/gem/dt/i18n-js.svg" alt="Gem"></a> <a href="https://tldrlegal.com/license/mit-license"><img src="https://img.shields.io/:License-MIT-blue.svg" alt="MIT License"></a> </p> ## Installation @@ -43,11 +43,19 @@ - Patterns can use `*` as a wildcard and can appear more than once. - `*` will include everything - `*.messages.*` - Patterns starting with `!` are excluded. - `!*.activerecord.*` will exclude all ActiveRecord translations. +- You can use groups: + - `{pt-BR,en}.js.*` will include only `pt-BR` and `en` translations, even if + more languages are available. +> **Note**: +> +> Patterns use [glob](https://rubygems.org/gems/glob), so check it out for the +> most up-to-date documentation about what's available. + The config file: ```yml --- translations: @@ -129,17 +137,19 @@ ignore: - en.mailer.login.subject - en.mailer.login.body ``` -> **Note**: In order to avoid mistakenly ignoring keys, this configuration -> option only accepts the full translation scope, rather than accepting a -> pattern like `pt.ignored.scope.*`. +> **Note**: +> +> In order to avoid mistakenly ignoring keys, this configuration option only +> accepts the full translation scope, rather than accepting a pattern like +> `pt.ignored.scope.*`. ## Automatically export translations -### Using watchman +### Using [watchman](https://facebook.github.io/watchman/) Create a script at `bin/i18n-watch`. ```bash #!/usr/bin/env bash @@ -180,15 +190,15 @@ ``` i18n: ./bin/i18n-watch ``` -### Using guard +### Using [guard](https://rubygems.org/gems/guard) -Install [guard](https://rubygems.org/packages/guard) and -[guard-compat](https://rubygems.org/packages/guard-compat). Then create a -Guardfile with the following configuration: +Install [guard](https://rubygems.org/gems/guard) and +[guard-compat](https://rubygems.org/gems/guard-compat). Then create a Guardfile +with the following configuration: ```ruby guard(:"i18n-js", run_on_start: true, config_file: "./config/i18n.yml", @@ -202,11 +212,11 @@ If your files are located in a different path, remember to configure file paths accordingly. Now you can run `guard start -i`. -### Using listen +### Using [listen](https://rubygems.org/gems/listen) Create a file under `config/initializers/i18n.rb` with the following content: ```ruby Rails.application.config.after_initialize do @@ -214,21 +224,41 @@ I18nJS.listen end ``` The code above will watch for changes based on `config/i18n.yml` and -`config/locales`. You can customize these options with -`I18nJS.listen(config_file: "config/i18n.yml", locales_dir: "config/locales")`. +`config/locales`. You can customize these options: +- `config_file` - i18n-js configuration file +- `locales_dir` - one or multiple directories to watch for locales changes +- `options` - passed directly to [listen](https://github.com/guard/listen/#options) + +Example: + +```ruby +I18nJS.listen( + config_file: "config/i18n.yml", + locales_dir: ["config/locales", "app/views"], + options: {only: %r{.yml$} +) +``` + ### Integrating with your frontend You're done exporting files, now what? Well, go to [i18n](https://github.com/fnando/i18n) to discover how to use the NPM package that loads all the exported translation. ### FAQ +#### I'm running v3. Is there a migration plan? + +[There's a document](https://github.com/fnando/i18n-js/tree/main/MIGRATING_FROM_V3_TO_V4.md) +outlining some of the things you need to do to migrate from v3 to v4. It may not +be as complete as we'd like it to be, so let's know if you face any issues +during the migration is not outline is that document. + #### How can I export translations without having a database around? Some people may have a build process using something like Docker that don't necessarily have a database available. In this case, you may define your own loading file by using something like @@ -244,12 +274,14 @@ require "action_view/railtie" I18n.load_path += Dir["./config/locales/**/*.yml"] ``` -Notice that you may not need to load ActiveSupport and ActionView lines, or even -may need to add additional requires for other libs. With this approach you have -full control on what's going to be loaded. +> **Note**: +> +> You may not need to load ActiveSupport and ActionView lines, or even may need +> to add additional requires for other libs. With this approach you have full +> control on what's going to be loaded. ## Maintainer - [Nando Vieira](https://github.com/fnando)