Skip to content

Commit af70a78

Browse files
authored
Activate GitHub Actions and clean up the code (svenfuchs#124)
- Activate GitHub Actions - Clean up the code - Update the README
1 parent 772506c commit af70a78

19 files changed

+344
-367
lines changed

.github/workflows/test.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: CI Tests
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: ['**']
8+
9+
jobs:
10+
test:
11+
services:
12+
postgres:
13+
image: postgres
14+
env:
15+
POSTGRES_DB: i18n_unittest
16+
POSTGRES_PASSWORD: postgres
17+
ports:
18+
- 5432:5432
19+
options: >-
20+
--health-cmd pg_isready
21+
--health-interval 10s
22+
--health-timeout 5s
23+
--health-retries 5
24+
mysql:
25+
image: mysql:5.7
26+
env:
27+
MYSQL_DATABASE: i18n_unittest
28+
MYSQL_ALLOW_EMPTY_PASSWORD: true
29+
ports:
30+
- '3306:3306'
31+
options: >-
32+
--health-cmd="mysqladmin ping"
33+
--health-interval=10s
34+
--health-timeout=5s
35+
--health-retries=3
36+
strategy:
37+
fail-fast: true
38+
matrix:
39+
ruby: [2.4, 2.5, 2.6, 2.7, 3.0, 'head']
40+
rails: [4, 5, 6, 'head']
41+
exclude:
42+
- ruby: 2.4
43+
rails: 6
44+
- ruby: 2.4
45+
rails: head
46+
- ruby: 2.5
47+
rails: head
48+
- ruby: 2.6
49+
rails: head
50+
- ruby: 2.7
51+
rails: 4
52+
- ruby: 3.0
53+
rails: 4
54+
- ruby: 3.0
55+
rails: 5
56+
- ruby: head
57+
rails: 4
58+
- ruby: head
59+
rails: 5
60+
name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.rails }}'
61+
runs-on: ubuntu-latest
62+
env:
63+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile.rails_${{ matrix.rails }}
64+
steps:
65+
- uses: actions/checkout@v2
66+
- uses: ruby/setup-ruby@v1
67+
with:
68+
ruby-version: ${{ matrix.ruby }}
69+
bundler-cache: true
70+
cache-version: 1
71+
- name: Run tests for SQLite
72+
run: bundle exec rake
73+
- name: Run tests for PostgreSQL
74+
env:
75+
DB: postgres
76+
run: bundle exec rake
77+
- name: Run tests for MySQL
78+
env:
79+
DB: mysql
80+
run: bundle exec rake

.travis.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
i18n-active_record (0.4.0)
4+
i18n-active_record (0.4.1)
55
i18n (>= 0.5.0)
66

77
GEM
@@ -22,12 +22,12 @@ GEM
2222
i18n (1.8.10)
2323
concurrent-ruby (~> 1.0)
2424
minitest (5.14.4)
25-
mocha (1.12.0)
25+
mocha (1.13.0)
2626
mysql2 (0.5.3)
2727
pg (1.2.3)
28-
rake (13.0.3)
28+
rake (13.0.1)
2929
sqlite3 (1.4.2)
30-
test_declarative (0.0.6)
30+
test_declarative (0.0.5)
3131
tzinfo (2.0.4)
3232
concurrent-ruby (~> 1.0)
3333
zeitwerk (2.4.2)
@@ -48,4 +48,4 @@ DEPENDENCIES
4848
test_declarative
4949

5050
BUNDLED WITH
51-
2.1.4
51+
2.2.29

README.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# I18n::Backend::ActiveRecord
1+
# I18n::Backend::ActiveRecord ![Build Status](https://github.com/svenfuchs/i18n-active_record/actions/workflows/test.yml/badge.svg)
22

33
This repository contains the I18n ActiveRecord backend and support code that has been extracted from the "I18n": https://github.com/svenfuchs/i18n.
4-
It is fully compatible with Rails 3, 4, 5 and 6.
4+
It is fully compatible with Rails 4, 5 and 6.
55

66
## Installation
77

