moirai 0.4.3 → 0.4.4

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: e417177bded1e57fa207b75a86d1b26c7b0d39aa6800b43a7d8a4c15d2926a86
4
- data.tar.gz: 248a19eaa9ab8eb10113be5166ae7f327f6c368cfaedd323c16296d187d2c35c
3
+ metadata.gz: 47104e0b041ca51bf1ea9211f52cb8ccd362d5458903a734a6596189ed8da6d3
4
+ data.tar.gz: 1a183a9d886321f9930d921068741a78c358ea81846fe4355a7d1271aac315af
5
5
  SHA512:
6
- metadata.gz: bb076f72b6715f531af179c2a76802761a2e656e1cec4e27afe7d8bd6c6bda25835b689941eb450c4a5fa1a3b8aed21f624e7cc416873af6333b284191c4139e
7
- data.tar.gz: dc1cf7853270e580be8af708a3c4e21ad43efcc63a3a1301d28268af82d4933c07d10969f464bf049f07af328254b0036e1af6540425d2ea7d67e4f32be60802
6
+ metadata.gz: 6d42da4c494dd4e9272014b54771dbc60297d019489ae44da09416820fc0f68a892508f991a8709a05f61bad09c4a77b5a5b6717d44d2605c0fb02b6990a2b39
7
+ data.tar.gz: f81cab05487087ecb4efa1b6c4b82b2e4ea3667d1bcb5a0e8654cb56c89e9e5e106685fbc912a208ec3be4d4d9c599c04d88ba01f86f3b4fc4538a09cb0d2400
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.4.4
2
+
3
+ * Allow to configure the root_path of moirai
4
+
1
5
  ## 0.4.3
2
6
 
3
7
  * Do not initialize moirai if we don't have a database connection. ([@coorasse][])
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
@@ -30,6 +30,7 @@ module Moirai
30
30
  if table_created
31
31
  I18n.backend = I18n::Backend::Chain.new(I18n::Backend::Moirai.new, I18n.backend)
32
32
  Rails.logger.info("moirai has been enabled.")
33
+ Moirai::TranslationSync.new.synchronize
33
34
  else
34
35
  Rails.logger.warn("moirai disabled: tables have not been generated yet.")
35
36
  end
@@ -46,5 +47,9 @@ module Moirai
46
47
  require "moirai/translation_helper"
47
48
  end
48
49
  end
50
+
51
+ initializer "moirai.assets" do |app|
52
+ app.config.assets.precompile += %w[moirai/application.css]
53
+ end
49
54
  end
50
55
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moirai
4
- VERSION = "0.4.3"
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.3
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-28 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: []