i18n-js 4.0.0.alpha2 → 4.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45e8592f190777f676916988517d474dffb4f18f09120df26733c947d63ca140
4
- data.tar.gz: 04dfd46cfd05501a7cd1e97c5612a1ab5dbec52f98bad5f9119febcf28ce3ab8
3
+ metadata.gz: 7e0fd83a034e8eaa82e97f46beb39a96da4d671952762f7751d093d4823e1aed
4
+ data.tar.gz: acff26df94aa46c0c50d5864c97b32bc1108a611a748c2dd7fff4d626ec41cf4
5
5
  SHA512:
6
- metadata.gz: 96caedcf824fb434a3b77dba666dd23cff72fbfd9f3d3175c928d768920d402f2d9250bb9ff0810e836ff5fbd90d3825b19621a4fd7c27ef10a7a40586990326
7
- data.tar.gz: bc68a8b9e54c991dc21e50ca52986b2f5c39418e6aed3b48664efbcb501e8f34d7a1333a608d6de4b6d5d8bcf7f2fc3c2de5584123b47cc6873e29047da2fdfb
6
+ metadata.gz: d72a28ddbe75742e605c86d8e3b06ce2e1ada21bc95f2b189e2e120b671c7c0d4d239dfc7c3753abd4b97f57820146001cfdfb89e2c407ae3054ea93fba98d72
7
+ data.tar.gz: 5ed38c2ea91915fadcc6cc7a4b718d1473cc41afff0c5cd3f6dd6e1345e2eed29c53bace6403239dd516a180485b055414cd65c00291747d20c6055c6b2f6a2a
@@ -0,0 +1,5 @@
1
+ ---
2
+ contact_links:
3
+ - name: "🤨 Q&A"
4
+ url: https://github.com/fnando/i18n-js/discussions/new?category=q-a
5
+ about: Have a question? Ask it away here!
@@ -2,8 +2,10 @@
2
2
  name: ruby-tests
3
3
 
4
4
  on:
5
- pull_request:
5
+ pull_request_target:
6
6
  push:
7
+ branches:
8
+ - v4
7
9
  workflow_dispatch:
8
10
  inputs: {}
9
11
 
@@ -14,14 +16,17 @@ jobs:
14
16
  strategy:
15
17
  fail-fast: false
16
18
  matrix:
17
- ruby: ["2.7", "3.0"]
19
+ ruby: ["2.7", "3.0", "3.1"]
18
20
  gemfile:
19
21
  - Gemfile
22
+ if: |
23
+ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target' ||
24
+ github.actor != 'dependabot[bot]'
20
25
 
21
26
  steps:
22
- - uses: actions/checkout@v1
27
+ - uses: actions/checkout@v3
23
28
 
24
- - uses: actions/cache@v2
29
+ - uses: actions/cache@v3
25
30
  id: bundler-cache
26
31
  with:
27
32
  path: vendor/bundle
data/.rubocop.yml CHANGED
@@ -7,11 +7,10 @@ AllCops:
7
7
  NewCops: enable
8
8
  Exclude:
9
9
  - tmp/**/*
10
+ - vendor/**/*
11
+ - gemfiles/**/*
10
12
 
11
13
  Naming/FileName:
12
14
  Exclude:
13
15
  - lib/i18n-js.rb
14
16
  - lib/guard/i18n-js.rb
