• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..22-Nov-2021-

app/assets/javascripts/H22-Nov-2021-

CHANGELOG.mdH A D22-Nov-202112.7 KiB355221

README.mdH A D22-Nov-202126.2 KiB873654

package.jsonH A D22-Nov-2021594 2625

yarn.lockH A D22-Nov-20214.3 KiB132107

README.md

1# I18n.js
2
3[![Gem Version](http://img.shields.io/gem/v/i18n-js.svg?style=flat-square)](http://badge.fury.io/rb/i18n-js)
4[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
5
6[![Build Status](http://img.shields.io/travis/fnando/i18n-js.svg?style=flat-square)](https://travis-ci.org/fnando/i18n-js)
7[![Dependency Status](http://img.shields.io/gemnasium/fnando/i18n-js.svg?style=flat-square)](https://gemnasium.com/fnando/i18n-js)
8[![Code Climate](http://img.shields.io/codeclimate/github/fnando/i18n-js.svg?style=flat-square)](https://codeclimate.com/github/fnando/i18n-js)
9
10[![Gitter](https://img.shields.io/badge/gitter-join%20chat-1dce73.svg?style=flat-square)](https://gitter.im/fnando/i18n-js)
11
12It's a small library to provide the Rails I18n translations on the JavaScript.
13
14Features:
15
16- Pluralization
17- Date/Time localization
18- Number localization
19- Locale fallback
20- Asset pipeline support
21- Lots more! :)
22
23## Version Notice
24The `master` branch (including this README) is for latest `3.0.0` instead of `2.x`.
25
26
27## Usage
28
29### Installation
30
31#### Rails app
32
33Add the gem to your Gemfile.
34```ruby
35gem "i18n-js"
36```
37
38#### Rails app with [Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html)
39
40If you're using the [asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html),
41then you must add the following line to your `app/assets/javascripts/application.js`.
42
43```javascript
44//
45// This is optional (in case you have `I18n is not defined` error)
46// If you want to put this line, you must put it BEFORE `i18n/translations`
47//= require i18n
48// Some people even need to add the extension to make it work, see https://github.com/fnando/i18n-js/issues/283
49//= require i18n.js
50//
51// This is a must
52//= require i18n/translations
53```
54
55#### Rails app without [Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html)
56
57
58First, put this in your `application.html` (layout file).
59Then get the JS files following the instructions below.
60```erb
61<%# This is just an example, you can put `i18n.js` and `translations.js` anywhere you like %>
62<%# Unlike the Asset Pipeline example, you need to require both **in order** %>
63<%= javascript_include_tag "i18n" %>
64<%= javascript_include_tag "translations", skip_pipeline: true %>
65```
66
67**There are two ways to get `translations.js` (For Rails app without Asset Pipeline).**
68
691. This `translations.js` file can be automatically generated by the `I18n::JS::Middleware`.
70  Just add `config.middleware.use I18n::JS::Middleware` to your `config/application.rb` file.
712. If you can't or prefer not to generate this file,
72  you can move the middleware line to your `config/environments/development.rb` file
73  and run `rake i18n:js:export` before deploying.
74  This will export all translation files, including the custom scopes
75  you may have defined on `config/i18n-js.yml`.
76  If `I18n.available_locales` is set (e.g. in your Rails `config/application.rb` file)
77  then only the specified locales will be exported.
78  Current version of `i18n.js` will also be exported to avoid version mismatching by downloading.
79
80#### Export Configuration (For translations)
81
82Exported translation files generated by `I18n::JS::Middleware` or `rake i18n:js:export` can be customized with config file `config/i18n-js.yml`
83(use `rails generate i18n:js:config` to create it).
84You can even get more files generated to different folders and with different translations to best suit your needs.
85The config file also affects developers using Asset Pipeline to require translations.
86Except the option `file`, since all translations are required by adding `//= require i18n/translations`.
87
88Examples:
89```yaml
90translations:
91- file: 'public/javascripts/path-to-your-messages-file.js'
92  only: '*.date.formats'
93- file: 'public/javascripts/path-to-your-second-file.js'
94  only: ['*.activerecord', '*.admin.*.title']
95```
96
97If `only` is omitted all the translations will be saved. Also, make sure you add that initial `*`; it specifies that all languages will be exported. If you want to export only one language, you can do something like this:
98```yaml
99translations:
100- file: 'public/javascripts/en.js'
101  only: 'en.*'
102- file: 'public/javascripts/pt-BR.js'
103  only: 'pt-BR.*'
104```
105
106Optionally, you can auto generate a translation file per available locale if you specify the `%{locale}` placeholder.
107```yaml
108translations:
109- file: "public/javascripts/i18n/%{locale}.js"
110  only: '*'
111- file: "public/javascripts/frontend/i18n/%{locale}.js"
112  only: ['*.frontend', '*.users.*']
113```
114
115You can also include ERB in your config file.
116```yaml
117translations:
118<% Widgets.each do |widget| %>
119- file: <%= "'#{widget.file}'" %>
120  only: <%= "'#{widget.only}'" %>
121<% end %>
122```
123
124You are able to exclude certain phrases or whole groups of phrases by
125specifying the YAML key(s) in the `except` configuration option. The outputted
126JS translations file (exported or generated by the middleware) will omit any
127keys listed in `except` configuration param:
128
129```yaml
130translations:
131  - except: ['*.active_admin', '*.ransack', '*.activerecord.errors']
132```
133
134
135#### Export Configuration (For other things)
136
137- `I18n::JS.config_file_path`
138  Expected Type: `String`
139  Default: `config/i18n-js.yml`
140  Behaviour: Try to read the config file from that location
141
142- `I18n::JS.export_i18n_js_dir_path`
143  Expected Type: `String`
144  Default: `public/javascripts`
145  Behaviour:
146  - Any `String`: considered as a relative path for a folder to `Rails.root` and export `i18n.js` to that folder for `rake i18n:js:export`
147  - Any non-`String` (`nil`, `false`, `:none`, etc): Disable `i18n.js` exporting
148
149- `I18n::JS.sort_translation_keys`
150  Expected Type: `Boolean`
151  Default: `true`
152  Behaviour:
153  - Sets whether or not to deep sort all translation keys in order to generate identical output for the same translations
154  - Set to true to ensure identical asset fingerprints for the asset pipeline
155
156- You may also set `export_i18n_js` and `sort_translation_keys` in your config file, e.g.:
157
158```yaml
159export_i18n_js: false
160# OR
161export_i18n_js: "my/path"
162
163sort_translation_keys: false
164
165translations:
166  - ...
167```
168
169To find more examples on how to use the configuration file please refer to the tests.
170
171#### Fallbacks
172
173If you specify the `fallbacks` option, you will be able to fill missing translations with those inside fallback locale(s).
174Default value is `true`.
175
176Examples:
177```yaml
178fallbacks: true
179
180translations:
181- file: "public/javascripts/i18n/%{locale}.js"
182  only: '*'
183```
184This will enable merging fallbacks into each file. (set to `false` to disable).
185If you use `I18n` with fallbacks, the fallbacks defined there will be used.
186Otherwise `I18n.default_locale` will be used.
187
188```yaml
189fallbacks: :de
190
191translations:
192- file: "public/javascripts/i18n/%{locale}.js"
193  only: '*'
194```
195Here, the specified locale `:de` will be used as fallback for all locales.
196
197```yaml
198fallbacks:
199  fr: ["de", "en"]
200  de: "en"
201
202translations:
203- file: "public/javascripts/i18n/%{locale}.js"
204  only: '*'
205```
206Fallbacks defined will be used, if not defined (e.g. `:pl`) `I18n.fallbacks` or `I18n.default_locale` will be used.
207
208```yaml
209fallbacks: :default_locale
210
211translations:
212- file: "public/javascripts/i18n/%{locale}.js"
213  only: '*'
214```
215Setting the option to `:default_locale` will enforce the fallback to use the `I18n.default_locale`, ignoring `I18n.fallbacks`.
216
217Examples:
218```yaml
219fallbacks: false
220
221translations:
222- file: "public/javascripts/i18n/%{locale}.js"
223  only: '*'
224```
225You must disable this feature by setting the option to `false`.
226
227To find more examples on how to use the configuration file please refer to the tests.
228
229
230#### Namespace
231
232Setting the `namespace` option will change the namespace of the output Javascript file to something other than `I18n`.
233This can be useful in no-conflict scenarios. Example:
234
235```yaml
236translations:
237- file: "public/javascripts/i18n/translations.js"
238  namespace: "MyNamespace"
239```
240
241will create:
242
243```
244MyNamespace.translations || (MyNamespace.translations = {});
245MyNamespace.translations["en"] = { ... }
246```
247
248
249#### Pretty Print
250
251Set the `pretty_print` option if you would like whitespace and indentation in your output file (default: false)
252
253```yaml
254translations:
255- file: "public/javascripts/i18n/translations.js"
256  pretty_print: true
257```
258
259
260#### Javascript Deep Merge (:js_extend option)
261
262By default, the output file Javascript will call the `I18n.extend` method to ensure that newly loaded locale
263files are deep-merged with any locale data already in memory. To disable this either globally or per-file,
264set the `js_extend` option to false
265
266```yaml
267js_extend: false  # this will disable Javascript I18n.extend globally
268translations:
269- file: "public/javascripts/i18n/translations.js"
270  js_extend: false  # this will disable Javascript I18n.extend for this file
271```
272
273
274#### Vanilla JavaScript
275
276Just add the `i18n.js` file to your page. You'll have to build the translations object
277by hand or using your favorite programming language. More info below.
278
279
280#### Via NPM with webpack and CommonJS
281
282
283Add the following line to your package.json dependencies
284where version is the version you want
285```javascript
286"i18n-js": "{version_constraint}"
287
288// Or if you want unreleased version
289// npm install requires it to be the gzipped tarball, see [npm install](https://www.npmjs.org/doc/cli/npm-install.html)
290"i18n-js": "https://github.com/fnando/i18n-js/archive/{tag_name_or_branch_name_or_commit_sha}.tar.gz"
291```
292Run npm install then use via
293```javascript
294var i18n = require("i18n-js");
295```
296
297
298### Setting up
299
300You **don't** need to set up a thing. The default settings will work just okay. But if you want to split translations into several files or specify specific contexts, you can follow the rest of this setting up section.
301
302Set your locale is easy as
303```javascript
304I18n.defaultLocale = "pt-BR";
305I18n.locale = "pt-BR";
306I18n.currentLocale();
307// pt-BR
308```
309
310**NOTE:** You can now apply your configuration **before I18n** is loaded like this:
311```javascript
312I18n = {} // You must define this object in top namespace, which should be `window`
313I18n.defaultLocale = "pt-BR";
314I18n.locale = "pt-BR";
315
316// Load I18n from `i18n.js`, `application.js` or whatever
317
318I18n.currentLocale();
319// pt-BR
320```
321
322In practice, you'll have something like the following in your `application.html.erb`:
323
324```erb
325<script type="text/javascript">
326  I18n.defaultLocale = "<%= I18n.default_locale %>";
327  I18n.locale = "<%= I18n.locale %>";
328</script>
329```
330
331You can use translate your messages:
332
333```javascript
334I18n.t("some.scoped.translation");
335// or translate with explicit setting of locale
336I18n.t("some.scoped.translation", {locale: "fr"});
337```
338
339You can also interpolate values:
340
341```javascript
342I18n.t("hello", {name: "John Doe"});
343```
344You can set default values for missing scopes:
345```javascript
346// simple translation
347I18n.t("some.missing.scope", {defaultValue: "A default message"});
348
349// with interpolation
350I18n.t("noun", {defaultValue: "I'm a {{noun}}", noun: "Mac"});
351```
352
353You can also provide a list of default fallbacks for missing scopes:
354
355```javascript
356// As a scope
357I18n.t("some.missing.scope", {defaults: [{scope: "some.existing.scope"}]});
358
359// As a simple translation
360I18n.t("some.missing.scope", {defaults: [{message: "Some message"}]});
361```
362
363Default values must be provided as an array of hashs where the key is the
364type of translation desired, a `scope` or a `message`. The translation returned
365will be either the first scope recognized, or the first message defined.
366
367The translation will fallback to the `defaultValue` translation if no scope
368in `defaults` matches and if no default of type `message` is found.
369
370Translation fallback can be enabled by enabling the `I18n.fallbacks` option:
371
372```erb
373<script type="text/javascript">
374  I18n.fallbacks = true;
375</script>
376```
377
378By default missing translations will first be looked for in less
379specific versions of the requested locale and if that fails by taking
380them from your `I18n.defaultLocale`.
381
382```javascript
383// if I18n.defaultLocale = "en" and translation doesn't exist
384// for I18n.locale = "de-DE" this key will be taken from "de" locale scope
385// or, if that also doesn't exist, from "en" locale scope
386I18n.t("some.missing.scope");
387```
388
389Custom fallback rules can also be specified for a particular language. There
390are three different ways of doing it so:
391
392```javascript
393I18n.locales.no = ["nb", "en"];
394I18n.locales.no = "nb";
395I18n.locales.no = function(locale){ return ["nb"]; };
396```
397
398By default a missing translation will be displayed as
399
400    [missing "name of scope" translation]
401
402While you are developing or if you do not want to provide a translation
403in the default language you can set
404
405```javascript
406I18n.missingBehaviour='guess';
407```
408
409this will take the last section of your scope and guess the intended value.
410Camel case becomes lower cased text and underscores are replaced with space
411
412    questionnaire.whatIsYourFavorite_ChristmasPresent
413
414becomes "what is your favorite Christmas present"
415
416In order to still detect untranslated strings, you can
417i18n.missingTranslationPrefix to something like:
418```javascript
419I18n.missingTranslationPrefix = 'EE: ';
420```
421
422And result will be:
423```javascript
424"EE: what is your favorite Christmas present"
425```
426
427This will help you doing automated tests against your localisation assets.
428
429Some people prefer returning `null` for missing translation:
430```javascript
431I18n.missingTranslation = function () { return undefined; };
432```
433
434Pluralization is possible as well and by default provides English rules:
435
436```javascript
437I18n.t("inbox.counting", {count: 10}); // You have 10 messages
438```
439
440The sample above expects the following translation:
441
442```yaml
443en:
444  inbox:
445    counting:
446      one: You have 1 new message
447      other: You have {{count}} new messages
448      zero: You have no messages
449```
450
451**NOTE:** Rails I18n recognizes the `zero` option.
452
453If you need special rules just define them for your language, for example Russian, just add a new pluralizer:
454
455```javascript
456I18n.pluralization["ru"] = function (count) {
457  var key = count % 10 == 1 && count % 100 != 11 ? "one" : [2, 3, 4].indexOf(count % 10) >= 0 && [12, 13, 14].indexOf(count % 100) < 0 ? "few" : count % 10 == 0 || [5, 6, 7, 8, 9].indexOf(count % 10) >= 0 || [11, 12, 13, 14].indexOf(count % 100) >= 0 ? "many" : "other";
458  return [key];
459};
460```
461
462You can find all rules on <http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html>.
463
464If you're using the same scope over and over again, you may use the `scope` option.
465
466```javascript
467var options = {scope: "activerecord.attributes.user"};
468
469I18n.t("name", options);
470I18n.t("email", options);
471I18n.t("username", options);
472```
473
474You can also provide an array as scope.
475
476```javascript
477// use the greetings.hello scope
478I18n.t(["greetings", "hello"]);
479```
480
481#### Number formatting
482
483Similar to Rails helpers, you have localized number and currency formatting.
484
485```javascript
486I18n.l("currency", 1990.99);
487// $1,990.99
488
489I18n.l("number", 1990.99);
490// 1,990.99
491
492I18n.l("percentage", 123.45);
493// 123.450%
494```
495
496To have more control over number formatting, you can use the
497`I18n.toNumber`, `I18n.toPercentage`, `I18n.toCurrency` and `I18n.toHumanSize`
498functions.
499
500```javascript
501I18n.toNumber(1000);     // 1,000.000
502I18n.toCurrency(1000);   // $1,000.00
503I18n.toPercentage(100);  // 100.000%
504```
505
506The `toNumber` and `toPercentage` functions accept the following options:
507
508- `precision`: defaults to `3`
509- `separator`: defaults to `.`
510- `delimiter`: defaults to `,`
511- `strip_insignificant_zeros`: defaults to `false`
512
513See some number formatting examples:
514
515```javascript
516I18n.toNumber(1000, {precision: 0});                   // 1,000
517I18n.toNumber(1000, {delimiter: ".", separator: ","}); // 1.000,000
518I18n.toNumber(1000, {delimiter: ".", precision: 0});   // 1.000
519```
520
521The `toCurrency` function accepts the following options:
522
523- `precision`: sets the level of precision
524- `separator`: sets the separator between the units
525- `delimiter`: sets the thousands delimiter
526- `format`: sets the format of the output string
527- `unit`: sets the denomination of the currency
528- `strip_insignificant_zeros`: defaults to `false`
529- `sign_first`: defaults to `true`
530
531You can provide only the options you want to override:
532
533```javascript
534I18n.toCurrency(1000, {precision: 0}); // $1,000
535```
536
537The `toHumanSize` function accepts the following options:
538
539- `precision`: defaults to `1`
540- `separator`: defaults to `.`
541- `delimiter`: defaults to `""`
542- `strip_insignificant_zeros`: defaults to `false`
543- `format`: defaults to `%n%u`
544
545<!---->
546
547```javascript
548I18n.toHumanSize(1234); // 1KB
549I18n.toHumanSize(1234 * 1024); // 1MB
550```
551
552
553#### Date formatting
554
555```javascript
556// accepted formats
557I18n.l("date.formats.short", "2009-09-18");           // yyyy-mm-dd
558I18n.l("time.formats.short", "2009-09-18 23:12:43");  // yyyy-mm-dd hh:mm:ss
559I18n.l("time.formats.short", "2009-11-09T18:10:34");  // JSON format with local Timezone (part of ISO-8601)
560I18n.l("time.formats.short", "2009-11-09T18:10:34Z"); // JSON format in UTC (part of ISO-8601)
561I18n.l("date.formats.short", 1251862029000);          // Epoch time
562I18n.l("date.formats.short", "09/18/2009");           // mm/dd/yyyy
563I18n.l("date.formats.short", (new Date()));           // Date object
564```
565
566You can also add placeholders to the date format:
567
568```javascript
569I18n.translations["en"] = {
570  date: {
571    formats: {
572      ordinal_day: "%B %{day}"
573    }
574  }
575}
576I18n.l("date.formats.ordinal_day", "2009-09-18", { day: '18th' }); // Sep 18th
577```
578
579If you prefer, you can use the `I18n.strftime` function to format dates.
580
581```javascript
582var date = new Date();
583I18n.strftime(date, "%d/%m/%Y");
584```
585
586The accepted formats are:
587
588    %a  - The abbreviated weekday name (Sun)
589    %A  - The full weekday name (Sunday)
590    %b  - The abbreviated month name (Jan)
591    %B  - The full month name (January)
592    %d  - Day of the month (01..31)
593    %-d - Day of the month (1..31)
594    %H  - Hour of the day, 24-hour clock (00..23)
595    %-H - Hour of the day, 24-hour clock (0..23)
596    %I  - Hour of the day, 12-hour clock (01..12)
597    %-I - Hour of the day, 12-hour clock (1..12)
598    %m  - Month of the year (01..12)
599    %-m - Month of the year (1..12)
600    %M  - Minute of the hour (00..59)
601    %-M - Minute of the hour (0..59)
602    %p  - Meridian indicator (AM  or  PM)
603    %S  - Second of the minute (00..60)
604    %-S - Second of the minute (0..60)
605    %w  - Day of the week (Sunday is 0, 0..6)
606    %y  - Year without a century (00..99)
607    %-y - Year without a century (0..99)
608    %Y  - Year with century
609    %z  - Timezone offset (+0545)
610
611Check out `spec/*.spec.js` files for more examples!
612
613#### Using pluralization and number formatting together
614Sometimes you might want to display translation with formatted number, like adding thousand delimiters to displayed number
615You can do this:
616```json
617{
618  "en": {
619    "point": {
620      "one": "1 Point",
621      "other": "{{formatted_number}} Points",
622      "zero": "0 Points"
623    }
624  }
625}
626```
627```js
628var point_in_number = 1000;
629I18n.t('point', { count: point_in_number, formatted_number: I18n.toNumber(point_in_number) });
630```
631Output should be `1,000 points`
632
633
634## Using multiple exported translation files on a page.
635This method is useful for very large apps where a single contained translations.js file is not desirable. Examples would be a global translations file and a more specific route translation file.
636
637### Rails without asset pipeline
6381. Setup your `config/i18n-js.yml` to have multiple files and try to minimize any overlap.
639
640  ```yaml
641  sort_translation_keys: true
642  fallbacks: false
643
644  translations:
645    + file: "app/assets/javascript/nls/welcome.js"
646      only:
647        + '*.welcome.*'
648
649    + file: "app/assets/javascript/nls/albums.js"
650      only:
651        + '*.albums.*'
652
653    + file: "app/assets/javascript/nls/global.js"
654      only:
655        + '*'
656      # Exempt any routes specific translations from being
657      # included in the global translation file
658      except:
659        + '*.welcome.*'
660        + '*.albums.*'
661  ```
662  When `rake i18n:js:export` is executed it will create 3 translations files that can be loaded via the `javascript_include_tag`
663
6642. Add the `javascript_include_tag` to your layout and to any route specific files that will require it.
665  ```ruby
666    # views/layouts/application.html.erb
667    <%= javascript_include_tag(
668          "i18n"
669          "nls/global"
670        ) %>
671  ```
672  and in the route specific
673
674  ```ruby
675    # views/welcome/index.html.erb
676    <%= javascript_include_tag(
677          "nls/welcome"
678        ) %>
679  ```
680
6813. Make sure that you add these files to your `config/application.rb`
682
683  ```ruby
684    config.assets.precompile += %w(
685      i18n
686      nls/*
687    )
688  ```
689
690### Using require.js / r.js
691
692To use this with require.js we are only going to change a few things from above.
693
6941. In your `config/i18n-js.yml` we need to add a better location for the i18n to be exported. You want to use this location so that it can be properly precompiled by r.js.
695
696  ```yaml
697  export_i18n_js: "app/assets/javascript/nls"
698  ```
699
7002. In your `config/require.yml` we need to add a map, shim all the translations, and include them into the appropriate modules
701
702  ```yaml
703  # In your maps add (if you do not have this you will need to add it)
704  map:
705    '*':
706      i18n: 'nls/i18n'
707
708  # In your shims
709  shims:
710    nls/welcome:
711      deps:
712        + i18n
713
714    nls/global:
715      deps:
716        + i18n
717
718  # Finally in your modules
719  modules:
720    + name: 'application'
721      include:
722        + i18n
723        + 'nls/global'
724
725    + name: 'welcome'
726      exclude:
727        + application
728      include:
729        + 'nls/welcome'
730  ```
7313. When `rake assets:precompile` is executed it will optimize the translations into the correct modules so they are loaded with their assigned module, and loading them with requirejs is as simple as requiring any other shim.
732
733  ```javascript
734  define(['welcome/other_asset','nls/welcome'], function (otherAsset){
735      // ...
736  });
737  ```
7384. (optional) As an additional configuration we can make a task to be run before the requirejs optimizer. This will allow any automated scripts that run the requirejs optimizer to export the strings before we run r.js
739
740  ```rake
741  # lib/tasks/i18n.rake
742  Rake::Task[:'i18n:js:export'].prerequisites.clear
743  task :'i18n:js:export' => :'i18n:js:before_export'
744  task :'requirejs:precompile:external' => :'i18n:js:export'
745
746  namespace :i18n do
747    namespace :js do
748      task :before_export => :'assets:environment' do
749        I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{yml,rb}')]
750        I18n.backend.load_translations
751      end
752    end
753  end
754  ```
755
756## Using I18n.js with other languages (Python, PHP, ...)
757
758The JavaScript library is language agnostic; so you can use it with PHP, Python, [your favorite language here].
759The only requirement is that you need to set the `translations` attribute like following:
760
761```javascript
762I18n.translations = {};
763
764I18n.translations["en"] = {
765  message: "Some special message for you"
766}
767
768I18n.translations["pt-BR"] = {
769  message: "Uma mensagem especial para você"
770}
771```
772
773
774## Known Issues
775
776### Missing translations in precompiled file(s) after adding any new locale file
777
778Due to the design of `sprockets`:
779
780- `depend_on` only takes file paths, not directory paths
781- registered `preprocessors` are only run when the fingerprint of any asset file, including `.erb` files, is changed
782
783This means that new locale files will not be detected, and so they will not trigger a i18n-js refresh. There are a few approaches to work around this:
784
7851. You can force i18n-js to update its translations by completely clearing the assets cache. Use one of the following:
786
787```bash
788$ rake assets:clobber
789# Or, with older versions of Rails:
790$ rake tmp:cache:clear
791```
792
793These commands will remove *all* fingerprinted assets, and you will have to recompile them with
794
795```bash
796$ rake assets:precompile
797```
798
799or similar commands.  If you are precompiling assets on the target machine(s), cached pages may be broken by this, so they will need to be refreshed.
800
8012. You can change something in a different locale file.
802
8033. Finally, you can change `config.assets.version`.
804
805**Note:** See issue [#213](https://github.com/fnando/i18n-js/issues/213) for more details and discussion of this issue.
806
807### Translations in JS are not updated when Sprockets not loaded before this gem
808
809The "rails engine" declaration will try to detect existence of "sprockets" before adding the initailizer
810If sprockets is loaded after this gem, the preprocessor for
811making JS translations file cache to depend on content of locale files will not be hooked.
812So ensure sprockets is loaded before this gem like moving entry of sprockets in Gemfile or adding "require" statements for sprockets somewhere.
813
814**Note:** See issue [#404](https://github.com/fnando/i18n-js/issues/404) for more details and discussion of this issue.
815
816
817## Maintainer
818
819- Nando Vieira - <http://nandovieira.com.br>
820
821## Contributing
822
823Once you've made your great commits:
824
8251. [Fork](http://help.github.com/forking/) I18n.js
8262. Create a branch with a clear name
8273. Make your changes (Please also add/change spec, README and CHANGELOG if applicable)
8284. Push changes to the created branch
8295. [Create an Pull Request](http://github.com/fnando/i18n-js/pulls)
8306. That's it!
831
832Please respect the indentation rules and code style.
833And use 2 spaces, not tabs. And don't touch the versioning thing.
834
835## Running tests
836
837You can run I18n tests using Node.js or your browser.
838
839To use Node.js, install the `jasmine-node` library:
840
841    $ npm install jasmine-node
842
843Then execute the following command from the lib's root directory:
844
845    $ npm test
846
847To run using your browser, just open the `spec/js/specs.html` file.
848
849You can run both Ruby and JavaScript specs with `rake spec`.
850
851## License
852
853(The MIT License)
854
855Permission is hereby granted, free of charge, to any person obtaining
856a copy of this software and associated documentation files (the
857'Software'), to deal in the Software without restriction, including
858without limitation the rights to use, copy, modify, merge, publish,
859distribute, sublicense, and/or sell copies of the Software, and to
860permit persons to whom the Software is furnished to do so, subject to
861the following conditions:
862
863The above copyright notice and this permission notice shall be
864included in all copies or substantial portions of the Software.
865
866THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
867EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
868MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
869IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
870CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
871TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
872SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
873