moirai 0.3.0 → 0.3.1

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: e9d7f98e48e08b3e5208041fbba3344f5b280492754b7943e159d0e90e71d075
4
- data.tar.gz: d4aa78c7ae9f0c27f18c3e760def299c5d8faf054b06423e300b2c095976ef0c
3
+ metadata.gz: ecb41a395f21cd347b67e6e0233bd776a80493be4bf98d423077b7fd7cbe2005
4
+ data.tar.gz: 1335f5ca28ab8804459172894841f71cb8ac88740ce0b94d21096bc3a1713386
5
5
  SHA512:
6
- metadata.gz: cb39e17d721373254b27086f4cf351c6145a3aa921809b8de0921ca82c661d53e0a1fb38da524c4fe012c2ecfcde7ffa2ec1029432e88d0cc43cf2f067c55341
7
- data.tar.gz: 601b7c5353bbc71cd094223df88b74dc9f82d07657f306f8402160bc47f4d056940a28db55b8b88f4fd2275c23e66379e2778e2856f0d93a57defd7b706dc68c
6
+ metadata.gz: 927bd40a31ce569fca7b6d6a68194106db7616bf3a733009dd84669a387450a4808bc650aeff8f7f1d6aefe630d859db0c0486972008189e183f957247fada80
7
+ data.tar.gz: c8a831cd233bf06ff6160acd096346afb3ab8b1209b3bda7a5a4c7ccbecffe263fadaffd4829508d5f13cb3f4201fdf3658ef46ddcb1ae14c16d46ca4c85c324
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.1
@@ -0,0 +1,18 @@
1
+ version: v1.0
2
+ name: main-deploy
3
+ agent:
4
+ machine:
5
+ type: e1-standard-2
6
+ os_image: ubuntu2004
7
+
8
+ blocks:
9
+ - name: main-deploy
10
+ task:
11
+ secrets:
12
+ - name: rubygems-deploy
13
+ jobs:
14
+ - name: main-deploy
15
+ commands:
16
+ - checkout --use-cache
17
+ - gem build moirai
18
+ - gem push moirai-*.gem
@@ -0,0 +1,50 @@
1
+ version: "v1.0"
2
+ name: moirai
3
+ agent:
4
+ machine:
5
+ type: e1-standard-2
6
+ os_image: ubuntu2004
7
+ auto_cancel:
8
+ running:
9
+ when: "true"
10
+
11
+ blocks:
12
+ - name: tests
13
+ execution_time_limit:
14
+ minutes: 10
15
+ task:
16
+ secrets:
17
+ - name: moirai
18
+ prologue:
19
+ commands:
20
+ - checkout --use-cache
21
+ - cache restore
22
+ - bundle config set path 'vendor/bundle'
23
+ - bundle install -j 4
24
+ - cache store
25
+ jobs:
26
+ - name: linter
27
+ commands:
28
+ - bundle exec standardrb
29
+ - name: tests sqlite
30
+ env_vars:
31
+ - name: TARGET_DB
32
+ value: sqlite
33
+ - name: RAILS_ENV
34
+ value: test
35
+ commands:
36
+ - bin/rails db:create db:schema:load
37
+ - bin/check
38
+ - name: tests postgres
39
+ env_vars:
40
+ - name: TARGET_DB
41
+ value: postgres
42
+ - name: RAILS_ENV
43
+ value: test
44
+ commands:
45
+ - sem-service start postgres 14 --username=semaphore
46
+ - bin/rails db:create db:schema:load
47
+ - bin/check
48
+ promotions:
49
+ - name: main
50
+ pipeline_file: main-deploy.yml
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.1
2
+
3
+ * Fixes a problem when running a rake command and no database exists yet using postgres. ([@coorasse][])
4
+
1
5
  ## 0.3.0
2
6
 
3
7
  * Added a method `I18n.translate_without_moirai` ([@oliveranthony17][])
@@ -5,6 +9,8 @@
5
9
  * Fixed some setup issues in test environments ([@oliveranthony17][])
6
10
  * Show original translation when deleting the whole inline editing content. ([@CuddlyBunion341][])
7
11
 
12
+ * Support for html translations ([@CuddlyBunion341][])
13
+ =======
8
14
  ## 0.2.0
9
15
 
10
16
  * Support for strings coming from gems ([@coorasse][])
data/Gemfile CHANGED
@@ -12,6 +12,7 @@ gem "stimulus-rails"
12
12
  group :development, :test do
13
13
  gem "puma"
14
14
  gem "sqlite3"
15
+ gem "pg"
15
16
  gem "rake"
16
17
  gem "dotenv"
17
18
  gem "minitest"
@@ -1,9 +1,9 @@
1
1
  <span
2
- contenteditable
2
+ contenteditable
3
3
  data-action="blur->moirai-translation#submit click->moirai-translation#click"
4
- style="border: 1px dashed #1d9f74; min-width: 30px; display: inline-block;"
4
+ style="outline: 1px solid #1d9f74; min-width: 30px; display: inline-block; <%= 'color: red;' if is_missing_translation %>"
5
5
  data-moirai-translation-key-value="<%= key %>"
6
6
  data-moirai-translation-locale-value="<%= locale %>"
7
7
  data-controller="moirai-translation">
8
- <%= value %>
8
+ <%= value.to_s.gsub("<", "&lt;").gsub(">", "&gt;").html_safe %>
9
9
  </span>
@@ -30,8 +30,7 @@
30
30
  method: :post do |f| %>
31
31
  <%= f.hidden_field :key %>
32
32
  <%= f.hidden_field :locale %>
