lesli_babel 1.1.2 → 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.
- checksums.yaml +4 -4
- data/Rakefile +3 -0
- data/app/assets/stylesheets/lesli_babel/application.css +652 -34
- data/app/controllers/lesli_babel/application_controller.rb +14 -0
- data/app/controllers/lesli_babel/buckets_controller.rb +1 -7
- data/app/controllers/lesli_babel/labels_controller.rb +53 -35
- data/app/controllers/lesli_babel/translations_controller.rb +33 -43
- data/app/helpers/lesli_babel/labels_helper.rb +51 -2
- data/app/models/lesli_babel/application_record.rb +1 -1
- data/app/models/lesli_babel/label.rb +19 -2
- data/app/services/lesli_babel/label_service.rb +35 -6
- data/app/services/lesli_babel/translation_deploy_service.rb +144 -0
- data/app/services/lesli_babel/translation_export_service.rb +119 -0
- data/app/services/lesli_babel/translation_import_service.rb +184 -0
- data/app/services/lesli_babel/translation_service.rb +39 -148
- data/app/views/lesli_babel/dashboards/show.html.erb +62 -11
- data/app/views/lesli_babel/labels/_copy_path.html.erb +15 -0
- data/app/views/lesli_babel/labels/_delete_button.html.erb +14 -0
- data/app/views/lesli_babel/labels/_form.html.erb +56 -9
- data/app/views/lesli_babel/labels/_module_navigation.html.erb +15 -0
- data/app/views/lesli_babel/labels/index.html.erb +65 -36
- data/app/views/lesli_babel/labels/panel.html.erb +8 -0
- data/app/views/lesli_babel/labels/show.html.erb +10 -2
- data/app/views/lesli_babel/partials/_deploy_button.html.erb +21 -0
- data/config/locales/navigation.en.yml +5 -0
- data/config/locales/navigation.es.yml +5 -0
- data/config/locales/translations.en.yml +11 -1
- data/config/locales/translations.es.yml +11 -1
- data/config/locales/translations.fr.yml +2 -1
- data/config/locales/translations.it.yml +2 -1
- data/config/locales/translations.pt.yml +2 -1
- data/config/routes.rb +1 -2
- data/db/migrate/v1.0/0901100110_create_lesli_babel_modules.rb +6 -5
- data/db/migrate/v1.0/0901110110_create_lesli_babel_buckets.rb +7 -6
- data/db/migrate/v1.0/0901120110_create_lesli_babel_labels.rb +23 -22
- data/lib/lesli_babel/engine.rb +0 -4
- data/lib/lesli_babel/version.rb +2 -2
- data/lib/tasks/lesli_babel_tasks.rake +135 -83
- data/readme.md +8 -6
- metadata +16 -6
- data/app/assets/config/lesli_babel_manifest.js +0 -7
- data/app/assets/stylesheets/lesli_babel/application.tailwind.css +0 -2
- data/app/views/lesli_babel/partials/_sidebar.html.erb +0 -45
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
|
|
3
|
+
module LesliBabel
|
|
4
|
+
# Builds one locale YAML document without writing to the filesystem.
|
|
5
|
+
#
|
|
6
|
+
# The generated hierarchy is locale -> module -> bucket -> label -> string.
|
|
7
|
+
# The engine metadata provides the owning module code and expected locale
|
|
8
|
+
# directory. Every call builds the complete document in memory.
|
|
9
|
+
#
|
|
10
|
+
# @example
|
|
11
|
+
# LesliBabel::TranslationExportService.call(
|
|
12
|
+
# engine: LesliSystem.engine("LesliBabel"),
|
|
13
|
+
# platform: "lesli_engine",
|
|
14
|
+
# locale: :en
|
|
15
|
+
# )
|
|
16
|
+
class TranslationExportService
|
|
17
|
+
# @param engine [Hash] engine metadata containing code and dir
|
|
18
|
+
# @param platform [String] platform used to identify the owning module
|
|
19
|
+
# @param locale [String, Symbol] locale column and YAML root
|
|
20
|
+
# @return [Hash] expected file_path and serialized YAML content
|
|
21
|
+
# @raise [ActiveRecord::RecordNotFound] when the owning module does not exist
|
|
22
|
+
def self.call(engine:, platform:, locale:)
|
|
23
|
+
new(engine: engine, platform: platform, locale: locale).call
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def initialize(engine:, platform:, locale:)
|
|
27
|
+
@engine = engine
|
|
28
|
+
@platform = platform
|
|
29
|
+
@locale = locale.to_s
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def call
|
|
33
|
+
# Export only the module owned by the requested engine and platform
|
|
34
|
+
translation_module = Module.find_by(
|
|
35
|
+
code: engine.fetch(:code),
|
|
36
|
+
platform: platform
|
|
37
|
+
)
|
|
38
|
+
unless translation_module
|
|
39
|
+
raise ActiveRecord::RecordNotFound,
|
|
40
|
+
"Translation module not found: code=#{engine.fetch(:code)}, platform=#{platform}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Return the expected destination and content without writing the file
|
|
44
|
+
{
|
|
45
|
+
file_path: translation_file_path,
|
|
46
|
+
content: serialize(build_document(translation_module))
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
attr_reader :engine, :platform, :locale
|
|
53
|
+
|
|
54
|
+
# Build the official locale path inside the owning package
|
|
55
|
+
def translation_file_path
|
|
56
|
+
File.join(
|
|
57
|
+
engine.fetch(:dir),
|
|
58
|
+
"config",
|
|
59
|
+
"locales",
|
|
60
|
+
"translations.#{locale}.yml"
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def build_document(translation_module)
|
|
65
|
+
# Build buckets in code order for deterministic YAML output
|
|
66
|
+
buckets = {}
|
|
67
|
+
|
|
68
|
+
translation_module.buckets.order(:code).each do |bucket|
|
|
69
|
+
labels = {}
|
|
70
|
+
|
|
71
|
+
bucket.labels.order(:text).each do |label|
|
|
72
|
+
|
|
73
|
+
# Build labels in text order and keep every key as a string
|
|
74
|
+
labels[label.text.to_s] = translation_value(translation_module, bucket, label)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
buckets[bucket.code.to_s] = labels
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Use string keys for the locale and module roots
|
|
81
|
+
{
|
|
82
|
+
locale => {
|
|
83
|
+
translation_module.code.to_s => buckets
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def translation_value(translation_module, bucket, label)
|
|
89
|
+
value = label[locale]
|
|
90
|
+
return value if value.present?
|
|
91
|
+
|
|
92
|
+
# Represent missing values with their complete translation path
|
|
93
|
+
":#{translation_module.code}.#{bucket.code}.#{label.text}:"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# Quote every translation value while keeping locale, module, bucket,
|
|
97
|
+
# and label keys as plain strings. This preserves interpolation tokens
|
|
98
|
+
# and prevents YAML punctuation from changing a value's scalar type.
|
|
99
|
+
def serialize(document)
|
|
100
|
+
stream = Psych.parse_stream(document.to_yaml)
|
|
101
|
+
quote_values(stream.children.first.root)
|
|
102
|
+
stream.to_yaml(nil, line_width: -1)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def quote_values(node, depth = 0)
|
|
106
|
+
return unless node.is_a?(Psych::Nodes::Mapping)
|
|
107
|
+
|
|
108
|
+
node.children.each_slice(2) do |_key, value|
|
|
109
|
+
if depth == 3 && value.is_a?(Psych::Nodes::Scalar)
|
|
110
|
+
value.style = Psych::Nodes::Scalar::DOUBLE_QUOTED
|
|
111
|
+
value.plain = false
|
|
112
|
+
value.quoted = true
|
|
113
|
+
else
|
|
114
|
+
quote_values(value, depth + 1)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
@@ -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,164 +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
|
-
|
|
6
|
+
labels = LabelService.new(current_user, query).builder
|
|
7
|
+
label_count = labels.reselect(:id).count
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# total translations by language
|
|
13
|
-
total_strings_translations = []
|
|
14
|
-
|
|
15
|
-
Lesli.config.babel.dig(:locales).each do |locale|
|
|
16
|
-
total_strings_translations.push({
|
|
17
|
-
code: locale[0],
|
|
18
|
-
name: locale[1],
|
|
19
|
-
total: label_service.builder.reselect(:id).where("#{locale[0]} is not null").where("#{locale[0]} != ''").count
|
|
20
|
-
})
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# total translations that needs help
|
|
24
|
-
total_strings_waiting_for_help = 0#self.list.reselect(:id).where(:status => 1).count
|
|
25
|
-
|
|
26
|
-
# total translations that needs translation
|
|
27
|
-
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
|
|
28
14
|
|
|
29
15
|
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
code: locale_code,
|
|
17
|
+
name: locale_name,
|
|
18
|
+
completed: completed,
|
|
19
|
+
missing: label_count - completed,
|
|
20
|
+
coverage: coverage(completed, label_count)
|
|
34
21
|
}
|
|
35
22
|
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def deploy
|
|
39
|
-
|
|
40
|
-
LesliSystem.engines.each do |engine, engine_info|
|
|
41
|
-
|
|
42
|
-
next if engine == "Root"
|
|
43
|
-
|
|
44
|
-
# get all rails engines to buil
|
|
45
|
-
engine_id = Module
|
|
46
|
-
.where("platform in ('lesli_core', 'lesli_engine')")
|
|
47
|
-
.where(:code => engine_info[:code])
|
|
48
|
-
.pluck(:id)
|
|
49
|
-
|
|
50
|
-
engine_id_lesli = Module
|
|
51
|
-
.where("platform in ('lesli_core', 'lesli_engine')")
|
|
52
|
-
.where(:code => "lesli")
|
|
53
|
-
.pluck(:id)
|
|
54
|
-
|
|
55
|
-
bucket_id_shared = Bucket
|
|
56
|
-
.where(:code => "shared")
|
|
57
|
-
.where(:module_id => engine_id_lesli)
|
|
58
|
-
.pluck(:id)
|
|
59
|
-
|
|
60
|
-
bucket_id_application = Bucket
|
|
61
|
-
.where(:code => "application")
|
|
62
|
-
.where(:module_id => engine_id_lesli)
|
|
63
|
-
.pluck(:id)
|
|
64
|
-
|
|
65
|
-
# get labels filtered by module (only rails translations)
|
|
66
|
-
labels = LabelService.new(current_user, query).builder(modules_id:engine_id).order(created_at: :asc)
|
|
67
|
-
labels_shared = LabelService.new(current_user, query).builder(modules_id:engine_id_lesli, buckets_id:bucket_id_shared).order(created_at: :asc)
|
|
68
|
-
labels_application = LabelService.new(current_user, query).builder(modules_id:engine_id_lesli, buckets_id:bucket_id_application).order(created_at: :asc)
|
|
69
|
-
|
|
70
|
-
translations = {}
|
|
71
|
-
|
|
72
|
-
available_locales = I18n.available_locales
|
|
73
|
-
|
|
74
|
-
# add key for every available language (required by i18n Rails gem)
|
|
75
|
-
available_locales.each do |lang|
|
|
76
|
-
translations[lang] = {
|
|
77
|
-
:file => "",
|
|
78
|
-
:labels => {}
|
|
79
|
-
}
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
engine_code = engine_info[:code]
|
|
83
|
-
|
|
84
|
-
available_locales.each do |lang|
|
|
85
|
-
|
|
86
|
-
# translations path for lesli core
|
|
87
|
-
translations[lang][:file] = "#{engine}::Engine".constantize.root.join(
|
|
88
|
-
"config", "locales", "translations.#{lang}.yml"
|
|
89
|
-
).to_s
|
|
90
|
-
|
|
91
|
-
# Create a collection of labels for the current module
|
|
92
|
-
labels.each do |label|
|
|
93
|
-
|
|
94
|
-
bucket_code = label[:bucket_code]
|
|
95
|
-
|
|
96
|
-
unless translations[lang][:labels].has_key? engine_code
|
|
97
|
-
translations[lang][:labels][engine_code] = { }
|
|
98
|
-
end
|
|
99
23
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
# # # send debug message for missing translations
|
|
123
|
-
# label[lang] = ":" + label.path + ":" if label[lang].blank?
|
|
124
|
-
|
|
125
|
-
# translations[lang][:labels]["lesli"]["shared"][label.text] = label[lang]
|
|
126
|
-
# end
|
|
127
|
-
|
|
128
|
-
# # Create a collection of labels for the application labels of Lesli
|
|
129
|
-
# labels_application.each do |label|
|
|
130
|
-
|
|
131
|
-
# unless translations[lang][:labels].has_key? "lesli"
|
|
132
|
-
# translations[lang][:labels]["lesli"] = { }
|
|
133
|
-
# end
|
|
134
|
-
|
|
135
|
-
# unless translations[lang][:labels]["lesli"].has_key? "application"
|
|
136
|
-
# translations[lang][:labels]["lesli"]["application"] = { }
|
|
137
|
-
# end
|
|
138
|
-
|
|
139
|
-
# # # send debug message for missing translations
|
|
140
|
-
# label[lang] = ":" + label.path + ":" if label[lang].blank?
|
|
141
|
-
|
|
142
|
-
# translations[lang][:labels]["lesli"]["application"][label.text] = label[lang]
|
|
143
|
-
# end
|
|
144
|
-
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
translations.each do |lang, translations|
|
|
148
|
-
|
|
149
|
-
# creates folder and subfolders
|
|
150
|
-
FileUtils.makedirs(File.dirname(translations[:file]))
|
|
151
|
-
|
|
152
|
-
# creates translation file for every available language
|
|
153
|
-
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
|
|
154
46
|
|
|
155
|
-
|
|
47
|
+
private
|
|
156
48
|
|
|
157
|
-
|
|
49
|
+
def coverage(completed, total)
|
|
50
|
+
return 0 if total.zero?
|
|
158
51
|
|
|
159
|
-
|
|
160
|
-
end
|
|
161
|
-
end
|
|
52
|
+
(completed * 100.0 / total).round
|
|
162
53
|
end
|
|
163
54
|
end
|
|
164
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(
|
|
5
|
-
|
|
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
|
|
12
|
-
<% @stats[:
|
|
13
|
-
|
|
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-
|
|
18
|
-
<%= locale[:name]
|
|
42
|
+
<h2 class="text-base font-medium text-slate-800">
|
|
43
|
+
<%= locale[:name] %>
|
|
19
44
|
</h2>
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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>
|