i18n-js 3.8.3 → 4.0.0.alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +4 -0
- data/.github/FUNDING.yml +1 -1
- data/.github/ISSUE_TEMPLATE/bug_report.md +41 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +23 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +38 -0
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ruby-tests.yml +61 -0
- data/.gitignore +11 -7
- data/.rubocop.yml +12 -0
- data/CHANGELOG.md +12 -535
- data/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +79 -0
- data/Gemfile +3 -0
- data/LICENSE.md +20 -0
- data/README.md +86 -1030
- data/Rakefile +10 -20
- data/exe/i18n +5 -0
- data/i18n-js.gemspec +47 -29
- data/lib/guard/i18n-js.rb +78 -0
- data/lib/guard/i18n-js/templates/Guardfile +10 -0
- data/lib/guard/i18n-js/version.rb +13 -0
- data/lib/i18n-js.rb +66 -1
- data/lib/i18n-js/cli.rb +47 -0
- data/lib/i18n-js/cli/command.rb +43 -0
- data/lib/i18n-js/cli/export_command.rb +108 -0
- data/lib/i18n-js/cli/init_command.rb +50 -0
- data/lib/i18n-js/cli/ui.rb +30 -0
- data/lib/i18n-js/cli/version_command.rb +18 -0
- data/lib/i18n-js/listen.rb +80 -0
- data/lib/i18n-js/schema.rb +92 -0
- data/lib/i18n-js/version.rb +5 -0
- metadata +122 -194
- data/.editorconfig +0 -24
- data/.github/workflows/tests.yaml +0 -100
- data/.npmignore +0 -27
- data/Appraisals +0 -44
- data/app/assets/javascripts/i18n.js +0 -1095
- data/app/assets/javascripts/i18n/filtered.js.erb +0 -23
- data/app/assets/javascripts/i18n/shims.js +0 -240
- data/app/assets/javascripts/i18n/translations.js +0 -3
- data/gemfiles/i18n_0_6.gemfile +0 -7
- data/gemfiles/i18n_0_7.gemfile +0 -7
- data/gemfiles/i18n_0_8.gemfile +0 -7
- data/gemfiles/i18n_0_9.gemfile +0 -7
- data/gemfiles/i18n_1_0.gemfile +0 -7
- data/gemfiles/i18n_1_1.gemfile +0 -7
- data/gemfiles/i18n_1_2.gemfile +0 -7
- data/gemfiles/i18n_1_3.gemfile +0 -7
- data/gemfiles/i18n_1_4.gemfile +0 -7
- data/gemfiles/i18n_1_5.gemfile +0 -7
- data/gemfiles/i18n_1_6.gemfile +0 -7
- data/gemfiles/i18n_1_7.gemfile +0 -7
- data/gemfiles/i18n_1_8.gemfile +0 -7
- data/i18njs.png +0 -0
- data/lib/i18n/js.rb +0 -264
- data/lib/i18n/js/dependencies.rb +0 -63
- data/lib/i18n/js/engine.rb +0 -87
- data/lib/i18n/js/fallback_locales.rb +0 -70
- data/lib/i18n/js/formatters/base.rb +0 -25
- data/lib/i18n/js/formatters/js.rb +0 -39
- data/lib/i18n/js/formatters/json.rb +0 -13
- data/lib/i18n/js/middleware.rb +0 -82
- data/lib/i18n/js/private/config_store.rb +0 -31
- data/lib/i18n/js/private/hash_with_symbol_keys.rb +0 -36
- data/lib/i18n/js/segment.rb +0 -80
- data/lib/i18n/js/utils.rb +0 -78
- data/lib/i18n/js/version.rb +0 -7
- data/lib/rails/generators/i18n/js/config/config_generator.rb +0 -19
- data/lib/rails/generators/i18n/js/config/templates/i18n-js.yml +0 -27
- data/lib/tasks/export.rake +0 -8
- data/package.json +0 -25
- data/spec/fixtures/custom_path.yml +0 -5
- data/spec/fixtures/default.yml +0 -5
- data/spec/fixtures/erb.yml +0 -5
- data/spec/fixtures/except_condition.yml +0 -7
- data/spec/fixtures/js_export_dir_custom.yml +0 -7
- data/spec/fixtures/js_export_dir_none.yml +0 -6
- data/spec/fixtures/js_extend_parent.yml +0 -6
- data/spec/fixtures/js_extend_segment.yml +0 -6
- data/spec/fixtures/js_file_per_locale.yml +0 -7
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_default_locale_symbol.yml +0 -4
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_hash.yml +0 -6
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale.yml +0 -4
- data/spec/fixtures/js_file_per_locale_with_fallbacks_as_locale_without_fallback_translations.yml +0 -4
- data/spec/fixtures/js_file_per_locale_with_fallbacks_enabled.yml +0 -4
- data/spec/fixtures/js_file_per_locale_without_fallbacks.yml +0 -4
- data/spec/fixtures/js_file_with_namespace_prefix_and_pretty_print.yml +0 -9
- data/spec/fixtures/js_sort_translation_keys_false.yml +0 -6
- data/spec/fixtures/js_sort_translation_keys_true.yml +0 -6
- data/spec/fixtures/json_only.yml +0 -18
- data/spec/fixtures/locales.yml +0 -133
- data/spec/fixtures/merge_plurals.yml +0 -6
- data/spec/fixtures/merge_plurals_with_no_overrides.yml +0 -4
- data/spec/fixtures/merge_plurals_with_partial_overrides.yml +0 -4
- data/spec/fixtures/millions.yml +0 -4
- data/spec/fixtures/multiple_conditions.yml +0 -7
- data/spec/fixtures/multiple_conditions_per_locale.yml +0 -7
- data/spec/fixtures/multiple_files.yml +0 -7
- data/spec/fixtures/no_config.yml +0 -2
- data/spec/fixtures/no_scope.yml +0 -4
- data/spec/fixtures/simple_scope.yml +0 -5
- data/spec/js/currency.spec.js +0 -62
- data/spec/js/current_locale.spec.js +0 -19
- data/spec/js/dates.spec.js +0 -276
- data/spec/js/defaults.spec.js +0 -31
- data/spec/js/extend.spec.js +0 -110
- data/spec/js/interpolation.spec.js +0 -124
- data/spec/js/jasmine/MIT.LICENSE +0 -20
- data/spec/js/jasmine/jasmine-html.js +0 -190
- data/spec/js/jasmine/jasmine.css +0 -166
- data/spec/js/jasmine/jasmine.js +0 -2476
- data/spec/js/jasmine/jasmine_favicon.png +0 -0
- data/spec/js/json_parsable.spec.js +0 -14
- data/spec/js/locales.spec.js +0 -31
- data/spec/js/localization.spec.js +0 -78
- data/spec/js/numbers.spec.js +0 -174
- data/spec/js/placeholder.spec.js +0 -24
- data/spec/js/pluralization.spec.js +0 -219
- data/spec/js/prepare_options.spec.js +0 -41
- data/spec/js/require.js +0 -2083
- data/spec/js/specs.html +0 -49
- data/spec/js/specs_requirejs.html +0 -72
- data/spec/js/translate.spec.js +0 -304
- data/spec/js/translations.js +0 -188
- data/spec/js/utility_functions.spec.js +0 -20
- data/spec/ruby/i18n/js/fallback_locales_spec.rb +0 -84
- data/spec/ruby/i18n/js/segment_spec.rb +0 -261
- data/spec/ruby/i18n/js/utils_spec.rb +0 -106
- data/spec/ruby/i18n/js_spec.rb +0 -748
- data/spec/spec_helper.rb +0 -80
- data/yarn.lock +0 -131
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at me@fnando.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Contributing to i18n-js
|
|
2
|
+
|
|
3
|
+
👍🎉 First off, thanks for taking the time to contribute! 🎉👍
|
|
4
|
+
|
|
5
|
+
The following is a set of guidelines for contributing to this project. These are
|
|
6
|
+
mostly guidelines, not rules. Use your best judgment, and feel free to propose
|
|
7
|
+
changes to this document in a pull request.
|
|
8
|
+
|
|
9
|
+
## Code of Conduct
|
|
10
|
+
|
|
11
|
+
Everyone interacting in this project's codebases, issue trackers, chat rooms and
|
|
12
|
+
mailing lists is expected to follow the [code of conduct](https://github.com/fnando/i18n-js/blob/main/CODE_OF_CONDUCT.md).
|
|
13
|
+
|
|
14
|
+
## Reporting bugs
|
|
15
|
+
|
|
16
|
+
This section guides you through submitting a bug report. Following these
|
|
17
|
+
guidelines helps maintainers and the community understand your report, reproduce
|
|
18
|
+
the behavior, and find related reports.
|
|
19
|
+
|
|
20
|
+
- Before creating bug reports, please check the open issues; somebody may
|
|
21
|
+
already have submitted something similar, and you may not need to create a new
|
|
22
|
+
one.
|
|
23
|
+
- When you are creating a bug report, please include as many details as
|
|
24
|
+
possible, with an example reproducing the issue.
|
|
25
|
+
|
|
26
|
+
## Contributing with code
|
|
27
|
+
|
|
28
|
+
Before making any radicals changes, please make sure you discuss your intention
|
|
29
|
+
by [opening an issue on Github](https://github.com/fnando/i18n-js/issues).
|
|
30
|
+
|
|
31
|
+
When you're ready to make your pull request, follow checklist below to make sure
|
|
32
|
+
your contribution is according to how this project works.
|
|
33
|
+
|
|
34
|
+
1. [Fork](https://help.github.com/forking/) i18n-js
|
|
35
|
+
2. Create a topic branch - `git checkout -b my_branch`
|
|
36
|
+
3. Make your changes using [descriptive commit messages](#commit-messages)
|
|
37
|
+
4. Update CHANGELOG.md describing your changes by adding an entry to the
|
|
38
|
+
"Unreleased" section. If this section is not available, create one right
|
|
39
|
+
before the last version.
|
|
40
|
+
5. Push to your branch - `git push origin my_branch`
|
|
41
|
+
6. [Create a pull request](https://help.github.com/articles/creating-a-pull-request)
|
|
42
|
+
7. That's it!
|
|
43
|
+
|
|
44
|
+
## Styleguides
|
|
45
|
+
|
|
46
|
+
### Commit messages
|
|
47
|
+
|
|
48
|
+
- Use the present tense ("Add feature" not "Added feature")
|
|
49
|
+
- Use the imperative mood ("Move cursor to..." not "Moves cursor to...")
|
|
50
|
+
- Limit the first line to 72 characters or less
|
|
51
|
+
- Reference issues and pull requests liberally after the first line
|
|
52
|
+
|
|
53
|
+
### Changelog
|
|
54
|
+
|
|
55
|
+
- Add a message describing your changes to the "Unreleased" section. The
|
|
56
|
+
changelog message should follow the same style as the commit message.
|
|
57
|
+
- Prefix your message with one of the following:
|
|
58
|
+
- `[Added]` for new features.
|
|
59
|
+
- `[Changed]` for changes in existing functionality.
|
|
60
|
+
- `[Deprecated]` for soon-to-be removed features.
|
|
61
|
+
- `[Removed]` for now removed features.
|
|
62
|
+
- `[Fixed]` for any bug fixes.
|
|
63
|
+
- `[Security]` in case of vulnerabilities.
|
|
64
|
+
|
|
65
|
+
### Ruby code
|
|
66
|
+
|
|
67
|
+
- This project uses [Rubocop](https://rubocop.org) to enforce code style. Before
|
|
68
|
+
submitting your changes, make sure your tests are passing and code conforms to
|
|
69
|
+
the expected style by running `rake`.
|
|
70
|
+
- Do not change the library version. This will be done by the maintainer
|
|
71
|
+
whenever a new version is about to be released.
|
|
72
|
+
|
|
73
|
+
### JavaScript code
|
|
74
|
+
|
|
75
|
+
- This project uses [ESLint](https://eslint.org) to enforce code style. Before
|
|
76
|
+
submitting your changes, make sure your tests are passing and code conforms to
|
|
77
|
+
the expected style by running `yarn test:ci`.
|
|
78
|
+
- Do not change the library version. This will be done by the maintainer
|
|
79
|
+
whenever a new version is about to be released.
|
data/Gemfile
CHANGED
data/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Nando Vieira
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,1086 +1,142 @@
|
|
|
1
|
-
|
|
2
|
-
<img width="250" height="58" src="https://github.com/fnando/i18n-js/raw/main/i18njs.png" alt="i18n.js">
|
|
3
|
-
</p>
|
|
1
|
+
# i18n-js
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
[](https://github.com/fnando/i18n-js)
|
|
4
|
+
[](https://codeclimate.com/github/fnando/i18n-js)
|
|
5
|
+
[](https://rubygems.org/gems/i18n-js)
|
|
6
|
+
[](https://rubygems.org/gems/i18n-js)
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<a href="http://badge.fury.io/rb/i18n-js"><img src="http://img.shields.io/gem/v/i18n-js.svg" alt="Gem Version"></a>
|
|
12
|
-
<a href="https://www.npmjs.com/package/i18n-js"><img src="https://img.shields.io/npm/v/i18n-js.svg" alt="npm"></a>
|
|
13
|
-
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
14
|
-
<a href="https://travis-ci.org/fnando/i18n-js"><img src="http://img.shields.io/travis/fnando/i18n-js.svg" alt="Build Status"></a>
|
|
15
|
-
<a href="https://coveralls.io/r/fnando/i18n-js"><img src="http://img.shields.io/coveralls/fnando/i18n-js.svg" alt="Coverage Status"></a>
|
|
16
|
-
<a href="https://gitter.im/fnando/i18n-js"><img src="https://img.shields.io/badge/gitter-join%20chat-1dce73.svg" alt="Gitter"></a>
|
|
17
|
-
</p>
|
|
8
|
+
Export [i18n](https://rubygems.org/gems/i18n) translations to JSON. A perfect
|
|
9
|
+
fit if you want to export translations to JavaScript.
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Features:
|
|
22
|
-
|
|
23
|
-
- Pluralization
|
|
24
|
-
- Date/Time localization
|
|
25
|
-
- Number localization
|
|
26
|
-
- Locale fallback
|
|
27
|
-
- Asset pipeline support
|
|
28
|
-
- Lots more! :)
|
|
29
|
-
|
|
30
|
-
## Version Notice
|
|
31
|
-
|
|
32
|
-
The `main` branch (including this README) is for latest `3.0.0` instead of
|
|
33
|
-
`2.x`.
|
|
34
|
-
|
|
35
|
-
## Usage
|
|
36
|
-
|
|
37
|
-
### Installation
|
|
38
|
-
|
|
39
|
-
#### Rails app
|
|
40
|
-
|
|
41
|
-
Add the gem to your Gemfile.
|
|
42
|
-
|
|
43
|
-
```ruby
|
|
44
|
-
gem "i18n-js"
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
#### Rails with [webpacker](https://github.com/rails/webpacker)
|
|
48
|
-
|
|
49
|
-
If you're using `webpacker`, you may need to add the dependencies to your client
|
|
50
|
-
with:
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
yarn add i18n-js
|
|
54
|
-
# or, if you're using npm,
|
|
55
|
-
npm install i18n-js
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
For more details, see:
|
|
59
|
-
- [this gist](https://gist.github.com/bazzel/ecdff4718962e57c2d5569cf01d332fe)
|
|
60
|
-
- https://github.com/fnando/i18n-js/issues/597
|
|
61
|
-
|
|
62
|
-
#### Rails app with [Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html)
|
|
63
|
-
|
|
64
|
-
If you're using the
|
|
65
|
-
[asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html), then you
|
|
66
|
-
must add the following line to your `app/assets/javascripts/application.js`.
|
|
67
|
-
|
|
68
|
-
```javascript
|
|
69
|
-
//
|
|
70
|
-
// This is optional (in case you have `I18n is not defined` error)
|
|
71
|
-
// If you want to put this line, you must put it BEFORE `i18n/translations`
|
|
72
|
-
//= require i18n
|
|
73
|
-
// Some people even need to add the extension to make it work, see https://github.com/fnando/i18n-js/issues/283
|
|
74
|
-
//= require i18n.js
|
|
75
|
-
//
|
|
76
|
-
// This is a must
|
|
77
|
-
//= require i18n/translations
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
#### Rails app without [Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html)
|
|
81
|
-
|
|
82
|
-
First, put this in your `application.html` (layout file). Then get the JS files
|
|
83
|
-
following the instructions below.
|
|
84
|
-
|
|
85
|
-
```erb
|
|
86
|
-
<%# This is just an example, you can put `i18n.js` and `translations.js` anywhere you like %>
|
|
87
|
-
<%# Unlike the Asset Pipeline example, you need to require both **in order** %>
|
|
88
|
-
<%= javascript_include_tag "i18n" %>
|
|
89
|
-
<%= javascript_include_tag "translations", skip_pipeline: true %>
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
**There are two ways to get `translations.js` (For Rails app without Asset
|
|
93
|
-
Pipeline).**
|
|
94
|
-
|
|
95
|
-
1. This `translations.js` file can be automatically generated by the
|
|
96
|
-
`I18n::JS::Middleware`. Just add `config.middleware.use I18n::JS::Middleware`
|
|
97
|
-
to your `config/application.rb` file.
|
|
98
|
-
2. If you can't or prefer not to generate this file, you can move the middleware
|
|
99
|
-
line to your `config/environments/development.rb` file and run
|
|
100
|
-
`rake i18n:js:export` before deploying. This will export all translation
|
|
101
|
-
files, including the custom scopes you may have defined on
|
|
102
|
-
`config/i18n-js.yml`. If `I18n.available_locales` is set (e.g. in your Rails
|
|
103
|
-
`config/application.rb` file) then only the specified locales will be
|
|
104
|
-
exported. Current version of `i18n.js` will also be exported to avoid version
|
|
105
|
-
mismatching by downloading.
|
|
106
|
-
|
|
107
|
-
#### Export Configuration (For translations)
|
|
108
|
-
|
|
109
|
-
Exported translation files generated by `I18n::JS::Middleware` or
|
|
110
|
-
`rake i18n:js:export` can be customized with config file `config/i18n-js.yml`
|
|
111
|
-
(use `rails generate i18n:js:config` to create it). You can even get more files
|
|
112
|
-
generated to different folders and with different translations to best suit your
|
|
113
|
-
needs. The config file also affects developers using Asset Pipeline to require
|
|
114
|
-
translations. Except the option `file`, since all translations are required by
|
|
115
|
-
adding `//= require i18n/translations`.
|
|
116
|
-
|
|
117
|
-
Examples:
|
|
118
|
-
|
|
119
|
-
```yaml
|
|
120
|
-
translations:
|
|
121
|
-
- file: "public/javascripts/path-to-your-messages-file.js"
|
|
122
|
-
only: "*.date.formats"
|
|
123
|
-
- file: "public/javascripts/path-to-your-second-file.js"
|
|
124
|
-
only: ["*.activerecord", "*.admin.*.title"]
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
If `only` is omitted all the translations will be saved. Also, make sure you add
|
|
128
|
-
that initial `*`; it specifies that all languages will be exported. If you want
|
|
129
|
-
to export only one language, you can do something like this:
|
|
130
|
-
|
|
131
|
-
```yaml
|
|
132
|
-
translations:
|
|
133
|
-
- file: "public/javascripts/en.js"
|
|
134
|
-
only: "en.*"
|
|
135
|
-
- file: "public/javascripts/pt-BR.js"
|
|
136
|
-
only: "pt-BR.*"
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
Optionally, you can auto generate a translation file per available locale if you
|
|
140
|
-
specify the `%{locale}` placeholder.
|
|
141
|
-
|
|
142
|
-
```yaml
|
|
143
|
-
translations:
|
|
144
|
-
- file: "public/javascripts/i18n/%{locale}.js"
|
|
145
|
-
only: "*"
|
|
146
|
-
- file: "public/javascripts/frontend/i18n/%{locale}.js"
|
|
147
|
-
only: ["*.frontend", "*.users.*"]
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
You can also include ERB in your config file.
|
|
151
|
-
|
|
152
|
-
```yaml
|
|
153
|
-
translations:
|
|
154
|
-
<% Widgets.each do |widget| %>
|
|
155
|
-
- file: <%= "'#{widget.file}'" %>
|
|
156
|
-
only: <%= "'#{widget.only}'" %>
|
|
157
|
-
<% end %>
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
You are able to exclude certain phrases or whole groups of phrases by specifying
|
|
161
|
-
the YAML key(s) in the `except` configuration option. The outputted JS
|
|
162
|
-
translations file (exported or generated by the middleware) will omit any keys
|
|
163
|
-
listed in `except` configuration param:
|
|
164
|
-
|
|
165
|
-
```yaml
|
|
166
|
-
translations:
|
|
167
|
-
- except: ["*.active_admin", "*.ransack", "*.activerecord.errors"]
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
#### Export Configuration (For other things)
|
|
171
|
-
|
|
172
|
-
- `I18n::JS.config_file_path` Expected Type: `String` Default:
|
|
173
|
-
`config/i18n-js.yml` Behaviour: Try to read the config file from that location
|
|
174
|
-
|
|
175
|
-
- `I18n::JS.export_i18n_js_dir_path` Expected Type: `String` Default:
|
|
176
|
-
`public/javascripts` Behaviour:
|
|
177
|
-
|
|
178
|
-
- Any `String`: considered as a relative path for a folder to `Rails.root` and
|
|
179
|
-
export `i18n.js` to that folder for `rake i18n:js:export`
|
|
180
|
-
- Any non-`String` (`nil`, `false`, `:none`, etc): Disable `i18n.js` exporting
|
|
181
|
-
|
|
182
|
-
- `I18n::JS.sort_translation_keys` Expected Type: `Boolean` Default: `true`
|
|
183
|
-
Behaviour:
|
|
184
|
-
|
|
185
|
-
- Sets whether or not to deep sort all translation keys in order to generate
|
|
186
|
-
identical output for the same translations
|
|
187
|
-
- Set to true to ensure identical asset fingerprints for the asset pipeline
|
|
188
|
-
|
|
189
|
-
- You may also set `export_i18n_js` and `sort_translation_keys` in your config
|
|
190
|
-
file, e.g.:
|
|
191
|
-
|
|
192
|
-
```yaml
|
|
193
|
-
export_i18n_js: false
|
|
194
|
-
# OR
|
|
195
|
-
export_i18n_js: "my/path"
|
|
196
|
-
|
|
197
|
-
sort_translation_keys: false
|
|
198
|
-
|
|
199
|
-
translations:
|
|
200
|
-
- ...
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
To find more examples on how to use the configuration file please refer to the
|
|
204
|
-
tests.
|
|
205
|
-
|
|
206
|
-
#### Fallbacks
|
|
207
|
-
|
|
208
|
-
If you specify the `fallbacks` option, you will be able to fill missing
|
|
209
|
-
translations with those inside fallback locale(s). Default value is `true`.
|
|
210
|
-
|
|
211
|
-
Examples:
|
|
212
|
-
|
|
213
|
-
```yaml
|
|
214
|
-
fallbacks: true
|
|
215
|
-
|
|
216
|
-
translations:
|
|
217
|
-
- file: "public/javascripts/i18n/%{locale}.js"
|
|
218
|
-
only: "*"
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
This will enable merging fallbacks into each file. (set to `false` to disable).
|
|
222
|
-
If you use `I18n` with fallbacks, the fallbacks defined there will be used.
|
|
223
|
-
Otherwise `I18n.default_locale` will be used.
|
|
224
|
-
|
|
225
|
-
```yaml
|
|
226
|
-
fallbacks: :de
|
|
227
|
-
|
|
228
|
-
translations:
|
|
229
|
-
- file: "public/javascripts/i18n/%{locale}.js"
|
|
230
|
-
only: "*"
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
Here, the specified locale `:de` will be used as fallback for all locales.
|
|
234
|
-
|
|
235
|
-
```yaml
|
|
236
|
-
fallbacks:
|
|
237
|
-
fr: ["de", "en"]
|
|
238
|
-
de: "en"
|
|
239
|
-
|
|
240
|
-
translations:
|
|
241
|
-
- file: "public/javascripts/i18n/%{locale}.js"
|
|
242
|
-
only: "*"
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
Fallbacks defined will be used, if not defined (e.g. `:pl`) `I18n.fallbacks` or
|
|
246
|
-
`I18n.default_locale` will be used.
|
|
247
|
-
|
|
248
|
-
```yaml
|
|
249
|
-
fallbacks: :default_locale
|
|
250
|
-
|
|
251
|
-
translations:
|
|
252
|
-
- file: "public/javascripts/i18n/%{locale}.js"
|
|
253
|
-
only: "*"
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
Setting the option to `:default_locale` will enforce the fallback to use the
|
|
257
|
-
`I18n.default_locale`, ignoring `I18n.fallbacks`.
|
|
258
|
-
|
|
259
|
-
Examples:
|
|
260
|
-
|
|
261
|
-
```yaml
|
|
262
|
-
fallbacks: false
|
|
263
|
-
|
|
264
|
-
translations:
|
|
265
|
-
- file: "public/javascripts/i18n/%{locale}.js"
|
|
266
|
-
only: "*"
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
You must disable this feature by setting the option to `false`.
|
|
270
|
-
|
|
271
|
-
To find more examples on how to use the configuration file please refer to the
|
|
272
|
-
tests.
|
|
273
|
-
|
|
274
|
-
#### Namespace
|
|
275
|
-
|
|
276
|
-
Setting the `namespace` option will change the namespace of the output
|
|
277
|
-
Javascript file to something other than `I18n`. This can be useful in
|
|
278
|
-
no-conflict scenarios. Example:
|
|
279
|
-
|
|
280
|
-
```yaml
|
|
281
|
-
translations:
|
|
282
|
-
- file: "public/javascripts/i18n/translations.js"
|
|
283
|
-
namespace: "MyNamespace"
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
will create:
|
|
287
|
-
|
|
288
|
-
```
|
|
289
|
-
MyNamespace.translations || (MyNamespace.translations = {});
|
|
290
|
-
MyNamespace.translations["en"] = { ... }
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
### Adding prefix & suffix to the translations file(s)
|
|
294
|
-
|
|
295
|
-
Setting the `prefix: "import I18n from 'i18n-js';\n"` option will add the line
|
|
296
|
-
at the beginning of the resultant translation file. This can be useful to use
|
|
297
|
-
this gem with the [i18n-js](https://www.npmjs.com/package/i18n-js) npm package,
|
|
298
|
-
which is quite useful to use it with webpack. The user should provide the
|
|
299
|
-
semi-colon and the newline character if needed.
|
|
300
|
-
|
|
301
|
-
For example:
|
|
302
|
-
|
|
303
|
-
```yaml
|
|
304
|
-
translations:
|
|
305
|
-
- file: "public/javascripts/i18n/translations.js"
|
|
306
|
-
prefix: "import I18n from 'i18n-js';\n"
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
will create:
|
|
310
|
-
|
|
311
|
-
```
|
|
312
|
-
import I18n from 'i18n-js';
|
|
313
|
-
I18n.translations || (I18n.translations = {});
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
`suffix` option is added in https://github.com/fnando/i18n-js/pull/561.
|
|
317
|
-
It's similar to `prefix` so won't explain it in details.
|
|
318
|
-
|
|
319
|
-
#### Pretty Print
|
|
320
|
-
|
|
321
|
-
Set the `pretty_print` option if you would like whitespace and indentation in
|
|
322
|
-
your output file (default: false)
|
|
323
|
-
|
|
324
|
-
```yaml
|
|
325
|
-
translations:
|
|
326
|
-
- file: "public/javascripts/i18n/translations.js"
|
|
327
|
-
pretty_print: true
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
#### Javascript Deep Merge (:js_extend option)
|
|
331
|
-
|
|
332
|
-
By default, the output file Javascript will call the `I18n.extend` method to
|
|
333
|
-
ensure that newly loaded locale files are deep-merged with any locale data
|
|
334
|
-
already in memory. To disable this either globally or per-file, set the
|
|
335
|
-
`js_extend` option to false
|
|
336
|
-
|
|
337
|
-
```yaml
|
|
338
|
-
js_extend: false # this will disable Javascript I18n.extend globally
|
|
339
|
-
translations:
|
|
340
|
-
- file: "public/javascripts/i18n/translations.js"
|
|
341
|
-
js_extend: false # this will disable Javascript I18n.extend for this file
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
#### Vanilla JavaScript
|
|
345
|
-
|
|
346
|
-
Just add the `i18n.js` file to your page. You'll have to build the translations
|
|
347
|
-
object by hand or using your favorite programming language. More info below.
|
|
348
|
-
|
|
349
|
-
#### Via NPM with webpack and CommonJS
|
|
350
|
-
|
|
351
|
-
Add the following line to your package.json dependencies where version is the
|
|
352
|
-
version you want:
|
|
353
|
-
|
|
354
|
-
```javascript
|
|
355
|
-
"i18n-js": "{version_constraint}"
|
|
356
|
-
|
|
357
|
-
// Or if you want unreleased version
|
|
358
|
-
// npm install requires it to be the gzipped tarball, see [npm install](https://www.npmjs.org/doc/cli/npm-install.html)
|
|
359
|
-
"i18n-js": "https://github.com/fnando/i18n-js/archive/{tag_name_or_branch_name_or_commit_sha}.tar.gz"
|
|
360
|
-
```
|
|
361
|
-
|
|
362
|
-
Run npm install then use via
|
|
363
|
-
|
|
364
|
-
```javascript
|
|
365
|
-
var i18n = require("i18n-js");
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
### Setting up
|
|
369
|
-
|
|
370
|
-
You **don't** need to set up a thing. The default settings will work just okay.
|
|
371
|
-
But if you want to split translations into several files or specify contexts,
|
|
372
|
-
you can follow the rest of this setting up section.
|
|
373
|
-
|
|
374
|
-
Set your locale is easy as
|
|
375
|
-
|
|
376
|
-
```javascript
|
|
377
|
-
I18n.defaultLocale = "pt-BR";
|
|
378
|
-
I18n.locale = "pt-BR";
|
|
379
|
-
I18n.currentLocale();
|
|
380
|
-
// pt-BR
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
**NOTE:** You can now apply your configuration **before I18n** is loaded like
|
|
384
|
-
this:
|
|
385
|
-
|
|
386
|
-
```javascript
|
|
387
|
-
I18n = {}; // You must define this object in top namespace, which should be `window`
|
|
388
|
-
I18n.defaultLocale = "pt-BR";
|
|
389
|
-
I18n.locale = "pt-BR";
|
|
390
|
-
|
|
391
|
-
// Load I18n from `i18n.js`, `application.js` or whatever
|
|
392
|
-
|
|
393
|
-
I18n.currentLocale();
|
|
394
|
-
// pt-BR
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
In practice, you'll have something like the following in your
|
|
398
|
-
`application.html.erb`:
|
|
399
|
-
|
|
400
|
-
```erb
|
|
401
|
-
<script type="text/javascript">
|
|
402
|
-
I18n.defaultLocale = "<%= I18n.default_locale %>";
|
|
403
|
-
I18n.locale = "<%= I18n.locale %>";
|
|
404
|
-
</script>
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
You can use translate your messages:
|
|
408
|
-
|
|
409
|
-
```javascript
|
|
410
|
-
I18n.t("some.scoped.translation");
|
|
411
|
-
// or translate with explicit setting of locale
|
|
412
|
-
I18n.t("some.scoped.translation", { locale: "fr" });
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
You can also interpolate values:
|
|
416
|
-
|
|
417
|
-
```javascript
|
|
418
|
-
// You need the `translations` object setup first
|
|
419
|
-
I18n.translations["en"] = {
|
|
420
|
-
greeting: "Hello %{name}",
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
I18n.t("greeting", { name: "John Doe" });
|
|
424
|
-
```
|
|
425
|
-
|
|
426
|
-
You can set default values for missing scopes:
|
|
427
|
-
|
|
428
|
-
```javascript
|
|
429
|
-
// simple translation
|
|
430
|
-
I18n.t("some.missing.scope", { defaultValue: "A default message" });
|
|
431
|
-
|
|
432
|
-
// with interpolation
|
|
433
|
-
I18n.t("noun", { defaultValue: "I'm a {{noun}}", noun: "Mac" });
|
|
434
|
-
```
|
|
435
|
-
|
|
436
|
-
You can also provide a list of default fallbacks for missing scopes:
|
|
437
|
-
|
|
438
|
-
```javascript
|
|
439
|
-
// As a scope
|
|
440
|
-
I18n.t("some.missing.scope", { defaults: [{ scope: "some.existing.scope" }] });
|
|
441
|
-
|
|
442
|
-
// As a simple translation
|
|
443
|
-
I18n.t("some.missing.scope", { defaults: [{ message: "Some message" }] });
|
|
444
|
-
```
|
|
445
|
-
|
|
446
|
-
Default values must be provided as an array of hashes where the key is the type
|
|
447
|
-
of translation desired, a `scope` or a `message`. The translation returned will
|
|
448
|
-
be either the first scope recognized, or the first message defined.
|
|
449
|
-
|
|
450
|
-
The translation will fallback to the `defaultValue` translation if no scope in
|
|
451
|
-
`defaults` matches and if no default of type `message` is found.
|
|
11
|
+
Oh, you don't use Ruby? No problem! You can still use i18n-js and the
|
|
12
|
+
[companion JavaScript package](https://npmjs.com/package/i18n-js).
|
|
452
13
|
|
|
453
|
-
|
|
14
|
+
## Installation
|
|
454
15
|
|
|
455
|
-
```
|
|
456
|
-
|
|
457
|
-
I18n.fallbacks = true;
|
|
458
|
-
</script>
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
By default missing translations will first be looked for in less specific
|
|
462
|
-
versions of the requested locale and if that fails by taking them from your
|
|
463
|
-
`I18n.defaultLocale`.
|
|
464
|
-
|
|
465
|
-
```javascript
|
|
466
|
-
// if I18n.defaultLocale = "en" and translation doesn't exist
|
|
467
|
-
// for I18n.locale = "de-DE" this key will be taken from "de" locale scope
|
|
468
|
-
// or, if that also doesn't exist, from "en" locale scope
|
|
469
|
-
I18n.t("some.missing.scope");
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
Custom fallback rules can also be specified for a particular language. There are
|
|
473
|
-
three different ways of doing it so:
|
|
474
|
-
|
|
475
|
-
```javascript
|
|
476
|
-
I18n.locales.no = ["nb", "en"];
|
|
477
|
-
I18n.locales.no = "nb";
|
|
478
|
-
I18n.locales.no = function (locale) {
|
|
479
|
-
return ["nb"];
|
|
480
|
-
};
|
|
481
|
-
```
|
|
482
|
-
|
|
483
|
-
### Translation Missing Behaviour Control
|
|
484
|
-
|
|
485
|
-
By default a missing translation will be displayed as
|
|
486
|
-
|
|
487
|
-
[missing "name of scope" translation]
|
|
488
|
-
|
|
489
|
-
While you are developing or if you do not want to provide a translation in the
|
|
490
|
-
default language you can set
|
|
491
|
-
|
|
492
|
-
```javascript
|
|
493
|
-
I18n.missingBehaviour = "guess";
|
|
494
|
-
```
|
|
495
|
-
|
|
496
|
-
this will take the last section of your scope and guess the intended value.
|
|
497
|
-
Camel case becomes lower cased text and underscores are replaced with space
|
|
498
|
-
|
|
499
|
-
questionnaire.whatIsYourFavorite_ChristmasPresent
|
|
500
|
-
|
|
501
|
-
becomes "what is your favorite Christmas present"
|
|
502
|
-
|
|
503
|
-
#### Option `missingTranslationPrefix`
|
|
504
|
-
|
|
505
|
-
In order to still detect untranslated strings, you can set
|
|
506
|
-
`I18n.missingTranslationPrefix` to something like:
|
|
507
|
-
|
|
508
|
-
```javascript
|
|
509
|
-
I18n.missingTranslationPrefix = "EE: ";
|
|
510
|
-
```
|
|
511
|
-
|
|
512
|
-
And result will be:
|
|
513
|
-
|
|
514
|
-
```javascript
|
|
515
|
-
"EE: what is your favorite Christmas present";
|
|
516
|
-
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
This will help you doing automated tests against your localisation assets.
|
|
520
|
-
|
|
521
|
-
#### Customize return when translation entry missing
|
|
522
|
-
|
|
523
|
-
Some people prefer returning `null`/`undefined` for missing translation:
|
|
524
|
-
|
|
525
|
-
```javascript
|
|
526
|
-
I18n.missingTranslation = function (scope, options) {
|
|
527
|
-
return undefined;
|
|
528
|
-
};
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
### Option `defaultSeparator` (global) / `separator` (local)
|
|
532
|
-
|
|
533
|
-
Default separator of translation key is `.` (dot)
|
|
534
|
-
Meaning `I18n.t("scope.entry")` would search for translation entry `I18n.translations[locale].scope.entry`
|
|
535
|
-
Using a different separator can be done either globally or locally.
|
|
536
|
-
|
|
537
|
-
Globally: `I18n.defaultSeparator = newSeparator`
|
|
538
|
-
Locally: `I18n.t("full_sentences|Server Busy. Please retry later", {separator: '|'})`
|
|
539
|
-
|
|
540
|
-
### Pluralization
|
|
541
|
-
|
|
542
|
-
Pluralization is possible as well and by default provides English rules:
|
|
543
|
-
|
|
544
|
-
```javascript
|
|
545
|
-
I18n.t("inbox.counting", { count: 10 }); // You have 10 messages
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
The sample above expects the following translation:
|
|
549
|
-
|
|
550
|
-
```yaml
|
|
551
|
-
en:
|
|
552
|
-
inbox:
|
|
553
|
-
counting:
|
|
554
|
-
one: You have 1 new message
|
|
555
|
-
other: You have {{count}} new messages
|
|
556
|
-
zero: You have no messages
|
|
557
|
-
```
|
|
558
|
-
|
|
559
|
-
**NOTE:** Rails I18n recognizes the `zero` option.
|
|
560
|
-
|
|
561
|
-
If you need special rules just define them for your language, for example
|
|
562
|
-
Russian, just add a new pluralizer:
|
|
563
|
-
|
|
564
|
-
```javascript
|
|
565
|
-
I18n.pluralization["ru"] = function (count) {
|
|
566
|
-
var key =
|
|
567
|
-
count % 10 == 1 && count % 100 != 11
|
|
568
|
-
? "one"
|
|
569
|
-
: [2, 3, 4].indexOf(count % 10) >= 0 &&
|
|
570
|
-
[12, 13, 14].indexOf(count % 100) < 0
|
|
571
|
-
? "few"
|
|
572
|
-
: count % 10 == 0 ||
|
|
573
|
-
[5, 6, 7, 8, 9].indexOf(count % 10) >= 0 ||
|
|
574
|
-
[11, 12, 13, 14].indexOf(count % 100) >= 0
|
|
575
|
-
? "many"
|
|
576
|
-
: "other";
|
|
577
|
-
return [key];
|
|
578
|
-
};
|
|
579
|
-
```
|
|
580
|
-
|
|
581
|
-
You can find all rules on
|
|
582
|
-
<https://unicode-org.github.io/cldr-staging/charts/37/supplemental/language_plural_rules.html>.
|
|
583
|
-
|
|
584
|
-
If you're using the same scope over and over again, you may use the `scope`
|
|
585
|
-
option.
|
|
586
|
-
|
|
587
|
-
```javascript
|
|
588
|
-
var options = { scope: "activerecord.attributes.user" };
|
|
589
|
-
|
|
590
|
-
I18n.t("name", options);
|
|
591
|
-
I18n.t("email", options);
|
|
592
|
-
I18n.t("username", options);
|
|
593
|
-
```
|
|
594
|
-
|
|
595
|
-
You can also provide an array as scope.
|
|
596
|
-
|
|
597
|
-
```javascript
|
|
598
|
-
// use the greetings.hello scope
|
|
599
|
-
I18n.t(["greetings", "hello"]);
|
|
600
|
-
```
|
|
601
|
-
|
|
602
|
-
#### Number formatting
|
|
603
|
-
|
|
604
|
-
Similar to Rails helpers, you have localized number and currency formatting.
|
|
605
|
-
|
|
606
|
-
```javascript
|
|
607
|
-
I18n.l("currency", 1990.99);
|
|
608
|
-
// $1,990.99
|
|
609
|
-
|
|
610
|
-
I18n.l("number", 1990.99);
|
|
611
|
-
// 1,990.99
|
|
612
|
-
|
|
613
|
-
I18n.l("percentage", 123.45);
|
|
614
|
-
// 123.450%
|
|
615
|
-
```
|
|
616
|
-
|
|
617
|
-
To have more control over number formatting, you can use the `I18n.toNumber`,
|
|
618
|
-
`I18n.toPercentage`, `I18n.toCurrency` and `I18n.toHumanSize` functions.
|
|
619
|
-
|
|
620
|
-
```javascript
|
|
621
|
-
I18n.toNumber(1000); // 1,000.000
|
|
622
|
-
I18n.toCurrency(1000); // $1,000.00
|
|
623
|
-
I18n.toPercentage(100); // 100.000%
|
|
624
|
-
```
|
|
625
|
-
|
|
626
|
-
The `toNumber` and `toPercentage` functions accept the following options:
|
|
627
|
-
|
|
628
|
-
- `precision`: defaults to `3`
|
|
629
|
-
- `separator`: defaults to `.`
|
|
630
|
-
- `delimiter`: defaults to `,`
|
|
631
|
-
- `strip_insignificant_zeros`: defaults to `false`
|
|
632
|
-
|
|
633
|
-
See some number formatting examples:
|
|
634
|
-
|
|
635
|
-
```javascript
|
|
636
|
-
I18n.toNumber(1000, { precision: 0 }); // 1,000
|
|
637
|
-
I18n.toNumber(1000, { delimiter: ".", separator: "," }); // 1.000,000
|
|
638
|
-
I18n.toNumber(1000, { delimiter: ".", precision: 0 }); // 1.000
|
|
639
|
-
```
|
|
640
|
-
|
|
641
|
-
The `toCurrency` function accepts the following options:
|
|
642
|
-
|
|
643
|
-
- `precision`: sets the level of precision
|
|
644
|
-
- `separator`: sets the separator between the units
|
|
645
|
-
- `delimiter`: sets the thousands delimiter
|
|
646
|
-
- `format`: sets the format of the output string
|
|
647
|
-
- `unit`: sets the denomination of the currency
|
|
648
|
-
- `strip_insignificant_zeros`: defaults to `false`
|
|
649
|
-
- `sign_first`: defaults to `true`
|
|
650
|
-
|
|
651
|
-
You can provide only the options you want to override:
|
|
652
|
-
|
|
653
|
-
```javascript
|
|
654
|
-
I18n.toCurrency(1000, { precision: 0 }); // $1,000
|
|
655
|
-
```
|
|
656
|
-
|
|
657
|
-
The `toHumanSize` function accepts the following options:
|
|
658
|
-
|
|
659
|
-
- `precision`: defaults to `1`
|
|
660
|
-
- `separator`: defaults to `.`
|
|
661
|
-
- `delimiter`: defaults to `""`
|
|
662
|
-
- `strip_insignificant_zeros`: defaults to `false`
|
|
663
|
-
- `format`: defaults to `%n%u`
|
|
664
|
-
- `scope`: defaults to `""`
|
|
665
|
-
|
|
666
|
-
<!---->
|
|
667
|
-
|
|
668
|
-
```javascript
|
|
669
|
-
I18n.toHumanSize(1234); // 1KB
|
|
670
|
-
I18n.toHumanSize(1234 * 1024); // 1MB
|
|
671
|
-
```
|
|
672
|
-
|
|
673
|
-
#### Date formatting
|
|
674
|
-
|
|
675
|
-
```javascript
|
|
676
|
-
// accepted formats
|
|
677
|
-
I18n.l("date.formats.short", "2009-09-18"); // yyyy-mm-dd
|
|
678
|
-
I18n.l("time.formats.short", "2009-09-18 23:12:43"); // yyyy-mm-dd hh:mm:ss
|
|
679
|
-
I18n.l("time.formats.short", "2009-11-09T18:10:34"); // JSON format with local Timezone (part of ISO-8601)
|
|
680
|
-
I18n.l("time.formats.short", "2009-11-09T18:10:34Z"); // JSON format in UTC (part of ISO-8601)
|
|
681
|
-
I18n.l("date.formats.short", 1251862029000); // Epoch time
|
|
682
|
-
I18n.l("date.formats.short", "09/18/2009"); // mm/dd/yyyy
|
|
683
|
-
I18n.l("date.formats.short", new Date()); // Date object
|
|
684
|
-
```
|
|
685
|
-
|
|
686
|
-
You can also add placeholders to the date format:
|
|
687
|
-
|
|
688
|
-
```javascript
|
|
689
|
-
I18n.translations["en"] = {
|
|
690
|
-
date: {
|
|
691
|
-
formats: {
|
|
692
|
-
ordinal_day: "%B %{day}",
|
|
693
|
-
},
|
|
694
|
-
},
|
|
695
|
-
};
|
|
696
|
-
|
|
697
|
-
I18n.l("date.formats.ordinal_day", "2009-09-18", { day: "18th" }); // Sep 18th
|
|
698
|
-
```
|
|
699
|
-
|
|
700
|
-
If you prefer, you can use the `I18n.toTime` and `I18n.strftime` functions to
|
|
701
|
-
format dates.
|
|
702
|
-
|
|
703
|
-
```javascript
|
|
704
|
-
var date = new Date();
|
|
705
|
-
I18n.toTime("date.formats.short", "2009-09-18");
|
|
706
|
-
I18n.toTime("date.formats.short", date);
|
|
707
|
-
I18n.strftime(date, "%d/%m/%Y");
|
|
16
|
+
```bash
|
|
17
|
+
gem install i18n-js
|
|
708
18
|
```
|
|
709
19
|
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
%a - The abbreviated weekday name (Sun)
|
|
713
|
-
%A - The full weekday name (Sunday)
|
|
714
|
-
%b - The abbreviated month name (Jan)
|
|
715
|
-
%B - The full month name (January)
|
|
716
|
-
%c - The preferred local date and time representation
|
|
717
|
-
%d - Day of the month (01..31)
|
|
718
|
-
%-d - Day of the month (1..31)
|
|
719
|
-
%H - Hour of the day, 24-hour clock (00..23)
|
|
720
|
-
%-H/%k - Hour of the day, 24-hour clock (0..23)
|
|
721
|
-
%I - Hour of the day, 12-hour clock (01..12)
|
|
722
|
-
%-I/%l - Hour of the day, 12-hour clock (1..12)
|
|
723
|
-
%m - Month of the year (01..12)
|
|
724
|
-
%-m - Month of the year (1..12)
|
|
725
|
-
%M - Minute of the hour (00..59)
|
|
726
|
-
%-M - Minute of the hour (0..59)
|
|
727
|
-
%p - Meridian indicator (AM or PM)
|
|
728
|
-
%P - Meridian indicator (am or pm)
|
|
729
|
-
%S - Second of the minute (00..60)
|
|
730
|
-
%-S - Second of the minute (0..60)
|
|
731
|
-
%w - Day of the week (Sunday is 0, 0..6)
|
|
732
|
-
%y - Year without a century (00..99)
|
|
733
|
-
%-y - Year without a century (0..99)
|
|
734
|
-
%Y - Year with century
|
|
735
|
-
%z/%Z - Timezone offset (+0545)
|
|
736
|
-
|
|
737
|
-
Check out `spec/*.spec.js` files for more examples!
|
|
738
|
-
|
|
739
|
-
#### Using pluralization and number formatting together
|
|
20
|
+
Or add the following line to your project's Gemfile:
|
|
740
21
|
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
```json
|
|
745
|
-
{
|
|
746
|
-
"en": {
|
|
747
|
-
"point": {
|
|
748
|
-
"one": "1 Point",
|
|
749
|
-
"other": "{{formatted_number}} Points",
|
|
750
|
-
"zero": "0 Points"
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
```
|
|
755
|
-
|
|
756
|
-
```js
|
|
757
|
-
var point_in_number = 1000;
|
|
758
|
-
I18n.t("point", {
|
|
759
|
-
count: point_in_number,
|
|
760
|
-
formatted_number: I18n.toNumber(point_in_number),
|
|
761
|
-
});
|
|
22
|
+
```ruby
|
|
23
|
+
gem "i18n-js", "~> 4.0.0.alpha1"
|
|
762
24
|
```
|
|
763
25
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
## Using multiple exported translation files on a page.
|
|
767
|
-
|
|
768
|
-
This method is useful for very large apps where a single contained
|
|
769
|
-
translations.js file is not desirable. Examples would be a global translations
|
|
770
|
-
file and a more specific route translation file.
|
|
26
|
+
## Usage
|
|
771
27
|
|
|
772
|
-
|
|
28
|
+
About patterns:
|
|
773
29
|
|
|
774
|
-
|
|
775
|
-
|
|
30
|
+
- Patterns can use `*` as a wildcard and can appear more than once.
|
|
31
|
+
- `*` will include everything
|
|
32
|
+
- `*.messages.*`
|
|
33
|
+
- Patterns starting with `!` are excluded.
|
|
34
|
+
- `!*.activerecord.*` will exclude all ActiveRecord translations.
|
|
776
35
|
|
|
777
|
-
|
|
778
|
-
sort_translation_keys: true
|
|
779
|
-
fallbacks: false
|
|
36
|
+
The config file:
|
|
780
37
|
|
|
38
|
+
```yml
|
|
39
|
+
---
|
|
781
40
|
translations:
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
41
|
+
- file: app/frontend/locales/en.json
|
|
42
|
+
patterns:
|
|
43
|
+
- "*"
|
|
44
|
+
- "!*.activerecord"
|
|
45
|
+
- "!*.errors"
|
|
46
|
+
- "!*.number.nth"
|
|
785
47
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
+ file: "app/assets/javascript/nls/global.js"
|
|
791
|
-
only:
|
|
792
|
-
+ '*'
|
|
793
|
-
# Exempt any routes specific translations from being
|
|
794
|
-
# included in the global translation file
|
|
795
|
-
except:
|
|
796
|
-
+ '*.welcome.*'
|
|
797
|
-
+ '*.albums.*'
|
|
48
|
+
- file: app/frontend/locales/:locale.json
|
|
49
|
+
patterns:
|
|
50
|
+
- "*"
|
|
798
51
|
```
|
|
799
52
|
|
|
800
|
-
|
|
801
|
-
can be loaded via the `javascript_include_tag`
|
|
802
|
-
|
|
803
|
-
2. Add the `javascript_include_tag` to your layout and to any route specific
|
|
804
|
-
files that will require it.
|
|
53
|
+
The Ruby API:
|
|
805
54
|
|
|
806
55
|
```ruby
|
|
807
|
-
|
|
808
|
-
<%= javascript_include_tag(
|
|
809
|
-
"i18n"
|
|
810
|
-
"nls/global"
|
|
811
|
-
) %>
|
|
812
|
-
```
|
|
813
|
-
|
|
814
|
-
and in the route specific
|
|
56
|
+
require "i18n-js"
|
|
815
57
|
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
<%= javascript_include_tag(
|
|
819
|
-
"nls/welcome"
|
|
820
|
-
) %>
|
|
58
|
+
I18nJS.call(config_file: "config/i18n.yml")
|
|
59
|
+
I18nJS.call(config: config)
|
|
821
60
|
```
|
|
822
61
|
|
|
823
|
-
|
|
62
|
+
The CLI API:
|
|
824
63
|
|
|
825
|
-
```
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
nls/*
|
|
829
|
-
)
|
|
64
|
+
```console
|
|
65
|
+
$ i18n init --config config/i18n.yml
|
|
66
|
+
$ i18n export --config config/i18n.yml --require config/environment.rb
|
|
830
67
|
```
|
|
831
68
|
|
|
832
|
-
|
|
69
|
+
By default, `i18n` will use `config/i18n.yml` and `config/environment.rb` as the
|
|
70
|
+
configuration files. If you don't have these files, then you'll need to specify
|
|
71
|
+
both `--config` and `--require`.
|
|
833
72
|
|
|
834
|
-
|
|
73
|
+
## Automatically export translations
|
|
835
74
|
|
|
836
|
-
|
|
837
|
-
be exported to. You want to use this location so that it can be properly
|
|
838
|
-
precompiled by r.js.
|
|
75
|
+
### Using guard
|
|
839
76
|
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
77
|
+
Install [guard](https://rubygems.org/packages/guard) and
|
|
78
|
+
[guard-compat](https://rubygems.org/packages/guard-compat). Then create a
|
|
79
|
+
Guardfile with the following configuration:
|
|
843
80
|
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
# In your shims
|
|
854
|
-
shims:
|
|
855
|
-
nls/welcome:
|
|
856
|
-
deps:
|
|
857
|
-
+ i18n
|
|
858
|
-
|
|
859
|
-
nls/global:
|
|
860
|
-
deps:
|
|
861
|
-
+ i18n
|
|
862
|
-
|
|
863
|
-
# Finally in your modules
|
|
864
|
-
modules:
|
|
865
|
-
+ name: 'application'
|
|
866
|
-
include:
|
|
867
|
-
+ i18n
|
|
868
|
-
+ 'nls/global'
|
|
869
|
-
|
|
870
|
-
+ name: 'welcome'
|
|
871
|
-
exclude:
|
|
872
|
-
+ application
|
|
873
|
-
include:
|
|
874
|
-
+ 'nls/welcome'
|
|
875
|
-
```
|
|
876
|
-
|
|
877
|
-
3. When `rake assets:precompile` is executed it will optimize the translations
|
|
878
|
-
into the correct modules so they are loaded with their assigned module, and
|
|
879
|
-
loading them with requirejs is as simple as requiring any other shim.
|
|
880
|
-
|
|
881
|
-
```javascript
|
|
882
|
-
define(["welcome/other_asset", "nls/welcome"], function (otherAsset) {
|
|
883
|
-
// ...
|
|
884
|
-
});
|
|
885
|
-
```
|
|
886
|
-
|
|
887
|
-
4. (optional) As an additional configuration we can make a task to be run before
|
|
888
|
-
the requirejs optimizer. This will allow any automated scripts that run the
|
|
889
|
-
requirejs optimizer to export the strings before we run r.js.
|
|
890
|
-
|
|
891
|
-
```rake
|
|
892
|
-
# lib/tasks/i18n.rake
|
|
893
|
-
Rake::Task[:'i18n:js:export'].prerequisites.clear
|
|
894
|
-
task :'i18n:js:export' => :'i18n:js:before_export'
|
|
895
|
-
task :'requirejs:precompile:external' => :'i18n:js:export'
|
|
896
|
-
|
|
897
|
-
namespace :i18n do
|
|
898
|
-
namespace :js do
|
|
899
|
-
task :before_export => :'assets:environment' do
|
|
900
|
-
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{yml,rb}')]
|
|
901
|
-
I18n.backend.load_translations
|
|
902
|
-
end
|
|
903
|
-
end
|
|
81
|
+
```ruby
|
|
82
|
+
guard(:"i18n-js",
|
|
83
|
+
run_on_start: true,
|
|
84
|
+
config_file: "./config/i18n.yml",
|
|
85
|
+
require_file: "./config/environment.rb") do
|
|
86
|
+
watch(%r{^(app|config)/locales/.+\.(yml|po)$})
|
|
87
|
+
watch(%r{^config/i18n.yml$})
|
|
88
|
+
watch("Gemfile")
|
|
904
89
|
end
|
|
905
90
|
```
|
|
906
91
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
The JavaScript library is language agnostic; so you can use it with PHP, Python,
|
|
910
|
-
[your favorite language here]. The only requirement is that you need to set the
|
|
911
|
-
`translations` attribute like following:
|
|
912
|
-
|
|
913
|
-
```javascript
|
|
914
|
-
I18n.translations = {};
|
|
915
|
-
|
|
916
|
-
I18n.translations["en"] = {
|
|
917
|
-
message: "Some special message for you",
|
|
918
|
-
};
|
|
919
|
-
|
|
920
|
-
I18n.translations["pt-BR"] = {
|
|
921
|
-
message: "Uma mensagem especial para você",
|
|
922
|
-
};
|
|
923
|
-
```
|
|
924
|
-
|
|
925
|
-
## Known Issues
|
|
926
|
-
|
|
927
|
-
### Missing translations in precompiled file(s) after adding any new locale file
|
|
928
|
-
|
|
929
|
-
Due to the design of `sprockets`:
|
|
930
|
-
|
|
931
|
-
- `depend_on` only takes file paths, not directory paths
|
|
932
|
-
- registered `preprocessors` are only run when the fingerprint of any asset
|
|
933
|
-
file, including `.erb` files, is changed
|
|
934
|
-
|
|
935
|
-
This means that new locale files will not be detected, and so they will not
|
|
936
|
-
trigger a i18n-js refresh. There are a few approaches to work around this:
|
|
937
|
-
|
|
938
|
-
1. You can force i18n-js to update its translations by completely clearing the
|
|
939
|
-
assets cache. Use one of the following:
|
|
940
|
-
|
|
941
|
-
```bash
|
|
942
|
-
$ rake assets:clobber
|
|
943
|
-
# Or, with older versions of Rails:
|
|
944
|
-
$ rake tmp:cache:clear
|
|
945
|
-
```
|
|
946
|
-
|
|
947
|
-
These commands will remove _all_ fingerprinted assets, and you will have to
|
|
948
|
-
recompile them with
|
|
949
|
-
|
|
950
|
-
```bash
|
|
951
|
-
$ rake assets:precompile
|
|
952
|
-
```
|
|
92
|
+
If you files in a different location, the remember to configure file paths
|
|
93
|
+
accordingly.
|
|
953
94
|
|
|
954
|
-
|
|
955
|
-
cached pages may be broken by this, so they will need to be refreshed.
|
|
95
|
+
Now you can run `guard start -i`.
|
|
956
96
|
|
|
957
|
-
|
|
97
|
+
### Using listen
|
|
958
98
|
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
**Note:** See issue [#213](https://github.com/fnando/i18n-js/issues/213) for
|
|
962
|
-
more details and discussion of this issue.
|
|
963
|
-
|
|
964
|
-
### Translations in JS are not updated when Sprockets not loaded before this gem
|
|
965
|
-
|
|
966
|
-
The "rails engine" declaration will try to detect existence of "sprockets"
|
|
967
|
-
before adding the initailizer If sprockets is loaded after this gem, the
|
|
968
|
-
preprocessor for making JS translations file cache to depend on content of
|
|
969
|
-
locale files will not be hooked. So ensure sprockets is loaded before this gem
|
|
970
|
-
by moving the entry of sprockets in the Gemfile or adding "require" statements
|
|
971
|
-
for sprockets somewhere.
|
|
972
|
-
|
|
973
|
-
**Note:** See issue [#404](https://github.com/fnando/i18n-js/issues/404) for
|
|
974
|
-
more details and discussion of this issue.
|
|
975
|
-
|
|
976
|
-
### JS `I18n.toCurrency` & `I18n.toNumber` cannot handle large integers
|
|
977
|
-
|
|
978
|
-
The above methods use `toFixed` and it only supports 53 bit integers. Ref:
|
|
979
|
-
http://2ality.com/2012/07/large-integers.html
|
|
980
|
-
|
|
981
|
-
Feel free to find & discuss possible solution(s) at issue
|
|
982
|
-
[#511](https://github.com/fnando/i18n-js/issues/511)
|
|
983
|
-
|
|
984
|
-
### Only works with `Simple` backend
|
|
985
|
-
|
|
986
|
-
If you set `I18n.backend` to something other than the default `Simple` backend,
|
|
987
|
-
you will likely get an exception like this:
|
|
988
|
-
|
|
989
|
-
```
|
|
990
|
-
Undefined method 'initialized?' for <your backend class>
|
|
991
|
-
```
|
|
992
|
-
|
|
993
|
-
For now, i18n-js is only compatible with the `Simple` backend. If you need a
|
|
994
|
-
more sophisticated backend for your rails application, like
|
|
995
|
-
`I18n::Backend::ActiveRecord`, you can setup i18n-js to get translations from a
|
|
996
|
-
separate `Simple` backend, by adding the following in an initializer:
|
|
99
|
+
Create a file under `config/initializers/i18n.rb` with the following content:
|
|
997
100
|
|
|
998
101
|
```ruby
|
|
999
|
-
|
|
1000
|
-
I18n.backend = I18n::Backend::Chain.new(<your other backend(s)>, I18n.backend)
|
|
1001
|
-
```
|
|
1002
|
-
|
|
1003
|
-
This will use your backend with the default `Simple` backend as fallback, while
|
|
1004
|
-
i18n-js only sees and uses the simple backend. This means however, that only
|
|
1005
|
-
translations from your static locale files will be present in JavaScript.
|
|
102
|
+
# frozen_string_literal: true
|
|
1006
103
|
|
|
1007
|
-
|
|
104
|
+
require "i18n-js/listen"
|
|
1008
105
|
|
|
1009
|
-
|
|
1010
|
-
I18n::JS.backend = I18n::Backend::Simple.new
|
|
1011
|
-
I18n.backend = <something different>
|
|
106
|
+
I18nJS.listen
|
|
1012
107
|
```
|
|
1013
108
|
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
a different object. One option would be to patch `I18n.reload!` in an
|
|
1018
|
-
initializer:
|
|
109
|
+
The code above will watch for changes based on `config/i18n.yml` and
|
|
110
|
+
`config/locales`. You can customize these options with
|
|
111
|
+
`I18nJS.listen(config_file: "config/i18n.yml", locales_dir: "config/locales")`.
|
|
1019
112
|
|
|
1020
|
-
|
|
1021
|
-
module I18n
|
|
1022
|
-
def self.reload!
|
|
1023
|
-
I18n::JS.backend.reload!
|
|
1024
|
-
super
|
|
1025
|
-
end
|
|
1026
|
-
end
|
|
1027
|
-
```
|
|
113
|
+
### Integrating with your frontend
|
|
1028
114
|
|
|
1029
|
-
|
|
1030
|
-
|
|
115
|
+
You're done exporting files, now what? Well, go to
|
|
116
|
+
[i18n](https://github.com/fnando/i18n) to discover how to use the NPM package
|
|
117
|
+
that loads all the exported translation.
|
|
1031
118
|
|
|
1032
119
|
## Maintainer
|
|
1033
120
|
|
|
1034
|
-
- Nando Vieira
|
|
1035
|
-
|
|
1036
|
-
## Contributing
|
|
1037
|
-
|
|
1038
|
-
Once you've made your great commits:
|
|
1039
|
-
|
|
1040
|
-
1. [Fork](http://help.github.com/forking/) I18n.js
|
|
1041
|
-
2. Create a branch with a clear name
|
|
1042
|
-
3. Make your changes (Please also add/change spec, README and CHANGELOG if
|
|
1043
|
-
applicable)
|
|
1044
|
-
4. Push changes to the created branch
|
|
1045
|
-
5. [Create an Pull Request](http://github.com/fnando/i18n-js/pulls)
|
|
1046
|
-
6. That's it!
|
|
1047
|
-
|
|
1048
|
-
Please respect the indentation rules and code style. And use 2 spaces, not tabs.
|
|
1049
|
-
And don't touch the versioning thing.
|
|
1050
|
-
|
|
1051
|
-
## Running tests
|
|
121
|
+
- [Nando Vieira](https://github.com/fnando)
|
|
1052
122
|
|
|
1053
|
-
|
|
123
|
+
## Contributors
|
|
1054
124
|
|
|
1055
|
-
|
|
125
|
+
- https://github.com/fnando/i18n-js/contributors
|
|
1056
126
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
Then execute the following command from the lib's root directory:
|
|
1060
|
-
|
|
1061
|
-
$ npm test
|
|
1062
|
-
|
|
1063
|
-
To run using your browser, just open the `spec/js/specs.html` file.
|
|
127
|
+
## Contributing
|
|
1064
128
|
|
|
1065
|
-
|
|
129
|
+
For more details about how to contribute, please read
|
|
130
|
+
https://github.com/fnando/i18n-js/blob/main/CONTRIBUTING.md.
|
|
1066
131
|
|
|
1067
132
|
## License
|
|
1068
133
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
this software and associated documentation files (the 'Software'), to deal in
|
|
1073
|
-
the Software without restriction, including without limitation the rights to
|
|
1074
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
1075
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
1076
|
-
subject to the following conditions:
|
|
134
|
+
The gem is available as open source under the terms of the
|
|
135
|
+
[MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
|
|
136
|
+
found at https://github.com/fnando/i18n-js/blob/main/LICENSE.md.
|
|
1077
137
|
|
|
1078
|
-
|
|
1079
|
-
copies or substantial portions of the Software.
|
|
138
|
+
## Code of Conduct
|
|
1080
139
|
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
1085
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
1086
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
140
|
+
Everyone interacting in the i18n-js project's codebases, issue trackers, chat
|
|
141
|
+
rooms and mailing lists is expected to follow the
|
|
142
|
+
[code of conduct](https://github.com/fnando/i18n-js/blob/main/CODE_OF_CONDUCT.md).
|