lesli_babel 0.7.0 → 1.1.0

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 (100) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/lesli_babel/babel-logo.svg +1 -157
  3. data/app/assets/javascripts/lesli_babel/application.js +1 -4602
  4. data/app/assets/stylesheets/lesli_babel/application.css +0 -1051
  5. data/app/controllers/lesli_babel/buckets_controller.rb +8 -16
  6. data/app/controllers/lesli_babel/dashboards_controller.rb +1 -0
  7. data/app/controllers/lesli_babel/labels_controller.rb +122 -0
  8. data/app/controllers/lesli_babel/modules_controller.rb +6 -44
  9. data/app/controllers/lesli_babel/translations_controller.rb +7 -61
  10. data/app/helpers/lesli_babel/labels_helper.rb +4 -0
  11. data/app/models/lesli_babel/label.rb +57 -0
  12. data/app/models/lesli_babel/module.rb +1 -9
  13. data/app/services/lesli_babel/label_service.rb +54 -0
  14. data/app/services/lesli_babel/module_service.rb +4 -1
  15. data/app/services/lesli_babel/translation_service.rb +164 -0
  16. data/app/views/lesli_babel/dashboards/show.html.erb +28 -1
  17. data/app/views/lesli_babel/labels/_form.html.erb +35 -0
  18. data/app/views/lesli_babel/labels/index.html.erb +59 -0
  19. data/app/views/lesli_babel/labels/new.html.erb +11 -0
  20. data/app/views/lesli_babel/labels/show.html.erb +10 -0
  21. data/app/views/lesli_babel/partials/{_engine-navigation.html.erb → _navigation.html.erb} +1 -1
  22. data/config/locales/translations.en.yml +1 -20
  23. data/config/locales/translations.es.yml +1 -20
  24. data/config/locales/translations.fr.yml +1 -20
  25. data/config/locales/translations.it.yml +1 -20
  26. data/config/locales/translations.pt.yml +1 -20
  27. data/config/routes.rb +11 -21
  28. data/db/migrate/v1.0/{0901120110_create_lesli_babel_strings.rb → 0901120110_create_lesli_babel_labels.rb} +9 -8
  29. data/lib/lesli_babel/version.rb +2 -2
  30. data/lib/tasks/lesli_babel_tasks.rake +14 -22
  31. data/readme.md +71 -28
  32. metadata +24 -96
  33. data/app/controllers/lesli_babel/clones_controller.rb +0 -80
  34. data/app/controllers/lesli_babel/relevants_controller.rb +0 -38
  35. data/app/controllers/lesli_babel/strings_controller.rb +0 -142
  36. data/app/models/lesli_babel/clone.rb +0 -24
  37. data/app/models/lesli_babel/relevant.rb +0 -21
  38. data/app/models/lesli_babel/string.rb +0 -242
  39. data/app/models/lesli_babel/translation.rb +0 -5
  40. data/app/services/lesli_babel/deploy_rails_service.rb +0 -142
  41. data/app/services/lesli_babel/string_service.rb +0 -78
  42. data/app/views/lesli_babel/buckets/_form.html.erb +0 -17
  43. data/app/views/lesli_babel/buckets/edit.html.erb +0 -6
  44. data/app/views/lesli_babel/buckets/index.html.erb +0 -25
  45. data/app/views/lesli_babel/buckets/new.html.erb +0 -5
  46. data/app/views/lesli_babel/buckets/show.html.erb +0 -4
  47. data/app/views/lesli_babel/clones/_form.html.erb +0 -19
  48. data/app/views/lesli_babel/clones/edit.html.erb +0 -20
  49. data/app/views/lesli_babel/clones/index.html.erb +0 -20
  50. data/app/views/lesli_babel/clones/new.html.erb +0 -20
  51. data/app/views/lesli_babel/clones/show.html.erb +0 -20
  52. data/app/views/lesli_babel/dashboards/stats..html.erb +0 -1
  53. data/app/views/lesli_babel/modules/_form.html.erb +0 -17
  54. data/app/views/lesli_babel/modules/edit.html.erb +0 -1
  55. data/app/views/lesli_babel/modules/index.html.erb +0 -1
  56. data/app/views/lesli_babel/modules/new.html.erb +0 -1
  57. data/app/views/lesli_babel/modules/show.html.erb +0 -1
  58. data/app/views/lesli_babel/relevants/edit.html.erb +0 -20
  59. data/app/views/lesli_babel/relevants/index.html.erb +0 -21
  60. data/app/views/lesli_babel/relevants/new.html.erb +0 -20
  61. data/app/views/lesli_babel/relevants/show.html.erb +0 -20
  62. data/app/views/lesli_babel/string/activities/_form.html.erb +0 -17
  63. data/app/views/lesli_babel/string/activities/edit.html.erb +0 -6
  64. data/app/views/lesli_babel/string/activities/index.html.erb +0 -25
  65. data/app/views/lesli_babel/string/activities/new.html.erb +0 -5
  66. data/app/views/lesli_babel/string/activities/show.html.erb +0 -4
  67. data/app/views/lesli_babel/string/discussions/_form.html.erb +0 -17
  68. data/app/views/lesli_babel/string/discussions/edit.html.erb +0 -6
  69. data/app/views/lesli_babel/string/discussions/index.html.erb +0 -25
  70. data/app/views/lesli_babel/string/discussions/new.html.erb +0 -5
  71. data/app/views/lesli_babel/string/discussions/show.html.erb +0 -4
  72. data/app/views/lesli_babel/strings/_form.html.erb +0 -17
  73. data/app/views/lesli_babel/strings/edit.html.erb +0 -6
  74. data/app/views/lesli_babel/strings/index.html.erb +0 -25
  75. data/app/views/lesli_babel/strings/new.html.erb +0 -5
  76. data/app/views/lesli_babel/strings/show.html.erb +0 -4
  77. data/app/views/lesli_babel/translations/_form.html.erb +0 -17
  78. data/app/views/lesli_babel/translations/edit.html.erb +0 -6
  79. data/app/views/lesli_babel/translations/index.html.erb +0 -1
  80. data/app/views/lesli_babel/translations/new.html.erb +0 -5
  81. data/app/views/lesli_babel/translations/show.html.erb +0 -1
  82. data/lib/scss/application.scss +0 -47
  83. data/lib/scss/dashboards.scss +0 -56
  84. data/lib/scss/modules.scss +0 -34
  85. data/lib/scss/translations.scss +0 -59
  86. data/lib/vue/application.js +0 -69
  87. data/lib/vue/apps/dashboards/show.vue +0 -83
  88. data/lib/vue/apps/modules/show.vue +0 -106
  89. data/lib/vue/apps/relevants/index.vue +0 -47
  90. data/lib/vue/apps/translations/index.vue +0 -64
  91. data/lib/vue/components/actions.vue +0 -29
  92. data/lib/vue/components/form-label-editor.vue +0 -439
  93. data/lib/vue/components/form-string-new.vue +0 -130
  94. data/lib/vue/stores/module.js +0 -63
  95. data/lib/vue/stores/statistics.js +0 -42
  96. data/lib/vue/stores/string.js +0 -84
  97. data/lib/vue/stores/strings.js +0 -141
  98. data/lib/vue/stores/translations.js +0 -73
  99. data/lib/vue/stores/translations.json +0 -152
  100. /data/app/views/lesli_babel/partials/{_engine-sidebar.html.erb → _sidebar.html.erb} +0 -0