@@ -77,11 +77,37 @@ I18n::Backend::ActiveRecord.configure do |config|
7777
end
7878
```
7979

80+
To configure the ActiveRecord backend to cache translations(might be useful in production) use:
81+
82+
```ruby
83+
I18n::Backend::ActiveRecord.configure do |config|
84+
config.cache_translations = true # defaults to false
85+
end
86+
```
87+
8088
## Usage
8189

8290
You can now use `I18n.t('Your String')` to lookup translations in the database.
8391

84-
## Missing Translations -> Interpolations
92+
## Missing Translations
93+
94+
### Usage
95+
96+
In order to make the `I18n::Backend::ActiveRecord::Missing` module working correctly pluralization rules should be configured properly.
97+
The `i18n.plural.keys` translation key should be present in any of the backends.
98+
(See https://github.com/svenfuchs/i18n-active_record/blob/master/lib/i18n/backend/active_record/missing.rb for more information)
99+
100+
```yaml
101+
en:
102+
i18n:
103+
plural:
104+
keys:
105+
- :zero
106+
- :one
107+
- :other
108+
```
109+
110+
### Interpolations
85111
86112
The `interpolations` field in the `translations` table is used by `I18n::Backend::ActiveRecord::Missing` to store the interpolations seen the first time this Translation was requested. This will help translators understand what interpolations to expect, and thus to include when providing the translations.
87113

@@ -93,7 +119,20 @@ The `interpolations` field is otherwise unused since the "value" in `Translation
93119

94120
## Contributing
95121

96-
To run the test suite for all databases use `rake test` or using only SQLite with `rake sqlite:test`
122+
### Test suite
123+
124+
The test suite can be run with:
125+
126+
bundle exec rake
127+
128+
By default it runs the tests for SQLite database, to specify a database the `DB` env variable can be used:
129+
130+
DB=postgres bundle exec rake
131+
DB=mysql bundle exec rake
132+
133+
There are multiple gemfiles(mostly used for CI) and they can be activated with the `--gemfile` option:
134+
135+
bundle exec --gemfile gemfiles/Gemfile.rails_4 rake
97136

98137
## Maintainers
99138

Rakefile

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,9 @@
1-
require 'rake'
21
require 'rake/testtask'
3-
require 'bundler/gem_tasks'
42

5-
def execute(command)
6-
puts command
7-
system command
8-
end
9-
10-
def bundle_options
11-
return '' unless ENV['BUNDLE_GEMFILE']
12-
13-
"--gemfile #{ENV['BUNDLE_GEMFILE']}"
14-
end
15-
16-
def each_database(&block)
17-
['sqlite', 'postgres', 'mysql'].each &block
18-
end
19-
20-
namespace :bundle do
21-
task :env do
22-
ar = ENV['AR'].to_s
23-
24-
next if ar.empty?
25-
26-
gemfile = "gemfiles/Gemfile.rails_#{ar}"
27-
raise "Cannot find gemfile at #{gemfile}" unless File.exist?(gemfile)
28-
29-
ENV['BUNDLE_GEMFILE'] = gemfile
30-
puts "Using gemfile: #{gemfile}"
31-
end
32-
33-
task install: :env do
34-
execute "bundle install #{bundle_options}"
35-
end
36-
37-
task update: :env do
38-
execute "bundle update #{bundle_options}"
39-
end
40-
41-
task :install_all do
42-
[nil, '3', '4', '5', '6', 'head'].each do |ar|
43-
opt = ar && "AR=#{ar}"
44-
execute "rake bundle:install #{opt}"
45-
end
46-
end
47-
end
48-
49-
task :test do
50-
each_database { |db| execute "rake #{db}:test" }
51-
end
52-
53-
Rake::TestTask.new :_test do |t|
3+
Rake::TestTask.new :test do |t|
544
t.libs << 'test'
555
t.pattern = 'test/**/*_test.rb'
566
t.verbose = false
577
end
588

59-
each_database do |db|
60-
namespace db do
61-
task(:env) { ENV['DB'] = db }
62-
task test: ['env', 'bundle:env', '_test']
63-
end
64-
end
65-
669
task default: :test

gemfiles/Gemfile.rails_3

Lines changed: 0 additions & 13 deletions
This file was deleted.

gemfiles/Gemfile.rails_3.lock

Lines changed: 0 additions & 52 deletions
This file was deleted.

gemfiles/Gemfile.rails_4.lock

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
i18n-active_record (0.4.0)
4+
i18n-active_record (0.4.1)
55
i18n (>= 0.5.0)
66

77
GEM
@@ -22,11 +22,9 @@ GEM
2222
arel (6.0.4)
2323
builder (3.2.3)
2424
i18n (0.8.1)
25-
metaclass (0.0.4)
2625
minitest (5.10.1)
27-
mocha (1.2.1)
28-
metaclass (~> 0.0.1)
29-
mysql2 (0.4.5)
26+
mocha (1.13.0)
27+
mysql2 (0.4.10)
3028
pg (0.18.4)
3129
rake (13.0.1)
3230
sqlite3 (1.3.13)

0 commit comments

Comments
 (0)