33
- <%= f.text_area :value, class: 'translation-textarea' %>
34
- <%= f.submit 'Update', style: 'display: none;' %>
33
+ <%= f.text_field :value, class: 'translation-textarea' %>
35
34
  <% end %>
36
35
  </td>
37
36
  <td>
data/lib/moirai/engine.rb CHANGED
@@ -10,7 +10,15 @@ module Moirai
10
10
 
11
11
  config.after_initialize do
12
12
  I18n.original_backend = I18n.backend
13
- if ActiveRecord::Base.connection.data_source_exists?("moirai_translations") || ENV["RAILS_ENV"] == "test"
13
+ table_created =
14
+ begin
15
+ (defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter) &&
16
+ ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::SQLite3Adapter)) ||
17
+ ActiveRecord::Base.connection.table_exists?("moirai_translations")
18
+ rescue ActiveRecord::NoDatabaseError
19
+ false
20
+ end
21
+ if table_created
14
22
  I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Moirai.new, I18n.backend)
15
23
  else
16
24
  Rails.logger.warn("moirai disabled: tables have not been generated yet.")
@@ -27,12 +35,18 @@ module Moirai
27
35
  def translate(key, **options)
28
36
  value = original_translate(key, **options)
29
37
 
38
+ is_missing_translation = value.include?('class="translation_missing"')
39
+ if value.is_a?(String) && is_missing_translation
40
+ value = extract_inner_content(value)
41
+ end
42
+
30
43
  if moirai_edit_enabled?
31
44
  @key_finder ||= Moirai::KeyFinder.new
32
45
 
33
46
  render(partial: "moirai/translation_files/form",
34
47
  locals: {key: scope_key_by_partial(key),
35
48
  locale: I18n.locale,
49
+ is_missing_translation: is_missing_translation,
36
50
  value: value})
37
51
  else
38
52
  value
@@ -44,6 +58,13 @@ module Moirai
44
58
  def moirai_edit_enabled?
45
59
  params[:moirai] == "true"
46
60
  end
61
+
62
+ private
63
+
64
+ def extract_inner_content(html)
65
+ match = html.match(/<[^>]+>([^<]*)<\/[^>]+>/)
66
+ match ? match[1] : nil
67
+ end
47
68
  end
48
69
  end
49
70
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moirai
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moirai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi
8
8
  - Oliver Anthony
9
9
  - Daniel Bengl
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2024-11-22 00:00:00.000000000 Z
13
+ date: 2024-11-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -38,8 +38,10 @@ extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
40
  - ".github/CODEOWNERS"
41
- - ".github/workflows/test.yml"
42
41
  - ".gitignore"
42
+ - ".ruby-version"
43
+ - ".semaphore/main-deploy.yml"
44
+ - ".semaphore/semaphore.yml"
43
45
  - Appraisals
44
46
  - CHANGELOG.md
45
47
  - Gemfile
@@ -94,7 +96,7 @@ metadata:
94
96
  changelog_uri: https://github.com/renuo/moirai/CHANGELOG.md
95
97
  steep_types: sig
96
98
  rubygems_mfa_required: 'true'
97
- post_install_message:
99
+ post_install_message:
98
100
  rdoc_options: []
99
101
  require_paths:
100
102
  - lib
@@ -109,8 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
111
  - !ruby/object:Gem::Version
110
112
  version: '0'
111
113
  requirements: []
112
- rubygems_version: 3.5.22
113
- signing_key:
114
+ rubygems_version: 3.4.7
115
+ signing_key:
114
116
  specification_version: 4
115
117
  summary: Manage translation strings in real time
116
118
  test_files: []
@@ -1,65 +0,0 @@
1
- name: Test & lint
2
- on: [push]
3
-
4
- env:
5
- RAILS_ENV: test
6
- PGHOST: localhost
7
- PGUSER: postgres
8
- MOIRAI_GITHUB_REPO_NAME: ${{ secrets.MOIRAI_GITHUB_REPO_NAME }}
9
- MOIRAI_GITHUB_ACCESS_TOKEN: ${{ secrets.MOIRAI_GITHUB_ACCESS_TOKEN }}
10
- jobs:
11
- tests:
12
- name: Test
13
-
14
- strategy:
15
- fail-fast: false
16
- matrix:
17
- os: [ubuntu-latest]
18
- ruby: [3.3]
19
-
20
- runs-on: ${{ matrix.os }}
21
-
22
- steps:
23
- - name: Checkout code
24
- uses: actions/checkout@v4
25
-
26
- - name: Set up Ruby
27
- uses: ruby/setup-ruby@v1
28
- with:
29
- ruby-version: ${{ matrix.ruby }}
30
- bundler-cache: true
31
-
32
- - name: Install dependencies
33
- run: bundle install --jobs 4 --retry 3
34
-
35
- - name: Run tests
36
- run: bundle exec rails test
37
-
38
- - name: Run system tests
39
- run: bundle exec rails test:system
40
-
41
- - name: Archive logs
42
- if: always()
43
- uses: actions/upload-artifact@v4
44
- with:
45
- name: test.log
46
- path: test/dummy/log/test.log
47
- lint:
48
- name: Lint
49
- runs-on: ubuntu-latest
50
-
51
- steps:
52
- - name: Checkout code
53
- uses: actions/checkout@v2
54
-
55
- - name: Set up Ruby
56
- uses: ruby/setup-ruby@v1
57
- with:
58
- ruby-version: 3.3
59
- bundler-cache: true
60
-
61
- - name: Install dependencies
62
- run: bundle install --jobs 4 --retry 3
63
-
64
- - name: Run linters
65
- run: bin/fastcheck