lesli_babel 1.1.3 → 1.1.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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/lesli_babel/application.css +294 -23
  3. data/app/controllers/lesli_babel/application_controller.rb +14 -0
  4. data/app/controllers/lesli_babel/buckets_controller.rb +1 -7
  5. data/app/controllers/lesli_babel/labels_controller.rb +53 -35
  6. data/app/controllers/lesli_babel/translations_controller.rb +33 -43
  7. data/app/helpers/lesli_babel/labels_helper.rb +51 -2
  8. data/app/models/lesli_babel/application_record.rb +1 -1
  9. data/app/models/lesli_babel/label.rb +19 -2
  10. data/app/services/lesli_babel/label_service.rb +35 -6
  11. data/app/services/lesli_babel/translation_deploy_service.rb +144 -0
  12. data/app/services/lesli_babel/translation_export_service.rb +119 -0
  13. data/app/services/lesli_babel/translation_import_service.rb +184 -0
  14. data/app/services/lesli_babel/translation_service.rb +39 -151
  15. data/app/views/lesli_babel/dashboards/show.html.erb +62 -11
  16. data/app/views/lesli_babel/labels/_copy_path.html.erb +15 -0
  17. data/app/views/lesli_babel/labels/_delete_button.html.erb +14 -0
  18. data/app/views/lesli_babel/labels/_form.html.erb +56 -9
  19. data/app/views/lesli_babel/labels/_module_navigation.html.erb +15 -0
  20. data/app/views/lesli_babel/labels/index.html.erb +65 -36
  21. data/app/views/lesli_babel/labels/panel.html.erb +8 -0
  22. data/app/views/lesli_babel/labels/show.html.erb +10 -2
  23. data/app/views/lesli_babel/partials/_deploy_button.html.erb +21 -0
  24. data/config/locales/navigation.en.yml +5 -0
  25. data/config/locales/navigation.es.yml +5 -0
  26. data/config/locales/translations.en.yml +11 -1
  27. data/config/locales/translations.es.yml +11 -1
  28. data/config/locales/translations.fr.yml +2 -1
  29. data/config/locales/translations.it.yml +2 -1
  30. data/config/locales/translations.pt.yml +2 -1
  31. data/config/routes.rb +1 -2
  32. data/db/migrate/v1.0/0901100110_create_lesli_babel_modules.rb +6 -5
  33. data/db/migrate/v1.0/0901110110_create_lesli_babel_buckets.rb +7 -6
  34. data/db/migrate/v1.0/0901120110_create_lesli_babel_labels.rb +23 -22
  35. data/lib/lesli_babel/version.rb +2 -2
  36. data/lib/tasks/lesli_babel_tasks.rake +135 -83
  37. data/readme.md +4 -2
  38. metadata +12 -3
  39. data/app/views/lesli_babel/partials/_sidebar.html.erb +0 -45
