Skip to content
Merged
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
18 changes: 6 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: CI

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -32,6 +32,9 @@ jobs:
- rails_7_1
- rails_7_2
- rails_main
exclude:
- ruby: "3.1"
gemfile: rails_main

services:
postgres:
Expand All @@ -57,8 +60,7 @@ jobs:
- name: Install packages
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y google-chrome-stable curl libjemalloc2 libsqlite3-0 libvips

- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -70,11 +72,3 @@ jobs:
run: |
bin/rails db:test:prepare
bin/rails test

- name: Keep screenshots from failed system tests
uses: actions/upload-artifact@v4
if: failure()
with:
name: screenshots
path: ${{ github.workspace }}/tmp/screenshots
if-no-files-found: ignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Locales::Translations::MissingController < Locales::TranslationsController
private

def scope
TranslationKey.with_missing_translation(@locale)
Locale.default_locale.text_entries.missing_translation(@locale)
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/rosetta/locales/translations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ class Locales::TranslationsController < ApplicationController
include LocaleScoped

def index
@pagy, @translation_keys = pagy(scope)
@pagy, @text_entries = pagy(scope)

render "rosetta/locales/translations/index"
end

private

def scope
TranslationKey.with_translation(@locale)
TextEntry.with_translated_version(@locale).where(locale: Locale.default_locale)
end
end
end
14 changes: 7 additions & 7 deletions app/controllers/rosetta/translations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ module Rosetta
class TranslationsController < ApplicationController
include LocaleScoped

before_action :set_translation_key
before_action :set_text_entry

def edit
end

def update
@translation_key.update(translation_key_params)
@text_entry.update(text_entry_params)

render partial: "rosetta/locales/translations/translation_key", locals: { translation_key: @translation_key }
render partial: "rosetta/text_entries/text_entry_with_translation", locals: { text_entry: @text_entry }
end

private

def set_translation_key
@translation_key = TranslationKey.find(params[:translation_key_id])
def set_text_entry
@text_entry = TextEntry.find(params[:text_entry_id])
end

def translation_key_params
params.require(:translation_key).permit(:"value_#{@locale.code}")
def text_entry_params
params.require(:text_entry).permit(:"content_#{@locale.code}")
end
end
end
4 changes: 2 additions & 2 deletions app/jobs/rosetta/autodiscovery_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class AutodiscoveryJob < Rosetta::ApplicationJob

discard_on ActiveRecord::RecordNotUnique

def perform(value)
TranslationKey.create!(value: value)
def perform(content)
TextEntry.create!(content: content, locale: Locale.default_locale)
end
end
end
11 changes: 11 additions & 0 deletions app/jobs/rosetta/purge_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Rosetta
class PurgeJob < Rosetta::ApplicationJob
queue_as { Rosetta.config.queues[:purge] }

discard_on ActiveRecord::RecordNotFound

def perform(text_entry)
text_entry.purge
end
end
end
3 changes: 1 addition & 2 deletions app/models/rosetta/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class Locale < ApplicationRecord
validates :code, uniqueness: true
validates :code, format: { with: CODE_FORMAT, message: "must only contain letters separated by an optional dash" }

has_many :translations, dependent: :destroy

has_many :text_entries, dependent: :destroy
after_create_commit :notify_translated_models

class << self
Expand Down
22 changes: 22 additions & 0 deletions app/models/rosetta/text_entry.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Rosetta
class TextEntry < ApplicationRecord
include Translated

translate_in_all_locales

belongs_to :locale

def self.create_later(content)
AutodiscoveryJob.perform_later(content)
end

def purge
destroy
rescue ActiveRecord::InvalidForeignKey
end

def purge_later
PurgeJob.perform_later(self)
end
end
end
13 changes: 11 additions & 2 deletions app/models/rosetta/translation.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
module Rosetta
class Translation < ApplicationRecord
belongs_to :locale, class_name: "Rosetta::Locale", inverse_of: :translations
belongs_to :translation_key, class_name: "Rosetta::TranslationKey", inverse_of: :translations
belongs_to :target_locale, class_name: "Rosetta::Locale"
belongs_to :from, class_name: "Rosetta::TextEntry"
belongs_to :to, class_name: "Rosetta::TextEntry"

after_destroy_commit :purge_orphaned_text_entries_later

private

def purge_orphaned_text_entries_later
to.purge_later
end
end
end
11 changes: 0 additions & 11 deletions app/models/rosetta/translation_key.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= tab_link_to locale_translations_missing_index_path(@locale) do %>
Missing
<span class="ml-3 hidden md:inline-block rounded-full px-2.5 py-0.5 text-xs font-medium bg-gray-100 text-gray-900 group-[.active]:bg-indigo-100 group-[.active]:text-indigo-600">
<%= Rosetta::TranslationKey.with_missing_translation(@locale).size %>
<%= Rosetta::TextEntry.where(locale: Rosetta::Locale.default_locale).missing_translation(@locale).size %>
</span>
<% end %>
</nav>
Expand Down
7 changes: 4 additions & 3 deletions app/views/rosetta/locales/translations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@
<table class="min-w-full divide-y divide-gray-300">
<thead class="bg-gray-50">
<tr class="divide-x divide-gray-200">
<th scope="col" class="w-1/2 py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6">Translation Key</th>
<th scope="col" class="w-1/2 py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6">Text Entry</th>
<th scope="col" class="w-1/2 px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Translation</th>
</tr>
</thead>

