Skip to content

Commit

Permalink
Activate GitHub Actions and clean up the code (#124)
Browse files Browse the repository at this point in the history
- Activate GitHub Actions
- Clean up the code
- Update the README
  • Loading branch information
timfjord authored Oct 26, 2021
1 parent 772506c commit af70a78
Show file tree
Hide file tree
Showing 19 changed files with 344 additions and 367 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI Tests

on:
push:
branches: [master]
pull_request:
branches: ['**']

jobs:
test:
services:
postgres:
image: postgres
env:
POSTGRES_DB: i18n_unittest
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
mysql:
image: mysql:5.7
env:
MYSQL_DATABASE: i18n_unittest
MYSQL_ALLOW_EMPTY_PASSWORD: true
ports:
- '3306:3306'
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
strategy:
fail-fast: true
matrix:
ruby: [2.4, 2.5, 2.6, 2.7, 3.0, 'head']
rails: [4, 5, 6, 'head']
exclude:
- ruby: 2.4
rails: 6
- ruby: 2.4
rails: head
- ruby: 2.5
rails: head
- ruby: 2.6
rails: head
- ruby: 2.7
rails: 4
- ruby: 3.0
rails: 4
- ruby: 3.0
rails: 5
- ruby: head
rails: 4
- ruby: head
rails: 5
name: 'Ruby: ${{ matrix.ruby }}, Rails: ${{ matrix.rails }}'
runs-on: ubuntu-latest
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/Gemfile.rails_${{ matrix.rails }}
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
cache-version: 1
- name: Run tests for SQLite
run: bundle exec rake
- name: Run tests for PostgreSQL
env:
DB: postgres
run: bundle exec rake
- name: Run tests for MySQL
env:
DB: mysql
run: bundle exec rake
49 changes: 0 additions & 49 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
i18n-active_record (0.4.0)
i18n-active_record (0.4.1)
i18n (>= 0.5.0)

GEM
Expand All @@ -22,12 +22,12 @@ GEM
i18n (1.8.10)
concurrent-ruby (~> 1.0)
minitest (5.14.4)
mocha (1.12.0)
mocha (1.13.0)
mysql2 (0.5.3)
pg (1.2.3)
rake (13.0.3)
rake (13.0.1)
sqlite3 (1.4.2)
test_declarative (0.0.6)
test_declarative (0.0.5)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
zeitwerk (2.4.2)
Expand All @@ -48,4 +48,4 @@ DEPENDENCIES
test_declarative

BUNDLED WITH
2.1.4
2.2.29
47 changes: 43 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# I18n::Backend::ActiveRecord
# I18n::Backend::ActiveRecord ![Build Status](https://github.com/svenfuchs/i18n-active_record/actions/workflows/test.yml/badge.svg)

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

## Installation

Expand Down Expand Up @@ -77,11 +77,37 @@ I18n::Backend::ActiveRecord.configure do |config|
end
```

To configure the ActiveRecord backend to cache translations(might be useful in production) use:

```ruby
I18n::Backend::ActiveRecord.configure do |config|
config.cache_translations = true # defaults to false
end
```

## Usage

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

## Missing Translations -> Interpolations
## Missing Translations

### Usage

In order to make the `I18n::Backend::ActiveRecord::Missing` module working correctly pluralization rules should be configured properly.
The `i18n.plural.keys` translation key should be present in any of the backends.
(See https://github.com/svenfuchs/i18n-active_record/blob/master/lib/i18n/backend/active_record/missing.rb for more information)

```yaml
en:
i18n:
plural:
keys:
- :zero
- :one
- :other
```
### Interpolations
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.

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

## Contributing

To run the test suite for all databases use `rake test` or using only SQLite with `rake sqlite:test`
### Test suite

The test suite can be run with:

bundle exec rake

By default it runs the tests for SQLite database, to specify a database the `DB` env variable can be used:

DB=postgres bundle exec rake
DB=mysql bundle exec rake

There are multiple gemfiles(mostly used for CI) and they can be activated with the `--gemfile` option:

bundle exec --gemfile gemfiles/Gemfile.rails_4 rake

## Maintainers

Expand Down
59 changes: 1 addition & 58 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,66 +1,9 @@
require 'rake'
require 'rake/testtask'
require 'bundler/gem_tasks'

def execute(command)
puts command
system command
end

def bundle_options
return '' unless ENV['BUNDLE_GEMFILE']

"--gemfile #{ENV['BUNDLE_GEMFILE']}"
end

def each_database(&block)
['sqlite', 'postgres', 'mysql'].each &block
end

namespace :bundle do
task :env do
ar = ENV['AR'].to_s

next if ar.empty?

gemfile = "gemfiles/Gemfile.rails_#{ar}"
raise "Cannot find gemfile at #{gemfile}" unless File.exist?(gemfile)

ENV['BUNDLE_GEMFILE'] = gemfile
puts "Using gemfile: #{gemfile}"
end

task install: :env do
execute "bundle install #{bundle_options}"
end

task update: :env do
execute "bundle update #{bundle_options}"
end

task :install_all do
[nil, '3', '4', '5', '6', 'head'].each do |ar|
opt = ar && "AR=#{ar}"
execute "rake bundle:install #{opt}"
end
end
end

task :test do
each_database { |db| execute "rake #{db}:test" }
end

Rake::TestTask.new :_test do |t|
Rake::TestTask.new :test do |t|
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end

each_database do |db|
namespace db do
task(:env) { ENV['DB'] = db }
task test: ['env', 'bundle:env', '_test']
end
end

task default: :test
13 changes: 0 additions & 13 deletions gemfiles/Gemfile.rails_3

This file was deleted.

52 changes: 0 additions & 52 deletions gemfiles/Gemfile.rails_3.lock

This file was deleted.

8 changes: 3 additions & 5 deletions gemfiles/Gemfile.rails_4.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
i18n-active_record (0.4.0)
i18n-active_record (0.4.1)
i18n (>= 0.5.0)

GEM
Expand All @@ -22,11 +22,9 @@ GEM
arel (6.0.4)
builder (3.2.3)
i18n (0.8.1)
metaclass (0.0.4)
minitest (5.10.1)
mocha (1.2.1)
metaclass (~> 0.0.1)
mysql2 (0.4.5)
mocha (1.13.0)
mysql2 (0.4.10)
pg (0.18.4)
rake (13.0.1)
sqlite3 (1.3.13)
Expand Down
Loading

0 comments on commit af70a78

Please sign in to comment.