@@ -0,0 +1,184 @@
1
+ require "yaml"
2
+
3
+ module LesliBabel
4
+ # Imports one YAML translation file into the Babel database.
5
+ #
6
+ # The expected hierarchy is locale -> module -> bucket -> label -> string.
7
+ # Every call validates the complete document before opening a transaction.
8
+ # Database writes for the file are atomic: if one record cannot be created,
9
+ # none of the records created by that import are persisted.
10
+ #
11
+ # @example
12
+ # LesliBabel::TranslationImportService.call(
13
+ # file_path: "/path/to/translations.en.yml",
14
+ # platform: "lesli_engine"
15
+ # )
16
+ class TranslationImportService
17
+ # Raised when a value does not match the expected YAML hierarchy.
18
+ class InvalidStructureError < StandardError; end
19
+
20
+ # @param file_path [String] absolute or relative path to the YAML file
21
+ # @param platform [String] platform assigned to every module in the file
22
+ # @return [Hash] structural errors found while validating the file
23
+ # @raise [Psych::Exception, SystemCallError] when the file cannot be loaded
24
+ def self.call(file_path:, platform:)
25
+ new(file_path: file_path, platform: platform).call
26
+ end
27
+
28
+ def initialize(file_path:, platform:)
29
+ @file_path = file_path
30
+ @platform = platform
31
+ end
32
+
33
+ def call
34
+ translations = load_yaml
35
+ errors = []
36
+ translations = validate_structure(translations, errors)
37
+
38
+ # Import the complete file in a single transaction
39
+ ApplicationRecord.transaction do
40
+ import_translations(translations)
41
+ end
42
+
43
+ { errors: errors }
44
+ end
45
+
46
+ private
47
+
48
+ attr_reader :file_path, :platform
49
+
50
+ def import_translations(translations)
51
+ # Iterate over every locale in the file
52
+ translations.each do |locale, modules|
53
+ modules.each do |module_code, buckets|
54
+
55
+ # Create the module if it does not exist
56
+ translation_module = Module.find_or_create_by!(
57
+ code: module_code,
58
+ platform: platform
59
+ )
60
+
61
+ # Iterate over the module buckets
62
+ buckets.each do |bucket_code, labels|
63
+
64
+ # Create the bucket if it does not exist
65
+ translation_bucket = translation_module.buckets
66
+ .create_with(reference_module: translation_module.code)
67
+ .find_or_create_by!(code: bucket_code)
68
+
69
+ # Iterate over the bucket labels
70
+ labels.each do |label, translation|
71
+
72
+ # Create the label if it does not exist
73
+ translation_label = translation_bucket.labels
74
+ .create_with(
75
+ locale => translation,
76
+ "last_update_#{locale}" => Time.current
77
+ )
78
+ .find_or_create_by!(text: label)
79
+ complete_translation(translation_label, locale, translation)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ # Complete an existing label only when its locale is empty
87
+ def complete_translation(translation_label, locale, translation)
88
+ return if translation_label.previously_new_record?
89
+ return if translation_label[locale].present?
90
+
91
+ translation_label.update!(
92
+ locale => translation,
93
+ "last_update_#{locale}" => Time.current
94
+ )
95
+ end
96
+
97
+ # Parser and filesystem exceptions intentionally propagate to the caller.
98
+ def load_yaml
99
+ YAML.safe_load_file(file_path, permitted_classes: [Symbol], aliases: false)
100
+ end
101
+
102
+ def validate_structure(translations, errors)
103
+ # Only validate the expected YAML hierarchy. Naming conventions and
104
+ # business rules belong to the importer, models, or database.
105
+ #
106
+ # locale:
107
+ # module:
108
+ # bucket:
109
+ # label: "translation"
110
+
111
+ # Without a root hash there are no independent branches that can be imported.
112
+ return {} unless valid_hash?(translations, [], "locales", errors)
113
+
114
+ # Build a clean copy instead of modifying the parsed YAML. Invalid branches
115
+ # are excluded from this hash while their valid siblings remain available.
116
+ valid_translations = {}
117
+
118
+ # A locale must contain a hash of modules. If it does not, reject only
119
+ # that locale and continue validating the remaining locales.
120
+ translations.each do |locale, modules|
121
+ next unless valid_hash?(modules, [locale], "modules", errors)
122
+
123
+ # Register the locale before traversing it so an empty locale remains valid.
124
+ valid_modules = {}
125
+ valid_translations[locale] = valid_modules
126
+
127
+ # A module must contain a hash of buckets.
128
+ modules.each do |module_code, buckets|
129
+ next unless valid_hash?(buckets, [locale, module_code], "buckets", errors)
130
+
131
+ # Preserve valid modules even when they do not define buckets.
132
+ valid_buckets = {}
133
+ valid_modules[module_code] = valid_buckets
134
+
135
+ # A bucket must contain a hash of labels.
136
+ buckets.each do |bucket_code, labels|
137
+ path = [locale, module_code, bucket_code]
138
+ next unless valid_hash?(labels, path, "labels", errors)
139
+
140
+ # Preserve valid buckets even when their label collection is empty.
141
+ valid_labels = {}
142
+ valid_buckets[bucket_code] = valid_labels
143
+
144
+ # Label values are the leaves of the supported hierarchy.
145
+ labels.each do |label, translation|
146
+ label_path = [locale, module_code, bucket_code, label]
147
+
148
+ if translation.is_a?(String)
149
+ # Only valid leaves are copied into the importable document.
150
+ valid_labels[label] = translation
151
+ else
152
+ # Reject the invalid label without discarding its siblings.
153
+ record_invalid_structure(errors, label_path, "string")
154
+ end
155
+ end
156
+ end
157
+ end
158
+ end
159
+
160
+ valid_translations
161
+ end
162
+
163
+ def valid_hash?(value, path, expected, errors)
164
+ # Returning a boolean lets each level decide which branch to skip.
165
+ return true if value.is_a?(Hash)
166
+
167
+ # The accumulated path identifies the exact level that cannot be traversed.
168
+ record_invalid_structure(errors, path, expected)
169
+ false
170
+ end
171
+
172
+ def record_invalid_structure(errors, path, expected)
173
+ # Root errors do not have YAML keys that can be joined into a path.
174
+ location = path.any? ? path.map(&:to_s).join(".") : "<root>"
175
+
176
+ # Record the error instead of raising it immediately so validation can
177
+ # discover other invalid branches and preserve every valid translation.
178
+ error = InvalidStructureError.new(
179
+ "Invalid translation structure at #{location}: expected #{expected}"
180
+ )
181
+ errors << error.message
182
+ end
183
+ end
184
+ end
@@ -1,167 +1,55 @@
1
1
  module LesliBabel