@@ -36,14 +36,7 @@ module LesliBabel
36
36
 
37
37
  # GET /buckets
38
38
  def index
39
- respond_to do |format|
40
- format.html { }
41
- format.json {
42
- respond_with_successful(
43
- Module.find(params[:module_id]).buckets.order(:code)
44
- )
45
- }
46
- end
39
+ Bucket.all
47
40
  end
48
41
 
49
42
  # GET /buckets/1
@@ -52,7 +45,6 @@ module LesliBabel
52
45
 
53
46
  # GET /buckets/new
54
47
  def new
55
- @bucket = Bucket.new
56
48
  end
57
49
 
58
50
  # GET /buckets/1/edit
@@ -74,17 +66,17 @@ module LesliBabel
74
66
 
75
67
  # PATCH/PUT /buckets/1
76
68
  def update
77
- if @bucket.update(bucket_params)
78
- redirect_to @bucket, notice: 'Bucket was successfully updated.'
79
- else
80
- render :edit
81
- end
69
+ if @bucket.update(bucket_params)
70
+ redirect_to @bucket, notice: 'Bucket was successfully updated.'
71
+ else
72
+ render :edit
73
+ end
82
74
  end
83
75
 
84
76
  # DELETE /buckets/1
85
77
  def destroy
86
- @bucket.destroy
87
- redirect_to buckets_url, notice: 'Bucket was successfully destroyed.'
78
+ @bucket.destroy
79
+ redirect_to buckets_url, notice: 'Bucket was successfully destroyed.'
88
80
  end