<tbody class="divide-y divide-gray-200 bg-white">
<%= render(
collection: @translation_keys,
partial: "rosetta/locales/translations/translation_key") %>
collection: @text_entries,
as: :text_entry,
partial: "rosetta/text_entries/text_entry_with_translation") %>
</tbody>
</table>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<tr class="divide-x divide-gray-200">
<td class="py-4 pl-4 pr-3 text-sm text-gray-900 sm:pl-6">
<%= translation_key.value %>
<%= text_entry.content %>
</td>
<td class="px-3 py-4 text-sm text-gray-900 group relative">
<%= turbo_frame_tag dom_id(translation_key) do %>
<%= translation_key.public_send("#{@locale.code}_translation")&.value %>
<%= turbo_frame_tag dom_id(text_entry) do %>
<%= text_entry.content_in(@locale) %>

<div class="hidden group-hover:flex absolute w-full h-full top-0 left-0 bg-indigo-50 bg-opacity-50 pr-4 items-center justify-end">
<%= link_to "edit", edit_translation_key_translation_path(translation_key, locale_id: @locale.id), class: "text-indigo-600 hover:text-indigo-900 font-medium" %>
<%= link_to "edit", edit_text_entry_translation_path(text_entry, locale_id: @locale.id), class: "text-indigo-600 hover:text-indigo-900 font-medium" %>
</div>
<% end %>
</td>
Expand Down
8 changes: 4 additions & 4 deletions app/views/rosetta/translations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%= turbo_frame_tag dom_id(@translation_key) do %>
<%= form_with model: @translation_key, url: translation_key_translation_path(@translation_key), method: :patch, class: "relative" do |f| %>
<%= turbo_frame_tag dom_id(@text_entry) do %>
<%= form_with model: @text_entry, url: text_entry_translation_path(@text_entry), method: :patch, class: "relative" do |f| %>
<%= hidden_field_tag :locale_id, @locale.id %>

<div class="overflow-hidden rounded-lg shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-indigo-600">
<%= f.label :"value_#{@locale.code}", "Translation", class: "sr-only" %>
<%= f.text_area :"value_#{@locale.code}", row: 3, autofocus: true, placeholder: "Enter your translation", class: "block w-full resize-none border-0 bg-transparent py-1.5 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6" %>
<%= f.label :"content_#{@locale.code}", "Translation", class: "sr-only" %>
<%= f.text_area :"content_#{@locale.code}", row: 3, autofocus: true, placeholder: "Enter your translation", class: "block w-full resize-none border-0 bg-transparent py-1.5 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6" %>

<div class="py-2" aria-hidden="true">
<div class="py-px">
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
end
end

resources :translation_keys do
resources :text_entries do
resource :translation, only: %i[edit update]
end
end
14 changes: 14 additions & 0 deletions db/migrate/20240930135507_create_rosetta_text_entries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateRosettaTextEntries < ActiveRecord::Migration[7.2]
def change
create_table :rosetta_text_entries do |t|
t.text :content, null: false
t.references :locale, null: false

t.timestamps

t.index :content
t.index [ :locale_id, :content ], unique: true
t.foreign_key :rosetta_locales, column: :locale_id
end
end
end
20 changes: 20 additions & 0 deletions db/migrate/20240930135810_update_rosetta_translations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class UpdateRosettaTranslations < ActiveRecord::Migration[7.2]
def change
change_table :rosetta_translations do |t|
t.remove :value

t.references :target_locale, null: false
t.references :from, null: false
t.references :to, null: false

t.foreign_key :rosetta_locales, column: :target_locale_id
t.foreign_key :rosetta_text_entries, column: :from_id
t.foreign_key :rosetta_text_entries, column: :to_id

t.index [ :target_locale_id, :from_id, :to_id ], name: :rosetta_translations_uniqueness, unique: true
end

remove_reference :rosetta_translations, :translation_key
remove_reference :rosetta_translations, :locale
end
end
5 changes: 5 additions & 0 deletions db/migrate/20241002152043_drop_translation_keys.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DropTranslationKeys < ActiveRecord::Migration[7.2]
def change
drop_table :rosetta_translation_keys
end
end
4 changes: 2 additions & 2 deletions gemfiles/rails_6_1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ GEM
rubocop-performance (1.22.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.26.1)
rubocop-rails (2.26.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
Expand All @@ -192,7 +192,7 @@ GEM
sprockets (>= 3.0.0)
thor (1.3.2)
timeout (0.4.1)
turbo-rails (2.0.9)
turbo-rails (2.0.10)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
Expand Down
4 changes: 2 additions & 2 deletions gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ GEM
rubocop-performance (1.22.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.26.1)
rubocop-rails (2.26.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
Expand All @@ -198,7 +198,7 @@ GEM
sprockets (>= 3.0.0)
thor (1.3.2)
timeout (0.4.1)
turbo-rails (2.0.9)
turbo-rails (2.0.10)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
Expand Down
8 changes: 4 additions & 4 deletions gemfiles/rails_7_1.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ GEM
i18n (1.14.6)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
irb (1.14.0)
irb (1.14.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.7.2)
Expand Down Expand Up @@ -207,7 +207,7 @@ GEM
rubocop-performance (1.22.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.26.1)
rubocop-rails (2.26.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
Expand All @@ -228,13 +228,13 @@ GEM
stringio (3.1.1)
thor (1.3.2)
timeout (0.4.1)
turbo-rails (2.0.9)
turbo-rails (2.0.10)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)
webrick (1.8.1)
webrick (1.8.2)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down
Loading