2
+ # Builds the translation statistics displayed by the Babel dashboard.
2
3
  class TranslationService < Lesli::ApplicationLesliService
3
4
 
4
5
  def stats
5
- Rails.cache.fetch(cache_key_for_account(__method__), expires_in: 1.hour) do
6
+ labels = LabelService.new(current_user, query).builder
7
+ label_count = labels.reselect(:id).count
6
8
 
7
- label_service = LabelService.new(current_user, query)
8
-
9
- # total translations registered in babel
10
- total_strings = label_service.builder.reselect(:id).count
11
-
12
- # total translations by language
13
- total_strings_translations = []
14
-
15
- Lesli.config.babel.dig(:locales).each do |locale_code, locale_name|
16
- total_strings_translations.push({
17
- code: locale_code,
18
- name: locale_name,
19
- total: label_service.builder
20
- .reselect(:id)
21
- .where.not(locale_code => [nil, ""])
22
- .count
23
- })
24
- end
25
-
26
- # total translations that needs help
27
- total_strings_waiting_for_help = 0#self.list.reselect(:id).where(:status => 1).count
28
-
29
- # total translations that needs translation
30
- total_strings_waiting_for_translation = 0 #self.list.reselect(:id).where(:status => 2).count
9
+ locales = Lesli.config.babel.fetch(:locales).map do |locale_code, locale_name|
10
+ completed = labels
11
+ .reselect(:id)
12
+ .where.not(locale_code => [nil, ""])
13
+ .count
31
14
 
32
15
  {
33
- total_strings: total_strings,
34
- total_strings_translations: total_strings_translations,
35
- total_strings_waiting_for_help: total_strings_waiting_for_help,
36
- total_strings_waiting_for_translation: total_strings_waiting_for_translation
16
+ code: locale_code,
17
+ name: locale_name,
18
+ completed: completed,
19
+ missing: label_count - completed,
20
+ coverage: coverage(completed, label_count)
37
21
  }
38
22
  end