89
81
 
90
82
  private
@@ -33,6 +33,7 @@ Building a better future, one line of code at a time.
33
33
  module LesliBabel
34
34
  class DashboardsController < ApplicationController
35
35
  def show
36
+ @stats = TranslationService.new(current_user, query).stats
36
37
  end
37
38
  end
38
39
  end
@@ -0,0 +1,122 @@
1
+ module LesliBabel
2
+ class LabelsController < ApplicationController
3
+ before_action :set_label, only: %i[show edit update destroy ]
4
+ before_action :set_module, only: [:new]
5
+
6
+ # GET /labels
7
+ def index
8
+ query[:pagination][:perPage] = 100
9
+ @labels = respond_with_pagination(LabelService.new(current_user, query).index(params))
10
+ end
11
+
12
+ # GET /labels/1
13
+ def show
14
+ @label = @label.show
15
+ end
16
+
17
+ # GET /labels/new
18
+ def new
19
+ @label = Label.new
20
+ end
21
+
22
+ # POST /labels
23
+ def create
24
+
25
+ @label = Label.new(label_params)
26
+ if @label.save
27
+ respond_to do |format|
28
+ format.html
29
+ format.turbo_stream do
30
+ respond_with_lesli(
31
+ :turbo => [
32
+ stream_notification_success('Label was successfully created.'),
33
+ stream_redirection(label_path(@label))
34
+ ]
35
+ )
36
+ end
37
+ end
38
+ else
39
+ render :new, status: :unprocessable_entity
40
+ end
41
+ end
42
+
43
+ def edit
44
+ end
45
+
46
+ # PATCH/PUT /labels/1
47
+ def update
48
+ return respond_with_not_found unless @label.found?
49
+
50
+ @label = @label.result
51
+
52
+ # if status changed
53
+ if @label["status"] != label_params["status"]
54
+
55
+ # saved update date
56
+ @label["last_update_status"] = Time.now
57
+
58
+ end
59
+
60
+ # if context changed
61
+ if @label["context"] != label_params["context"]
62
+
63
+ # saved update date
64
+ @label["last_update_context"] = Time.now
65
+
66
+ end
67
+
68
+ Lesli.config.locales.keys.each do |locale|
69
+
70
+ # if translation changed
71
+ if @label[locale] != label_params[locale]
72
+
73
+ # saved update date
74
+ @label["last_update_#{locale}"] = Time.now
75
+ end
76
+ end
77
+
78
+ if @label.update(label_params)
79
+ respond_with_lesli(
80
+ :turbo => [
81
+ stream_notification_success("Translation label updated successfully!"),
82
+ turbo_stream.replace('lesli-babel-labels-form', partial: 'lesli_babel/labels/form')
83
+ ]
84
+ )
85
+ else
86
+ respond_with_lesli(:turbo => stream_notification_success("Error updating translation label"))
87
+ end
88
+ end
89
+
90
+ # DELETE /labels/1
91
+ def destroy
92
+ @label.destroy
93
+ redirect_to labels_url, notice: "Label was successfully destroyed.", status: :see_other
94
+ end
95
+
96
+ private
97
+
98
+ # Use callbacks to share common setup or constraints between actions.
99
+ def set_label
100
+ @label = LabelService.new(current_user, query).find(params[:id])
101
+ end
102
+
103
+ def set_module
104
+ modules_id = params.dig(:modules_id)
105
+ modules_id = @label.result.bucket.module if @label
106
+ @module = ModuleService.new(current_user, query).find(modules_id).result
107
+ end
108
+
109
+ # Only allow a list of trusted parameters through.
110
+ def label_params
111
+ params.require(:label).permit(
112
+ :id,
113
+ :text,
114
+ :prefix,
115
+ :status,
116
+ :context,
117
+ :bucket_id,
118
+ Lesli.config.locales.keys
119
+ )
120
+ end
121
+ end
122
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Lesli
4
4
 