15
-
16
- Metrics:
17
- Enabled: false
data/README.md CHANGED
@@ -1,15 +1,30 @@
1
- # i18n-js
2
-
3
- [![Tests](https://github.com/fnando/i18n-js/workflows/ruby-tests/badge.svg)](https://github.com/fnando/i18n-js)
4
- [![Code Climate](https://codeclimate.com/github/fnando/i18n-js/badges/gpa.svg)](https://codeclimate.com/github/fnando/i18n-js)
5
- [![Gem](https://img.shields.io/gem/v/i18n-js.svg)](https://rubygems.org/gems/i18n-js)
6
- [![Gem](https://img.shields.io/gem/dt/i18n-js.svg)](https://rubygems.org/gems/i18n-js)
7
-
8
- Export [i18n](https://rubygems.org/gems/i18n) translations to JSON. A perfect
9
- fit if you want to export translations to JavaScript.
10
-
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).
1
+ <p align="center">
2
+ <img width="250" height="58" src="https://github.com/fnando/i18n-js/raw/main/i18njs.png" alt="i18n.js">
3
+ </p>
4
+
5
+ <p align="center">
6
+ Export <a href="https://rubygems.org/gems/i18n">i18n</a> translations to JSON.
7
+ <br>
8
+ A perfect fit if you want to export translations to JavaScript.
9
+ </p>
10
+
11
+ <p align="center">
12
+ <small>
13
+ Oh, you don't use Ruby? No problem! You can still use i18n-js
14
+ <br>
15
+ and the
16
+ <a href="https://www.npmjs.com/package/i18n-js/v/next">companion JavaScript package</a>.
17
+ </small>
18
+ </p>
19
+
20
+ <p align="center">
21
+ <a href="https://github.com/fnando/i18n-js"><img src="https://github.com/fnando/i18n-js/workflows/ruby-tests/badge.svg" alt="Tests"></a>
22
+ <a href="https://rubygems.org/gems/i18n-js"><img src="https://img.shields.io/gem/v/i18n-js.svg" alt="Gem"></a>
23
+ <a href="https://rubygems.org/gems/i18n-js"><img src="https://img.shields.io/gem/dt/i18n-js.svg" alt="Gem"></a>
24
+ <a href="https://tldrlegal.com/license/mit-license"><img src="https://img.shields.io/:License-MIT-blue.svg" alt="MIT License"></a>
25
+ </p>
26
+
27
+ ![This branch contains the code for v4, our next major release.](https://messages-svg.herokuapp.com/warning.svg?message=This%20branch%20contains%20the%20code%20for%20v4%2C%20our%20next%20major%20release.)
13
28
 
14
29
  ## Installation
15
30
 
@@ -45,11 +60,16 @@ translations:
45
60
  - "!*.errors"
46
61
  - "!*.number.nth"
47
62
 
48
- - file: app/frontend/locales/:locale.json
63
+ - file: app/frontend/locales/:locale.:digest.json
49
64
  patterns:
50
65
  - "*"
51
66
  ```
52
67
 
68
+ The output path can use the following placeholders:
69
+
70
+ - `:locale`: the language that's being exported.
71
+ - `:digest`: the MD5 hex digest of the exported file.
72
+
53
73
  The Ruby API:
54
74
 
55
75
  ```ruby
@@ -72,6 +92,51 @@ both `--config` and `--require`.
72
92
 
73
93
  ## Automatically export translations
74
94
 
95
+ ### Using watchman
96
+
97
+ Create a script at `bin/i18n-watch`.
98
+
99
+ ```bash
100
+ #!/usr/bin/env bash
101
+
102
+ root=`pwd`
103
+
104
+ watchman watch-del "$root"
105
+ watchman watch-project "$root"
106
+ watchman trigger-del "$root" i18n
107
+
108
+ watchman -j <<-JSON
109
+ [
110
+ "trigger",
111
+ "$root",
112
+ {
113
+ "name": "i18n",
114
+ "expression": [
115
+ "anyof",
116
+ ["match", "config/locales/**/*.yml", "wholename"],
117
+ ["match", "config/i18n.yml", "wholename"]
118
+ ],
119
+ "command": ["i18n", "export"]
120
+ }
121
+ ]
122
+ JSON
123
+
124
+ # If you're running this through Foreman,
125
+ # the uncomment the following lines:
126
+ # while true; do
127
+ # sleep 1
128
+ # done
129
+ ```
130
+
131
+ Make it executable with `chmod +x bin/i18n-watch`. To watch for changes, run
132
+ `./bin/i18n-watch`. If you're using Foreman, make sure you uncommented the lines
133
+ that keep the process running (`while..`), and add something like the following
134
+ line to your Procfile:
135
+
136
+ ```
137
+ i18n: ./bin/i18n-watch
138
+ ```
139
+
75
140
  ### Using guard
76
141
 
77
142
  Install [guard](https://rubygems.org/packages/guard) and
@@ -89,7 +154,7 @@ guard(:"i18n-js",
89
154
  end
90
155
  ```
91
156
 
92
- If you files in a different location, the remember to configure file paths
157
+ If your files are located in a different path, remember to configure file paths
93
158
  accordingly.
94
159
 
95
160
  Now you can run `guard start -i`.
@@ -115,6 +180,31 @@ You're done exporting files, now what? Well, go to
115
180
  [i18n](https://github.com/fnando/i18n) to discover how to use the NPM package
116
181
  that loads all the exported translation.
117
182
 
183
+ ### FAQ
184
+
185
+ #### How can I export translations without having a database around?
186
+
187
+ Some people may have a build process using something like Docker that don't
188
+ necessarily have a database available. In this case, you may define your own
189
+ loading file by using something like
190
+ `i18n export --require ./config/i18n_export.rb`, where `i18n_export.rb` may look
191
+ like this:
192
+
193
+ ```ruby
194
+ # frozen_string_literal: true
195
+
196
+ require "bundler/setup"
197
+ require "rails"
198
+ require "active_support/railtie"
199
+ require "action_view/railtie"
200
+
201
+ I18n.load_path += Dir["./config/locales/**/*.yml"]
202
+ ```
203
+
204
+ Notice that you may not need to load ActiveSupport and ActionView lines, or even
205
+ may need to add additional requires for other libs. With this approach you have
206
+ full control on what's going to be loaded.
207
+
118
208
  ## Maintainer
119
209
 
120
210
  - [Nando Vieira](https://github.com/fnando)
data/i18njs.png ADDED
Binary file
@@ -23,7 +23,9 @@ module I18nJS
23
23
  end
24
24
 
25
25
  command do
26
- file_path = File.expand_path(options[:config_file])
26
+ file_path = File.expand_path(
27
+ options.fetch(:config_file, "config/i18n.yml")
28
+ )
27
29
 
28
30
  if File.file?(file_path)
29
31
  ui.fail_with("ERROR: #{file_path} already exists!")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module I18nJS
4
- VERSION = "4.0.0.alpha2"
4
+ VERSION = "4.0.0.alpha3"
5
5
  end
data/lib/i18n-js.rb CHANGED
@@ -44,8 +44,12 @@ module I18nJS
44
44
  def self.write_file(file_path, translations)
45
45
  FileUtils.mkdir_p(File.dirname(file_path))
46
46
 
47
+ contents = ::JSON.pretty_generate(translations)
48
+ digest = Digest::MD5.hexdigest(contents)
49
+ file_path = file_path.gsub(/:digest/, digest)
50
+
47
51
  File.open(file_path, "w") do |file|
48
- file << ::JSON.pretty_generate(translations)
52
+ file << contents
49
53
  end
50
54
  end
51
55
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-js
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.alpha2
4
+ version: 4.0.0.alpha3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-28 00:00:00.000000000 Z
11
+ date: 2022-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: glob
@@ -161,6 +161,7 @@ files:
161
161
  - ".github/CODEOWNERS"
162
162
  - ".github/FUNDING.yml"
163
163
  - ".github/ISSUE_TEMPLATE/bug_report.md"
164
+ - ".github/ISSUE_TEMPLATE/config.yml"
164
165
  - ".github/ISSUE_TEMPLATE/feature_request.md"
165
166
  - ".github/PULL_REQUEST_TEMPLATE.md"
166
167
  - ".github/dependabot.yml"
@@ -176,6 +177,7 @@ files:
176
177
  - Rakefile
177
178
  - exe/i18n
178
179
  - i18n-js.gemspec
180
+ - i18njs.png
179
181
  - lib/guard/i18n-js.rb
180
182
  - lib/guard/i18n-js/templates/Guardfile
181
183
  - lib/guard/i18n-js/version.rb
@@ -196,10 +198,10 @@ metadata:
196
198
  rubygems_mfa_required: 'true'
197
199
  homepage_uri: https://github.com/fnando/i18n-js
198
200
  bug_tracker_uri: https://github.com/fnando/i18n-js/issues
199
- source_code_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha2
200
- changelog_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha2/CHANGELOG.md
201
- documentation_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha2/README.md
202
- license_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha2/LICENSE.md
201
+ source_code_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha3
202
+ changelog_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha3/CHANGELOG.md
203
+ documentation_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha3/README.md
204
+ license_uri: https://github.com/fnando/i18n-js/tree/v4.0.0.alpha3/LICENSE.md
203
205
  post_install_message:
204
206
  rdoc_options: []
205
207
  require_paths:
@@ -215,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
217
  - !ruby/object:Gem::Version
216
218
  version: 1.3.1
217
219
  requirements: []
218
- rubygems_version: 3.2.32
220
+ rubygems_version: 3.3.17
219
221
  signing_key:
220
222
  specification_version: 4
221
223
  summary: Export i18n translations and use them on JavaScript.