39
- end
40
-
41
- def deploy
42
-
43
- LesliSystem.engines.each do |engine, engine_info|
44
-
45
- next if engine == "Root"
46
-
47
- # get all rails engines to buil
48
- engine_id = Module
49
- .where("platform in ('lesli_core', 'lesli_engine')")
50
- .where(:code => engine_info[:code])
51
- .pluck(:id)
52
-
53
- engine_id_lesli = Module
54
- .where("platform in ('lesli_core', 'lesli_engine')")
55
- .where(:code => "lesli")
56
- .pluck(:id)
57
-
58
- bucket_id_shared = Bucket
59
- .where(:code => "shared")
60
- .where(:module_id => engine_id_lesli)
61
- .pluck(:id)
62
-
63
- bucket_id_application = Bucket
64
- .where(:code => "application")
65
- .where(:module_id => engine_id_lesli)
66
- .pluck(:id)
67
-
68
- # get labels filtered by module (only rails translations)
69
- labels = LabelService.new(current_user, query).builder(modules_id:engine_id).order(created_at: :asc)
70
- labels_shared = LabelService.new(current_user, query).builder(modules_id:engine_id_lesli, buckets_id:bucket_id_shared).order(created_at: :asc)
71
- labels_application = LabelService.new(current_user, query).builder(modules_id:engine_id_lesli, buckets_id:bucket_id_application).order(created_at: :asc)
72
-
73
- translations = {}
74
-
75
- available_locales = I18n.available_locales
76
-
77
- # add key for every available language (required by i18n Rails gem)
78
- available_locales.each do |lang|
79
- translations[lang] = {
80
- :file => "",
81
- :labels => {}
82
- }
83
- end
84
-
85
- engine_code = engine_info[:code]
86
-
87
- available_locales.each do |lang|
88
-
89
- # translations path for lesli core
90
- translations[lang][:file] = "#{engine}::Engine".constantize.root.join(
91
- "config", "locales", "translations.#{lang}.yml"
92
- ).to_s
93
-
94
- # Create a collection of labels for the current module
95
- labels.each do |label|
96
-
97
- bucket_code = label[:bucket_code]
98
-
99
- unless translations[lang][:labels].has_key? engine_code
100
- translations[lang][:labels][engine_code] = { }
101
- end
102
23
 
103
- unless translations[lang][:labels][engine_code].has_key? bucket_code
104
- translations[lang][:labels][engine_code][bucket_code] = { }
105
- end
106
-
107
- # # send debug message for missing translations
108
- label[lang] = ":" + label.path + ":" if label[lang].blank?
109
-
110
- translations[lang][:labels][engine_code][bucket_code][label.text] = label[lang]
111
-
112
- end
113
-
114
- # Create a collection of labels for the shared labels of Lesli
115
- # labels_shared.each do |label|
116
-
117
- # unless translations[lang][:labels].has_key? "lesli"
118
- # translations[lang][:labels]["lesli"] = { }
119
- # end
120
-
121
- # unless translations[lang][:labels]["lesli"].has_key? "shared"
122
- # translations[lang][:labels]["lesli"]["shared"] = { }
123
- # end
124
-
125
- # # # send debug message for missing translations
126
- # label[lang] = ":" + label.path + ":" if label[lang].blank?
127
-
128
- # translations[lang][:labels]["lesli"]["shared"][label.text] = label[lang]
129
- # end
130
-
131
- # # Create a collection of labels for the application labels of Lesli
132
- # labels_application.each do |label|
133
-
134
- # unless translations[lang][:labels].has_key? "lesli"
135
- # translations[lang][:labels]["lesli"] = { }
136
- # end
137
-
138
- # unless translations[lang][:labels]["lesli"].has_key? "application"
139
- # translations[lang][:labels]["lesli"]["application"] = { }
140
- # end
141
-
142
- # # # send debug message for missing translations
143
- # label[lang] = ":" + label.path + ":" if label[lang].blank?
144
-
145
- # translations[lang][:labels]["lesli"]["application"][label.text] = label[lang]
146
- # end
147
-
148
- end
149
-
150
- translations.each do |lang, translations|
151
-
152
- # creates folder and subfolders
153
- FileUtils.makedirs(File.dirname(translations[:file]))
154
-
155
- # creates translation file for every available language
156
- translation_file = File.new(translations[:file], "w+")
24
+ completed_translations = locales.sum { |locale| locale[:completed] }
25
+ pending_translations = locales.sum { |locale| locale[:missing] }
26
+ status_counts = labels.reselect(:status).group(:status).count
27
+
28
+ {
29
+ total_labels: label_count,
30
+ locales: locales.sort_by { |locale| [locale[:coverage], locale[:name].to_s] },
31
+ summary: {
32
+ configured_locales: locales.size,
33
+ pending_translations: pending_translations,
34
+ coverage: coverage(
35
+ completed_translations,
36
+ completed_translations + pending_translations
37
+ )
38
+ },
39
+ attention: {
40
+ need_translation: status_counts.fetch("need_translation", 0),
41
+ need_help: status_counts.fetch("need_help", 0),
42
+ need_context: status_counts.fetch("need_context", 0)
43
+ }
44
+ }
45
+ end
157
46
 