5
- Copyright (c) 2023, Lesli Technologies, S. A.
5
+ Copyright (c) 2025, Lesli Technologies, S. A.
6
6
 
7
7
  This program is free software: you can redistribute it and/or modify
8
8
  it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
19
19
 
20
20
  Lesli · Ruby on Rails SaaS Development Framework.
21
21
 
22
- Made with ♥ by https://www.lesli.tech
22
+ Made with ♥ by LesliTech
23
23
  Building a better future, one line of code at a time.
24
24
 
25
25
  @contact hello@lesli.tech
@@ -32,61 +32,23 @@ Building a better future, one line of code at a time.
32
32
 
33
33
  module LesliBabel
34
34
  class ModulesController < ApplicationController
35
- before_action :set_module, only: [:show, :edit, :update, :destroy]
35
+ before_action :set_module, only: [:show]
36
36
 
37
37
  # GET /modules
38
38
  def index
39
- respond_to do |format|
40
- format.html { }
41
- format.json { respond_with_successful(Module.index) }
42
- end
43
39
  end
44
40
 
45
41
  # GET /modules/1
46
42
  def show
47
- respond_to do |format|
48
- format.html { }
49
- format.json { respond_with_successful(@module.show) }
50
- end
51
- end
52
-
53
- # GET /modules/new
54
- def new
55
- @module = Module.new
56
- end
57
-
58
- # GET /modules/1/edit
59
- def edit
60
- end
61
-
62
- # POST /modules
63
- def create
64
- new_module = Module.new(module_params)
65
- if new_module.save
66
- respond_with_successful(new_module)
67
- else
68
- respond_with_error("Error on create module", new_module.errors)
69
- end
70
- end
71
-
72
- # PATCH/PUT /modules/1
73
- def update
74
- if @module.update(module_params)
75
- redirect_to @module, notice: 'Module was successfully updated.'
76
- else
77
- render :edit
78
- end
79
- end
80
-
81
- # DELETE /modules/1
82
- def destroy
43
+ @labels = respond_with_pagination(LabelService.new(current_user, query).index({ modules_id: @module.id }))
44
+ render("lesli_babel/labels/index")
83
45
  end
84
46
 
85
47
  private
86
48
 
87
49
  # Use callbacks to share common setup or constraints between actions.
88
50
  def set_module
89
- @module = Module.find(params[:id])
51
+ @module = ModuleService.new(current_user, query).find(params[:id]).result
90
52
  end
91
53
 
92
54
  # Only allow a trusted parameter "white list" through.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Lesli
4
4
 
5
- Copyright (c) 2023, Lesli Technologies, S. A.
5
+ Copyright (c) 2025, Lesli Technologies, S. A.
6
6
 
7
7
  This program is free software: you can redistribute it and/or modify
8
8
  it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
19
19
 
20
20
  Lesli · Ruby on Rails SaaS Development Framework.
21
21
 
22
- Made with ♥ by https://www.lesli.tech
22
+ Made with ♥ by LesliTech
23
23
  Building a better future, one line of code at a time.
24
24
 
25
25
  @contact hello@lesli.tech
@@ -34,65 +34,12 @@ module LesliBabel
34
34
  class TranslationsController < ApplicationController
35
35
  before_action :set_translation, only: []
36
36
 
