Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2, rails 7.x support, only ruby 3.2+ #191

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test/dummy/tmp/
test/dummy/.sass-cache
.sass-cache/
/lit-*.gem
/*.json
**.DS_Store
Gemfile.lock
vendor/bundle
Expand Down
1 change: 0 additions & 1 deletion .ruby-gemset

This file was deleted.

2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.4
3.2.5
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
language: ruby
jobs:
exclude:
- rvm: 3.0.1
gemfile: gemfiles/rails_5.2.gemfile
# jobs:
# exclude:
# - rvm: 3.0.1
# gemfile: gemfiles/rails_5.2.gemfile
rvm:
- 2.7.3
- 3.0.1
- 3.2.5
- 3.3.3
gemfile:
- gemfiles/rails_5.2.gemfile
- gemfiles/rails_6.0.gemfile
- gemfiles/rails_6.1.gemfile
- gemfiles/rails_7.0.gemfile
- gemfiles/rails_7.1.gemfile
services:
- postgresql
- redis-server
Expand Down
99 changes: 42 additions & 57 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,62 +1,47 @@
appraise 'rails-5.2' do
appraise 'rails-7.0' do
source 'https://rubygems.org'
gem 'rails', '~> 5.2.0'
gem 'devise'
gem 'pg', '~> 1.2.3'
gem 'redis'
gem 'capybara'
gem 'database_cleaner'
gem 'test_declarative'
gem 'mocha'
gem 'webmock'
gem 'sass-rails'
gem 'jquery-rails'
gem 'coffee-rails'
gem 'pry-rails'
gem 'rails-controller-testing'
gem 'minitest'
gem 'm', '~> 1.5.0'
gem 'google-cloud-translate', '~> 1.2.4'
gem "rails", "~> 7.0.8.4"
gem "devise"
gem "pg", "~> 1.0"
gem "redis"
gem "capybara"
gem "database_cleaner"
gem "test_declarative"
gem "mocha"
gem "webmock"
gem "sass-rails"
gem "jquery-rails"
gem "coffee-rails"
gem "pry-rails"
gem "pry-stack_explorer"
gem "rails-controller-testing"
gem "minitest"
gem "minitest-vcr", github: "manuelvanrijn/minitest-vcr"
gem "m", "~> 1.6"
gem "google-cloud-translate", "~> 2.0"
gem "puma"
end

appraise 'rails-6.0' do
appraise 'rails-7.1' do
source 'https://rubygems.org'
gem 'rails', '~> 6.0.3'
gem 'devise'
gem 'pg', '~> 1.2.3'
gem 'redis'
gem 'capybara'
gem 'database_cleaner'
gem 'test_declarative'
gem 'mocha'
gem 'webmock'
gem 'sass-rails'
gem 'jquery-rails'
gem 'coffee-rails'
gem 'pry-rails'
gem 'rails-controller-testing'
gem 'minitest'
gem 'm', '~> 1.5.0'
gem 'google-cloud-translate', '~> 1.2.4'
end

appraise 'rails-6.1' do
source 'https://rubygems.org'
gem 'rails', '~> 6.1.4.1'
gem 'devise'
gem 'pg', '~> 1.2.3'
gem 'redis'
gem 'capybara'
gem 'database_cleaner'
gem 'test_declarative'
gem 'mocha'
gem 'webmock'
gem 'sass-rails'
gem 'jquery-rails'
gem 'coffee-rails'
gem 'pry-rails'
gem 'rails-controller-testing'
gem 'minitest'
gem 'm', '~> 1.5.0'
gem 'google-cloud-translate', '~> 2.1.2'
gem "rails", "~> 7.1.3.4"
gem "devise"
gem "pg", "~> 1.0"
gem "redis"
gem "capybara"
gem "database_cleaner"
gem "test_declarative"
gem "mocha"
gem "webmock"
gem "sass-rails"
gem "jquery-rails"
gem "coffee-rails"
gem "pry-rails"
gem "pry-stack_explorer"
gem "rails-controller-testing"
gem "minitest"
gem "minitest-vcr", github: "manuelvanrijn/minitest-vcr"
gem "m", "~> 1.6"
gem "google-cloud-translate", "~> 2.0"
gem "puma"
end
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased]

## [WIP]
- Defaults to ruby 3.2.5+
- Supports Rails 7.x only, drops support for older versions
- Efforts to use Vanilla JS and remove jQuery [WIP]
- Fix for `Undefined method 'id' for False class` error in view partial [WIP]
- REMOVED Lit.humanize_key - it's replaced by Lit.store_humanized_key variable

## [1.1.6] - 2022-03-28
### Fixed
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
### Rails i18n web interface

Translate your apps with pleasure (sort of...) and for free. It's simple i18n
web interface, build on top of twitter bootstrap, that one may find helpful in
web interface,that one may find helpful in
translating app by non-technicals.

Highly inspired by Copycopter by thoughtbot.
Expand Down Expand Up @@ -40,6 +40,10 @@ gem 'lit'

For Ruby < 1.9 use `gem 'lit', '= 0.2.4'`, as next versions introduced new ruby hash syntax.

For Ruby < 3.x use `gem 'lit', '< 2.0'`

Starting with version 2.x support for Rails < 7.0 and Ruby < 3.2.5 has been dropped.

2. run `bundle install`

3. Add `config.i18n.available_locales = [...]` to `application.rb` - it's required to precompile appropriate language flags in lit backend.
Expand All @@ -54,6 +58,8 @@ gem 'lit'

You may want to take a look at generated initializer in `config/initializers/lit.rb` and change some default configuration options.

Note `Lit.ignore_yaml_on_startup = true` setting - when it's set to true, Lit won't automatically import translations from yaml and add them to interface. Either change this to `false` or import using rake task

### So... again - what is it and how to use it?
*Lit* is Rails engine - it runs in it's own namespace, by default it's available under `/lit`. It provides UI for managing translations of your app.

Expand Down Expand Up @@ -133,10 +139,6 @@ Lit::CloudTranslation.provider = Lit::CloudTranslation::Providers::Google

...and make sure you have this in your Gemfile:
```
gem 'google-cloud-translate', '~> 1.2.4'
```
...we also support V2 of Google Cloud Translate gem, should you need it:
```
gem 'google-cloud-translate', '~> 2.1.2'
```

Expand Down Expand Up @@ -185,6 +187,12 @@ Lit::CloudTranslation.configure do |config|
end
```

### 1.x -> 2.0.x upgrade guide

Also applies to upgrading from `1.x` versions.

1. Specify `gem 'lit', '~> 2.0.0'` in your Gemfile and run `bundle update lit`.

### 0.3 -> 1.0 upgrade guide

Also applies to upgrading from `0.4.pre.alpha` versions.
Expand Down
28 changes: 15 additions & 13 deletions app/helpers/lit/frontend_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def pluralized_key(key, count)
pluralizer = I18n.backend.send(:pluralizer, locale)
return unless pluralizer.respond_to?(:call)
last = count.zero? ? :zero : pluralizer.call(count)
format '%<key>s.%<last>s', key: key, last: last
format "%<key>s.%<last>s", key: key, last: last
end

def t(key, options = {})
Expand All @@ -31,41 +31,43 @@ def missing_translation(key, options)
# Humanizing key should be last resort
if Lit::Services::HumanizeService.should_humanize?(key)
return Lit::Services::HumanizeService.humanize_and_cache(key, options)
else
return Lit::Services::HumanizeService.humanize(key)
end

super(key, options)
super
end
end
prepend Lit::FrontendHelper::TranslationKeyWrapper

def javascript_lit_tag
javascript_include_tag 'lit/lit_frontend', defer: true
javascript_include_tag "lit/lit_frontend", defer: true
end

def stylesheet_lit_tag
stylesheet_link_tag 'lit/lit_frontend'
stylesheet_link_tag "lit/lit_frontend"
end

def lit_frontend_assets
return unless lit_authorized?

meta = content_tag :meta, '', value: lit.find_localization_localization_keys_path, name: 'lit-url-base'
meta = content_tag :meta, "", value: lit.find_localization_localization_keys_path, name: "lit-url-base"
safe_join [javascript_lit_tag, stylesheet_lit_tag, meta]
end

def lit_translations_info
return if Thread.current[:lit_request_keys].nil?
return unless lit_authorized?

content_tag :div, class: 'lit-translations-info collapsed' do
concat content_tag(:span, 'Show translations', class: 'lit-open-button')
concat content_tag(:span, 'X', class: 'lit-close-button')
content_tag :div, class: "lit-translations-info collapsed" do
concat content_tag(:span, "Show translations", class: "lit-open-button")
concat content_tag(:span, "X", class: "lit-close-button")
concat translations_list_content_tag
end
end

def translations_list_content_tag
content_tag :ul, class: 'lit-translations-list' do
content_tag :ul, class: "lit-translations-list" do
Lit
.init
.cache
Expand All @@ -74,8 +76,8 @@ def translations_list_content_tag
concat(
content_tag(:li) do
concat content_tag(:code, "#{k}:")
concat get_translateable_span(k, v, alternative_text: '[empty]')
end,
concat get_translateable_span(k, v, alternative_text: "[empty]")
end
)
end
end
Expand All @@ -88,8 +90,8 @@ def lit_authorized?
end

def get_translateable_span(key, localization, alternative_text: nil)
content_tag :span, class: 'lit-key-generic', data: { key: key, locale: I18n.locale } do
localization.blank? ? alternative_text : localization
content_tag :span, class: "lit-key-generic", data: {key: key, locale: I18n.locale} do
localization.blank? ? alternative_text : localization.to_s
end
end
end
16 changes: 9 additions & 7 deletions app/models/lit/localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ class Localization < Lit::Base
scope :not_changed, -> { where is_changed: false }

# @HACK: dirty, find a way to round date to full second
scope :after, lambda { |dt| where('updated_at >= ?', dt + 1.second).where(is_changed: true) }
scope :active, lambda { joins(:localization_key).where(Lit::LocalizationKey.table_name => { is_deleted: false }) }
scope :after, ->(dt) { where("updated_at >= ?", dt + 1.second).where(is_changed: true) }
scope :active, -> { joins(:localization_key).where(Lit::LocalizationKey.table_name => {is_deleted: false}) }

## ASSOCIATIONS
belongs_to :locale, required: true
belongs_to :localization_key, touch: true, required: true
has_many :localization_versions, dependent: :destroy
has_many :versions, class_name: '::Lit::LocalizationVersion'
has_many :versions, class_name: "::Lit::LocalizationVersion"

## DELEGATIONS
delegate :is_deleted, to: :localization_key
Expand All @@ -39,11 +39,11 @@ def to_s
end

def full_key
full_key_str || [locale.locale, localization_key.localization_key].join('.')
full_key_str || [locale.locale, localization_key.localization_key].join(".")
end

def translation
is_changed? && !translated_value.nil? ? translated_value : default_value
(is_changed? && !translated_value.nil?) ? translated_value : default_value
end

def value
Expand All @@ -63,11 +63,12 @@ def locale_str
end

def last_change
updated_at.to_s(:db)
updated_at.to_fs(:db)
end

def update_default_value(value)
return true if persisted? && default_value == value

if persisted?
update(default_value: value)
else
Expand All @@ -84,8 +85,9 @@ def update_cache

def create_version
return if translated_value.blank?

translated_value = translated_value_was || default_value
localization_versions.new(translated_value: translated_value)
localization_versions.new(translated_value:)
end
end
end
Loading