158
- translation_file.write({ "#{lang}": translations[:labels] }.to_yaml)
47
+ private
159
48
 
160
- translation_file.close
49
+ def coverage(completed, total)
50
+ return 0 if total.zero?
161
51
 
162
- #L2.msg "file added: #{ translations[:file] }"
163
- end
164
- end
52
+ (completed * 100.0 / total).round
165
53
  end
166
54
  end
167
55
  end
@@ -1,26 +1,77 @@
1
1
 
2
2
  <%= render(LesliView::Layout::Container.new("babel-dashboard")) do %>
3
3
 
4
- <%= render(LesliView::Components::Header.new("Found #{@stats[:total_strings]} registered labels")) do %>
5
- <%= render(LesliView::Elements::Button.new('Deploy', solid:true, icon:'rocket_launch', url:deploy_translations_path, method: :post)) %>
4
+ <%= render(LesliView::Components::Header.new(
5
+ "Translations dashboard",
6
+ "Tracking #{@stats[:total_labels]} labels across #{@stats.dig(:summary, :configured_locales)} locales with #{@stats.dig(:summary, :coverage)}% global coverage."
7
+ )) do %>
8
+ <%= render(LesliView::Elements::Button.new(
9
+ "#{@stats.dig(:summary, :pending_translations)} pending translations",
10
+ solid: false,
11
+ icon: "translate",
12
+ url: labels_path(missing: true)
13
+ )) %>
14
+ <%= render "lesli_babel/partials/deploy_button" %>
6
15
  <% end %>
7
16
 
8
17
  <%= render(LesliView::Components::Toolbar.new) %>
9
18
 
19
+ <section class="grid gap-4 py-6 sm:grid-cols-2 lg:grid-cols-3" aria-label="Labels requiring attention">
20
+ <% {
21
+ "Need translation" => @stats.dig(:attention, :need_translation),
22
+ "Need help" => @stats.dig(:attention, :need_help),
23
+ "Need context" => @stats.dig(:attention, :need_context)
24
+ }.each do |label, total| %>
25
+ <article class="rounded-xl border border-slate-200 bg-white p-5 shadow-sm">
26
+ <p class="text-sm font-medium text-slate-600"><%= label %></p>
27
+ <p class="mt-2 text-3xl font-semibold tabular-nums text-slate-900"><%= total %></p>
28
+ </article>
29
+ <% end %>
30
+ </section>
31
+
10
32
  <section class="py-6 sm:py-8" aria-label="Translation status by locale">
11
- <div class="grid gap-5 sm:grid-cols-2 sm:gap-6 lg:grid-cols-3 xl:grid-cols-4">
12
- <% @stats[:total_strings_translations].each do |locale| %>
13
- <article class="flex flex-col items-center rounded-2xl border border-slate-200 bg-white p-5 text-center shadow-sm sm:p-6">
33
+ <div class="grid gap-5 sm:grid-cols-2 sm:gap-6 lg:grid-cols-3">
34
+ <% @stats[:locales].each do |locale| %>
35
+ <%= link_to labels_path(locale: locale[:code], missing: true),
36
+ class: "group flex flex-col items-center rounded-2xl border border-slate-200 bg-white p-5 text-center shadow-sm transition hover:border-sky-300 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-sky-600 focus-visible:ring-offset-2 sm:p-6",
37
+ aria: { label: "#{locale[:name]}: #{locale[:coverage]}% coverage, #{locale[:missing]} pending translations. View pending translations." },
38
+ data: { turbo_frame: "_top" } do %>
14
39
  <svg class="mb-3 h-12 w-16" aria-hidden="true">
15
40
  <use xlink:href="#locale-<%= locale[:code] %>"></use>
16
41
  </svg>
17
- <h2 class="text-lg font-semibold text-slate-900">
18
- <%= locale[:name] %>: <span class="tabular-nums"><%= locale[:total] %></span>
42
+ <h2 class="text-base font-medium text-slate-800">
43
+ <%= locale[:name] %>
19
44
  </h2>