37
- # GET /translations
38
- def index
39
- #@translations = Translation.all
40
- end
41
-
42
- # GET /translations/1
43
- def show
44
- end
45
-
46
- # GET /translations/new
47
- def new
48
- @translation = Translation.new
49
- end
50
-
51
- # GET /translations/1/edit
52
- def edit
53
- end
54
-
55
- # POST /translations
56
- def create
57
- @translation = Translation.new(translation_params)
58
-
59
- if @translation.save
60
- redirect_to @translation, notice: "Translation was successfully created."
61
- else
62
- render :new
63
- end
64
- end
65
-
66
- # PATCH/PUT /translations/1
67
- def update
68
- if @translation.update(translation_params)
69
- redirect_to @translation, notice: "Translation was successfully updated."
70
- else
71
- render :edit
72
- end
73
- end
74
-
75
- # DELETE /translations/1
76
- def destroy
77
- @translation.destroy
78
- redirect_to translations_url, notice: "Translation was successfully destroyed."
79
- end
80
-
81
- def options
82
- respond_with_successful({
83
- locales_available: Lesli.config.locales
84
- })
85
- end
86
-
87
- def clean
88
- respond_with_successful()
89
- end
90
-
91
37
  def deploy
92
- #TranslationsService.clean
93
- DeployRailsService.new(current_user, query).build
94
- #TranslationsService.restart_server
95
- respond_with_successful
38
+ TranslationService.new(current_user, query).deploy
39
+
40
+ respond_with_lesli(
41
+ :turbo => stream_notification_success("Translation deployed successfully!")
42
+ )
96
43
  end
97
44
 
98
45
  def renovate
@@ -140,6 +87,5 @@ module LesliBabel
140
87
  def translation_params
141
88
  params.fetch(:translation, {})
142
89
  end
143
-
144
90
  end
145
91
  end
@@ -0,0 +1,4 @@
1
+ module LesliBabel
2
+ module LabelsHelper
3
+ end
4
+ end
@@ -0,0 +1,57 @@
1
+ module LesliBabel
2
+ class Label < ApplicationRecord
3
+ attribute :prefix, :string
4
+
5
+ belongs_to :bucket
6
+
7
+ before_create :prepare_label
8
+
9
+ enum :status, {
10
+ :ok => "ok",
11
+ :disabled => "disabled",
12
+ :need_help => "need_help",
13
+ :need_context => "need_context",
14
+ :need_translation => "need_translation"
15
+ }
16
+
17
+ enum :prefix, {
18
+
19
+ # database
20
+ :column => "column",
21
+
22
+ # layout
23
+ :navigation => "navigation",
24
+
25
+ # components & elements
26
+ :button => "button",
27
+ :chart => "chart",
28
+ :tab => "tab",
29
+ :table => "table",
30
+ :toolbar => "toolbar",
31
+
32
+ # general
33
+ :view => "view",
34
+ :message => "message"
35
+ }, prefix: true
36
+
37
+ def category
38
+ return "warning" if need_help?
39
+ return "info" if need_context?
40
+ return "danger" if need_translation?
41
+ "ok"
42
+ end
43
+
44
+ private
45
+
46
+ def prepare_label
47
+
48
+ self.text = [self.prefix, self.text].compact.join('_')
49
+ .downcase # string to lowercase
50
+ .gsub(/[^0-9A-Za-z\s\-\_]/, '') # remove special characters from string
51
+ .gsub(/-/, '_') # replace dashes with underscore
52
+ .gsub(/\s+/, '_') # replace spaces or spaces with single dash
53
+
54
+ self.reference_bucket = "#{self.bucket.reference_module}-#{self.bucket.code}"
55
+ end
56
+ end
57
+ end
@@ -1,6 +1,7 @@
1
1
  module LesliBabel
2
2
  class Module < ApplicationRecord
3
3
  has_many :buckets
4
+ has_many :labels
4
5
 
5
6
  validates_presence_of :platform
6
7
 
@@ -18,15 +19,6 @@ module LesliBabel
18
19
  end
19
20
  end
20
21
 
21
- def show
22
- {
23
- :id => self.id,
24
- :code => self.code.titleize,
25
- :platform => self.platform,
26
- :created_at => self.created_at
27
- }
28
- end
29
-
30
22
  def format_module_name
31
23
 
32
24
  return if self.code == "main_app"
