moirai 0.4.2 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1ccb1de7355ee89f7ab7c774ef50df313d18e76073cdfca05274c90ffc1b00e
4
- data.tar.gz: 2baade3d17dd785693a3770687bf16555624508936db76cc65346ad83f143319
3
+ metadata.gz: 47104e0b041ca51bf1ea9211f52cb8ccd362d5458903a734a6596189ed8da6d3
4
+ data.tar.gz: 1a183a9d886321f9930d921068741a78c358ea81846fe4355a7d1271aac315af
5
5
  SHA512:
6
- metadata.gz: 86aaf468fff8de8cdd1c0de8f3af40bccc4fab4ef14c752bea1773d5c5cb7dd3e0a2a1d89616c295265a1d9407398f3c7d31a5a6c8b04185358b02202cebf7c0
7
- data.tar.gz: d822eed2aae03aa6f1eaa4274d2a187d724125ab7b64b8dac6344b5235208ce5995e1703012d905d8384ec7634cb9d191ebd215266147437ab3962b263379bde
6
+ metadata.gz: 6d42da4c494dd4e9272014b54771dbc60297d019489ae44da09416820fc0f68a892508f991a8709a05f61bad09c4a77b5a5b6717d44d2605c0fb02b6990a2b39
7
+ data.tar.gz: f81cab05487087ecb4efa1b6c4b82b2e4ea3667d1bcb5a0e8654cb56c89e9e5e106685fbc912a208ec3be4d4d9c599c04d88ba01f86f3b4fc4538a09cb0d2400
data/CHANGELOG.md CHANGED
@@ -1,10 +1,18 @@
1
+ ## 0.4.4
2
+
3
+ * Allow to configure the root_path of moirai
4
+
5
+ ## 0.4.3
6
+
7
+ * Do not initialize moirai if we don't have a database connection. ([@coorasse][])
8
+
1
9
  ## 0.4.2
2
10
 
3
- * Fix bug when the params is defined but is `nil`
11
+ * Fix bug when the params is defined but is `nil`. ([@coorasse][])
4
12
 
5
13
  ## 0.4.1
6
14
 
7
- * Fix bug when the string is not a string, but a boolean
15
+ * Fix bug when the string is not a string, but a boolean. ([@coorasse][])
8
16
 
9
17
  ## 0.4.0 - Breaking Changes ⚠️
10
18
 
@@ -16,7 +24,7 @@ config.moirai.enable_inline_editing = ->(params:) { your_options_here }
16
24
 
17
25
  move in here the conditions you had previously defined in the helper.
18
26
 
19
- * Moirai now works also in emails. That's why we have a breaking change.
27
+ * Moirai now works also in emails. That's why we have a breaking change. ([@coorasse][])
20
28
 
21
29
  ## 0.3.1
22
30
 
data/README.md CHANGED
@@ -41,6 +41,15 @@ bin/rails db:migrate
41
41
 
42
42
  ## Usage
43
43
 
44
+ ### Mount path
45
+
46
+ By default, Moirai is mounted under `/moirai`. You can change it by specifying the `root_path` option in `config/initializers/moirai.rb`:
47
+
48
+ ```ruby
49
+ # config/initializers/moirai.rb
50
+ config.root_path = '/my_translations'
51
+ ```
52
+
44
53
  ### How to change translations
45
54
 
46
55
  If you mounted Moirai under "/moirai", head there and you will find a list of all the files containing texts that can be
@@ -104,12 +113,13 @@ Then run `bundle install`.
104
113
  You will need a Personal Access Token (PAT) with the `Content - Write` permission to allow Octokit to create branches
105
114
  and pull requests.
106
115
 