20
- <p class="mt-1 text-sm text-slate-500">
21
- missing: <span class="tabular-nums"><%= @stats[:total_strings].to_i - locale[:total] %></span> translations
22
- </p>
23
- </article>
45
+ <dl class="mt-3 grid w-full grid-cols-2 gap-3 text-sm">
46
+ <div>
47
+ <dt class="text-slate-600">Translated</dt>
48
+ <dd class="font-semibold tabular-nums text-slate-900"><%= locale[:completed] %></dd>
49
+ </div>
50
+ <div>
51
+ <dt class="text-slate-600">Pending</dt>
52
+ <dd class="font-semibold tabular-nums text-slate-900"><%= locale[:missing] %></dd>
53
+ </div>
54
+ </dl>
55
+ <div class="mt-4 w-full">
56
+ <div class="mb-2 flex items-center justify-between text-xs font-medium text-slate-600">
57
+ <span>Coverage</span>
58
+ <span class="tabular-nums"><%= locale[:coverage] %>%</span>
59
+ </div>
60
+ <div
61
+ class="h-2 overflow-hidden rounded-full bg-slate-100"
62
+ role="progressbar"
63
+ aria-label="<%= locale[:name] %> coverage"
64
+ aria-valuemin="0"
65
+ aria-valuemax="100"
66
+ aria-valuenow="<%= locale[:coverage] %>"
67
+ aria-valuetext="<%= locale[:coverage] %>% coverage">
68
+ <div
69
+ class="h-full rounded-full bg-sky-600 transition-all"
70
+ style="width: <%= locale[:coverage] %>%">
71
+ </div>
72
+ </div>
73
+ </div>
74
+ <% end %>
24
75
  <% end %>
25
76
  </div>
26
77
  </section>
@@ -0,0 +1,15 @@
1
+ <span class="inline-flex max-w-full items-center gap-2" x-data="{ copied: false }">
2
+ <span class="sr-only">Translation path:</span>
3
+ <code class="min-w-0 break-all text-xs leading-5 text-slate-600" x-ref="path"><%= path %></code>
4
+ <button
5
+ type="button"
6
+ class="inline-flex size-8 shrink-0 items-center justify-center rounded-lg text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-700 focus-visible:outline-none focus-visible:ring-4 focus-visible:ring-sky-500/20"
7
+ :aria-label="copied ? 'Path copied' : 'Copy path'"
8
+ @click="
9
+ navigator.clipboard.writeText($refs.path.innerText.trim());
10
+ copied = true;
11
+ setTimeout(() => copied = false, 2000)
12
+ ">
13
+ <span class="material-symbols text-lg leading-none" x-text="copied ? 'check' : 'content_copy'" aria-hidden="true"></span>
14
+ </button>
15
+ </span>
@@ -0,0 +1,14 @@
1
+ <div class="mt-6 border-t border-slate-200 pt-6">
2
+ <%= render(LesliView::Elements::Button.new(
3
+ "Delete translation",
4
+ url: label_path(@label),
5
+ method: :delete,
6
+ icon: "delete",
7
+ danger: true,
8
+ solid: false,
9
+ data: {
10
+ turbo_confirm: "Permanently delete this translation? This action cannot be undone.",
11
+ turbo_submits_with: "Deleting..."
12
+ }
13
+ )) %>
14
+ </div>
@@ -5,31 +5,78 @@
5
5
  builder: LesliView::Forms::BuilderHorizontal
6
6
  ) do |form| %>
7
7
 
8
- <% label_status = 'Label ' + @label.status.humanize.downcase if @label.status %>
9
- <% label_category = '' + @label.category if @label.category %>
8
+ <% form.fieldset("", { class: label_status_border_class(@label.status) }) do %>
10
9
 