@@ -0,0 +1,54 @@
1
+ module LesliBabel
2
+ class LabelService < Lesli::ApplicationLesliService
3
+
4
+ def find id
5
+ super(Label.find_by_id(id))
6
+ end
7
+
8
+ def builder modules_id:nil, buckets_id:nil
9
+
10
+ # get strings with bucket and module information
11
+ strings = Label
12
+ .joins("inner join lesli_babel_buckets on lesli_babel_buckets.id = lesli_babel_labels.bucket_id and lesli_babel_buckets.deleted_at is NULL")
13
+ .joins("inner join lesli_babel_modules on lesli_babel_modules.id = lesli_babel_buckets.module_id and lesli_babel_modules.deleted_at is NULL")
14
+ .where("lesli_babel_labels.status != 0 OR lesli_babel_labels.status is NULL")
15
+
16
+ # filter by specific engines
17
+ if modules_id
18
+ strings = strings.where("lesli_babel_modules.id in (?)", modules_id)
19
+ end
20
+
21
+ # filter by specific engine buckets
22
+ if buckets_id
23
+ strings = strings.where("lesli_babel_buckets.id in (?)", buckets_id)
24
+ end
25
+
26
+ strings.select(
27
+ :id,
28
+ :text,
29
+ :status,
30
+ :context,
31
+ Lesli.config.locales.keys,
32
+ "lesli_babel_modules.id as engine_id",
33
+ "lesli_babel_buckets.id as bucket_id",
34
+ "lesli_babel_buckets.code as bucket_code",
35
+ "lesli_babel_modules.code as engine_code",
36
+ "lesli_babel_modules.platform as platform",
37
+ "concat_ws('.', lesli_babel_modules.code, lesli_babel_buckets.code, text) as path"
38
+ )
39
+
40
+ end
41
+
42
+ def index params
43
+ self.builder(modules_id:params[:modules_id])
44
+ .page(query[:pagination][:page])
45
+ .per(query[:pagination][:perPage])
46
+ .order(status: :desc )
47
+ .order(updated_at: :desc)
48
+ end
49
+
50
+ def show
51
+ self.builder.find_by_id(self.resource.id)
52
+ end
53
+ end
54
+ end
@@ -1,6 +1,10 @@
1
1
  module LesliBabel
2
2
  class ModuleService < Lesli::ApplicationLesliService
3
3
 
4
+ def find id
5
+ super(Module.find_by_id(id))
6
+ end
7
+
4
8
  def list
5
9
 
6
10
  # get the list of installed engines, including: rails_core, rails_builder, rails_engine
@@ -13,6 +17,5 @@ module LesliBabel
13
17
  .map { |engine| engine.id }
14
18
 
15
19
  end
16
-
17
20
  end
18
21
  end
@@ -0,0 +1,164 @@
1
+ module LesliBabel
2
+ class TranslationService < Lesli::ApplicationLesliService
3
+
4
+ def stats
5
+ Rails.cache.fetch(cache_key_for_account(__method__), expires_in: 1.hour) do
6
+
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.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
28
+
29
+ {
30
+ total_strings: total_strings,
31
+ total_strings_translations: total_strings_translations,
32
+ total_strings_waiting_for_help: total_strings_waiting_for_help,
33
+ total_strings_waiting_for_translation: total_strings_waiting_for_translation
34
+ }
35
+ 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 = Lesli.config.locales.keys
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
+
100
+ unless translations[lang][:labels][engine_code].has_key? bucket_code
101
+ translations[lang][:labels][engine_code][bucket_code] = { }
102
+ end
103
+
104
+ # # send debug message for missing translations
105
+ label[lang] = ":" + label.path + ":" if label[lang].blank?
106
+
107
+ translations[lang][:labels][engine_code][bucket_code][label.text] = label[lang]
108
+
109
+ end
110
+
111
+ # Create a collection of labels for the shared labels of Lesli
112
+ # labels_shared.each do |label|
113
+
114
+ # unless translations[lang][:labels].has_key? "lesli"
115
+ # translations[lang][:labels]["lesli"] = { }
116
+ # end
117
+
118
+ # unless translations[lang][:labels]["lesli"].has_key? "shared"
119
+ # translations[lang][:labels]["lesli"]["shared"] = { }
120
+ # end
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+")
154
+
155
+ translation_file.write({ "#{lang}": translations[:labels] }.to_yaml)
156
+
157
+ translation_file.close
158
+
159
+ #L2.msg "file added: #{ translations[:file] }"
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end