107
- - Go to GitHub Token Settings.
108
- - Click Generate New Token.
109
- - Give your token a name (e.g., “Moirai”).
110
- - Under Scopes, select:
111
- - repo (for full control of private repositories, including writing content).
112
- - content (for read/write access to code, commit statuses, and pull requests).
116
+ - Go to [GitHub Token Settings](https://github.com/settings/personal-access-tokens/).
117
+ - Click Generate New Token in Fine Grained Tokens.
118
+ - Give your token a name (e.g., "moirai").
119
+ - Under Repository Permissions, select:
120
+ - Actions - Read/Write
121
+ - Contents - Read/Write
122
+ - Pull Request - Read/Write
113
123
  - Generate the token and copy it immediately as it will be shown only once.
114
124
 
115
125
  #### 3. Set Up Environment Variables
@@ -2,6 +2,7 @@ import { Controller } from "@hotwired/stimulus"
2
2
 
3
3
  export default class MoiraiTranslationController extends Controller {
4
4
  static values = {
5
+ rootPath: { type: String, default: '/moirai' },
5
6
  key: String,
6
7
  locale: String
7
8
  }
@@ -13,7 +14,7 @@ export default class MoiraiTranslationController extends Controller {
13
14
  submit(event) {
14
15
  const csrfToken = document.querySelector('meta[name="csrf-token"]').content
15
16
 
16
- fetch('/moirai/translation_files', {
17
+ fetch(`${this.rootPathValue}/translation_files`, {
17
18
  method: 'POST',
18
19
  headers: {
19
20
  'X-CSRF-Token': csrfToken,
@@ -14,5 +14,10 @@ module Moirai
14
14
  key_finder = KeyFinder.new
15
15
  all.select { |translation| key_finder.file_paths_for(translation.key, locale: translation.locale).include?(file_path) }
16
16
  end
17
+
18
+ def in_sync_with_file?
19
+ translation_without_moirai = I18n.translate_without_moirai(key, locale)
20
+ translation_without_moirai.present? && translation_without_moirai == value
21
+ end
17
22
  end
18
23
  end
@@ -0,0 +1,15 @@
1
+ module Moirai
2
+ class TranslationSync
3
+ def initialize
4
+ @translations = Moirai::Translation.all
5
+ end
6
+
7
+ def synchronize
8
+ Rails.logger.info "Synchronizing translations..."
9
+ @translations.each do |translation|
10
+ translation.destroy if translation.in_sync_with_file?
11
+ end
12
+ Rails.logger.info "Synchronization complete."
13
+ end
14
+ end
15
+ end
@@ -1,9 +1,10 @@
1
- <span
1
+ <span
2
2
  contenteditable
3
3
  data-action="blur->moirai-translation#submit click->moirai-translation#click"
4
- style="outline: 1px solid #1d9f74; min-width: 30px; display: inline-block; <%= 'color: red;' if is_missing_translation %>"
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
- data-controller="moirai-translation">
7
+ data-controller="moirai-translation"
8
+ data-moirai-translation-root-path-value="<%= Moirai.configuration.root_path %>">
8
9
  <%= value.to_s.gsub("<", "&lt;").gsub(">", "&gt;").html_safe %>
9
10
  </span>
@@ -24,14 +24,17 @@ module Moirai
24
24
  end
25
25
  end
26
26
 
27
- private
28
-
29
27
  def using_js_bundling?
30
28
  Rails.root.join("app/javascript/controllers").exist?
31
29
  end
32
30
 
33
31
  def mount_engine
34
- route 'mount Moirai::Engine => "/moirai", as: "moirai"'
32
+ route "mount Moirai::Engine, at: Moirai.configuration.root_path, as: 'moirai'"
33
+ end
34
+
35
+ def add_initializer
36
+ say "Copying Moirai initializer"
37
+ template "initializers/moirai.tt", "config/initializers/moirai.rb"
35
38
  end
36
39
 
37
40
  private
@@ -0,0 +1,5 @@
1
+ # The values displayed here are the default ones. Change them to fit your needs.
2
+ Moirai.configure do |config|
3
+ ## == Routing ==
4
+ config.root_path = '/moirai'
5
+ end
@@ -8,6 +8,10 @@ module I18n
8
8
  def self.translate_without_moirai(key, locale, **)
9
9
  raise "Original backend is not set" unless original_backend
10
10
 
11
- original_backend.translate(locale, key, **)
11
+ begin
12
+ original_backend.translate(locale, key, **)
13
+ rescue
14
+ nil
15
+ end
12
16
  end
13
17
  end
@@ -0,0 +1,21 @@
1
+ module Moirai
2
+ class Configuration
3
+ attr_accessor :root_path
4
+
5
+ def initialize
6
+ @root_path = '/moirai'
7
+ end
8
+ end
9
+
10
+ def self.configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+
14
+ def self.configuration=(config)
15
+ @configuration = config
16
+ end
17
+
18
+ def self.configure
19
+ yield configuration
20
+ end
21
+ end
data/lib/moirai/engine.rb CHANGED
@@ -10,18 +10,27 @@ module Moirai
10
10
 
11
11
  config.moirai = ActiveSupport::OrderedOptions.new
12
12
 
13
+ def self.on_sqlite?
14
+ defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter) &&
15
+ ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::SQLite3Adapter)
16
+ end
17
+
18
+ def self.on_postgres?
19
+ ActiveRecord::Base.connection.table_exists?("moirai_translations")
20
+ end
21
+
13
22
  config.after_initialize do
14
23
  I18n.original_backend = I18n.backend
15
24
  table_created =
16
25
  begin
17
- (defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter) &&
18
- ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::SQLite3Adapter)) ||
19
- ActiveRecord::Base.connection.table_exists?("moirai_translations")
20
- rescue ActiveRecord::NoDatabaseError
26
+ on_sqlite? || on_postgres?
27
+ rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished
21
28
  false
22
29
  end
23
30
  if table_created
24
31
  I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Moirai.new, I18n.backend)
32
+ Rails.logger.info("moirai has been enabled.")
33
+ Moirai::TranslationSync.new.synchronize
25
34
  else
26
35
  Rails.logger.warn("moirai disabled: tables have not been generated yet.")
27
36
  end
@@ -38,5 +47,9 @@ module Moirai
38
47
  require "moirai/translation_helper"
39
48
  end
40
49
  end
50
+
51
+ initializer "moirai.assets" do |app|
52
+ app.config.assets.precompile += %w[moirai/application.css]
53
+ end
41
54
  end
42
55
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moirai
4
- VERSION = "0.4.2"
4
+ VERSION = "0.4.4"
5
5
  end
data/lib/moirai.rb CHANGED
@@ -4,6 +4,7 @@ require "moirai/version"
4
4
  require "i18n/extensions/i18n"
5
5
  require "i18n/backend/moirai"
6
6
  require "moirai/engine"
7
+ require "moirai/configuration"
7
8
  require "moirai/pull_request_creator"
8
9
 
9
10
  module Moirai
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.4.2
4
+ version: 0.4.4
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-26 00:00:00.000000000 Z
13
+ date: 2024-12-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -65,6 +65,7 @@ files:
65
65
  - app/models/moirai/translation.rb
66
66
  - app/models/moirai/translation_dumper.rb
67
67
  - app/models/moirai/translation_file_handler.rb
68
+ - app/models/moirai/translation_sync.rb
68
69
  - app/views/application_mailer/test.html.erb
69
70
  - app/views/layouts/moirai/application.html.erb
70
71
  - app/views/moirai/translation_files/_form.html.erb
@@ -80,10 +81,12 @@ files:
80
81
  - lib/generators/moirai/install_generator.rb
81
82
  - lib/generators/moirai/migration_generator.rb
82
83
  - lib/generators/moirai/templates/create_moirai_translations.rb.erb
84
+ - lib/generators/moirai/templates/initializers/moirai.tt
83
85
  - lib/generators/moirai/templates/make_moirai_translations_file_path_not_required.rb.erb
84
86
  - lib/i18n/backend/moirai.rb
85
87
  - lib/i18n/extensions/i18n.rb
86
88
  - lib/moirai.rb
89
+ - lib/moirai/configuration.rb
87
90
  - lib/moirai/engine.rb
88
91
  - lib/moirai/pull_request_creator.rb
89
92
  - lib/moirai/translation_helper.rb
@@ -98,7 +101,7 @@ metadata:
98
101
  changelog_uri: https://github.com/renuo/moirai/CHANGELOG.md
99
102
  steep_types: sig
100
103
  rubygems_mfa_required: 'true'
101
- post_install_message:
104
+ post_install_message:
102
105
  rdoc_options: []
103
106
  require_paths:
104
107
  - lib
@@ -113,8 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
116
  - !ruby/object:Gem::Version
114
117
  version: '0'
115
118
  requirements: []
116
- rubygems_version: 3.4.7
117
- signing_key:
119
+ rubygems_version: 3.5.22
120
+ signing_key:
118
121
  specification_version: 4
119
122
  summary: Manage translation strings in real time
120
123
  test_files: []