11
- <% form.fieldset(label_status, category:label_category) do %>
10
+ <% unless @label.new_record? %>
11
+ <div class="mb-6 flex flex-wrap items-center justify-end gap-x-5 gap-y-2 text-sm text-slate-600" aria-label="Translation label metadata">
12
+ <span class="<%= label_status_badge_classes(@label.status) %>" data-label-status="<%= @label.status %>">
13
+ <%= label_status_name(@label.status) %>
14
+ </span>
15
+ <span>
16
+ <span class="text-slate-400">Module</span>
17
+ <strong class="ml-1 font-medium text-slate-700"><%= @label.translation_module_code.titleize %></strong>
18
+ </span>
19
+ <span>
20
+ <span class="text-slate-400">Bucket</span>
21
+ <strong class="ml-1 font-medium text-slate-700"><%= @label.translation_bucket_code.titleize %></strong>
22
+ </span>
23
+ </div>
24
+
25
+ <% missing_languages = missing_translation_languages(@label) %>
26
+ <% if missing_languages.any? %>
27
+ <div class="mb-6 rounded-xl border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900" role="status" aria-label="Missing translation languages">
28
+ <p class="font-semibold">Missing translations</p>
29
+ <p class="mt-1"><%= missing_languages.to_sentence %></p>
30
+ </div>
31
+ <% end %>
32
+
33
+ <% if @label.need_context? && @label.context.blank? %>
34
+ <div class="mb-6 rounded-xl border border-sky-200 bg-sky-50 p-4 text-sm text-sky-900" role="alert">
35
+ <p class="font-semibold">Context required</p>
36
+ <p class="mt-1">This label is marked Need context, but no context has been provided.</p>
37
+ </div>
38
+ <% end %>
39
+ <% end %>
40
+
41
+ <% if @label.errors.any? %>
42
+ <div class="mb-6 rounded-xl border border-rose-200 bg-rose-50 p-4 text-sm text-rose-800" role="alert">
43
+ <p class="font-semibold">Translation label could not be updated.</p>
44
+ <ul class="mt-2 list-disc space-y-1 pl-5">
45
+ <% @label.errors.full_messages.each do |message| %>
46
+ <li><%= message %></li>
47
+ <% end %>
48
+ </ul>
49
+ </div>
50
+ <% end %>
12
51
 
13
52
  <% if @label.new_record? %>
14
53
  <%= form.field_control_select(:bucket_id, @module.buckets.order(:code).pluck(:code, :id)) %>
15
54
  <%= form.field_control_select(:prefix, LesliBabel::Label.prefixes) %>
16
55
  <%= form.field_control(:text) %>
17
- <%= form.field_control(:context) %>
56
+ <%= form.field_control_textarea(:context, rows: 3, class: "!min-h-0") %>
18
57
  <% end %>
19
58
 
20
59
  <% unless @label.new_record? %>
21
- <% I18n.available_locales.each do |locale| %>
22
- <%= form.field_control(locale, label:language_name(locale)) %>
60
+ <% babel_locales.each do |locale, language| %>
61
+ <% missing_translation = @label.public_send(locale).blank? %>
62
+ <%= form.field_control_textarea(
63
+ locale,
64
+ label: language,
65
+ message: translation_field_message(@label, locale),
66
+ category: ("warning" if missing_translation),
67
+ rows: 3,
68
+ class: "!min-h-0",
69
+ placeholder: ("Missing translation" if missing_translation)
70
+ ) %>
23
71
  <% end %>
24
72
  <hr class="my-6 border-0 border-t border-slate-200">
25
- <%= form.field_control(:context) %>
73
+ <%= form.field_control_textarea(:context, rows: 3, class: "!min-h-0") %>
26
74
  <%= form.field_control_select(:status, LesliBabel::Label.statuses) %>
27
- <%= form.field_control(:path) unless @label[:path].blank? %>
28
75
  <% end %>
29
76
 
30
77
  <hr class="my-6 border-0 border-t border-slate-200">
31
78
 
32
- <%= form.field_control_button("Update", icon:"save") %>
79
+ <%= form.field_control_button("Save translations", icon: "save") %>
33
80
 
34
81
  <% end %>
35
82
  <% end %>
@@ -0,0 +1,15 @@
1
+ <%
2
+ selected_module_id = @module&.id || @label&.engine_id || params[:modules_id].presence&.to_i
3
+ items = LesliBabel::Module.order(:code).map do |engine|
4
+ {
5
+ label: engine.code.titleize,
6
+ path: module_path(engine),
7
+ selected: selected_module_id == engine.id
8
+ }
9
+ end
10
+ %>
11
+ <%= render LesliView::Layout::NavigationSidebar.new(
12
+ items: items,
13
+ label: t("lesli_babel.navigation.modules"),
14
+ empty_selection_label: t("lesli_babel.navigation.all_modules")
15
+ ) %>