lesli_babel 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,102 +0,0 @@
1
- module LesliBabel
2
- class TranslationsFlutterService
3
-
4
- def self.build(engine_id = nil)
5
-
6
- # get all rails engines
7
- engines = Module.where(:id => engine_id).map do |engine|
8
- engine[:id]
9
- end
10
-
11
- # get strings filtered by module (only rails translations)
12
- strings = TranslationsService.strings_for_apps(engines)
13
-
14
- indexes = {}
15
- translations = {}
16
- available_locales = Rails.application.config.lesli_settings["configuration"]["locales"]
17
-
18
- strings.each do |string|
19
-
20
- module_name = string[:engine_name].downcase.sub("cloud", "")
21
- engine_name = string[:engine_name]
22
- bucket_name = string[:bucket_name]
23
- module_type = string[:platform]
24
-
25
- bucket_name_clean = bucket_name.gsub("/","_")
26
-
27
- available_locales.each do |lang|
28
-
29
- file_path = Rails.root.join(
30
- "public", "tmp", "babel", "flutter","l10n", "app_#{lang}.arb"
31
- )
32
-
33
- file_id = file_path.to_s
34
-
35
- unless translations.has_key? file_id
36
- translations[file_id] = []
37
- end
38
-
39
- # send debug message for missing translations
40
- string[lang] = ":" + string.path + ":" if string[lang].blank?
41
-
42
- translations[file_id].push({
43
- label: "#{bucket_name_clean}_#{string.label}".camelize(:lower),
44
- translation: string[lang]
45
- })
46
-
47
- end
48
-
49
- # Index keys
50
- if not indexes.has_key? bucket_name_clean
51
- indexes[bucket_name_clean] = []
52
- end
53
-
54
- indexes[bucket_name_clean].push({
55
- k: string.label.camelize(:lower),
56
- v: "#{bucket_name_clean}_#{string.label}".upcase
57
- })
58
-
59
- end
60
-
61
- translation_files = []
62
-
63
- # Create translations files for every available language
64
- translations.each do |translation|
65
-
66
- file_path = translation[0]
67
- strings = translation[1]
68
-
69
- translation_files.push(file_path)
70
-
71
- # creates folder and subfolders
72
- FileUtils.makedirs(File.dirname(file_path))
73
-
74
- # creates translation file for every available language
75
- translation_file = File.new(file_path, "w+")
76
-
77
- # start the file with curlybraces as flutter requires
78
- translation_file.write("{\n")
79
-
80
- strings.each_with_index do |string,index|
81
-
82
- # writes the key value translations
83
- translation_file.write("\"#{string[:label]}\": \"#{string[:translation]}\"")
84
-
85
- # add comma and new line if not last string
86
- translation_file.write(",\n") if index != strings.size - 1
87
-
88
- end
89
-
90
- # ends the file with curlybraces
91
- translation_file.write("}\n")
92
-
93
- translation_file.close
94
-
95
- end
96
-
97
- LC::Response.service true, translation_files
98
-
99
- end
100
-
101
- end
102
- end
@@ -1,119 +0,0 @@
1
- module LesliBabel
2
- class TranslationsIosService
3
-
4
- def self.build(engine_id = nil)
5
-
6
- # get all rails engines
7
- engines = Module.where(:id => engine_id).map do |engine|
8
- engine[:id]
9
- end
10
-
11
- # get strings filtered by module (only rails translations)
12
- strings = TranslationsService.strings_for_apps(engines)
13
-
14
- indexes = {}
15
- translations = {}
16
-
17
- available_locales = Rails.application.config.lesli_settings["configuration"]["locales"]
18
-
19
- strings.each do |string|
20
-
21
- module_name = string[:engine_name].downcase.sub("cloud", "")
22
- engine_name = string[:engine_name]
23
- bucket_name = string[:bucket_name]
24
- module_type = string[:platform]
25
- bucket_name_clean = bucket_name.gsub("/","_")
26
-
27
- available_locales.each do |lang|
28
-
29
- file_path = Rails.root.join(
30
- "public", "tmp", "locales", engine_name, "Resources",
31
- "#{lang}.lproj", "Localizable.strings"
32
- )
33
-
34
- file_id = file_path.to_s
35
-
36
- unless translations.has_key? file_id
37
- translations[file_id] = []
38
- end
39
-
40
- # send debug message for missing translations
41
- string[lang] = ":" + string.path + ":" if string[lang].blank?
42
-
43
- translations[file_id].push({
44
- label: "#{bucket_name_clean}_#{string.label}".upcase,
45
- translation: string[lang]
46
- })
47
-
48
- end
49
-
50
- # Index keys
51
- if not indexes.has_key? bucket_name_clean
52
- indexes[bucket_name_clean] = []
53
- end
54
-
55
- indexes[bucket_name_clean].push({
56
- k: string.label.camelize(:lower),
57
- v: "#{bucket_name_clean}_#{string.label}".upcase
58
- })
59
-
60
- end
61
-
62
- translation_files = []
63
-
64
- # Create translations files for every available language
65
- translations.each do |translation|
66
-
67
- file_path = translation[0]
68
- strings = translation[1]
69
-
70
- translation_files.push(file_path)
71
-
72
- # creates folder and subfolders
73
- FileUtils.makedirs(File.dirname(file_path))
74
-
75
- # creates translation file for every available language
76
- translation_file = File.new(file_path, "w+")
77
-
78
- strings.each do |string|
79
- translation_file.write("\"#{string[:label]}\" = \"#{string[:translation]}\";\n")
80
- end
81
-
82
- translation_file.close
83
-
84
- end
85
-
86
- # Create global label index file
87
- index_file_path = Rails.root.join("public", "tmp", "locales", "Translations.swift")
88
-
89
- FileUtils.makedirs(File.dirname(index_file_path))
90
-
91
- index_file = File.new(index_file_path, "w+")
92
-
93
- index_file.write("\ enum Translations { \n")
94
-
95
- indexes.each do |index_bucket|
96
-
97
- index_file.write("\ enum #{index_bucket[0]} { \n")
98
-
99
- index_bucket[1].each do |index_label|
100
- index_file.write("static let #{index_label[:k]} = \"#{index_label[:v]}\"\n")
101
- end
102
-
103
- index_file.write("\ } \n")
104
-
105
- end
106
-
107
- index_file.write("\ } \n")
108
-
109
- index_file.close
110
-
111
- # include index into translation files zip
112
- translation_files.push(index_file_path)
113
-
114
- LC::Response.service true, translation_files
115
-
116
- end
117
-
118
- end
119
- end
@@ -1,114 +0,0 @@
1
- module LesliBabel
2
- class TranslationsJsService
3
-
4
- def self.build
5
-
6
- # usually we download translations to use with other platforms like, flutter, reactnative, electron etc.
7
- # so for these cases we need to include all the translations
8
- engines = Module.all.map do |engine|
9
- engine[:id]
10
- end
11
-
12
- # get strings filtered by module (only rails translations)
13
- strings = TranslationsService.strings(engines)
14
-
15
- strings = strings.select(
16
- :id,
17
- :label,
18
- :status,
19
- :context,
20
- :priority,
21
- :need_help,
22
- :need_translation,
23
- Rails.application.config.lesli_settings["configuration"]["locales"],
24
- "cloud_babel_modules.id as engine_id",
25
- "cloud_babel_buckets.id as bucket_id",
26
- "cloud_babel_buckets.name as bucket_name",
27
- "cloud_babel_modules.name as engine_name",
28
- "cloud_babel_modules.platform as platform",
29
- "'' as path"
30
- )
31
-
32
- translations = {}
33
-
34
- available_locales = Rails.application.config.lesli_settings["configuration"]["locales"]
35
-
36
- # add key for every available language (required by i18n Rails gem)
37
- available_locales.each do |lang|
38
- translations[lang] = { }
39
- end
40
-
41
- strings.each do |string|
42
- module_name = string[:engine_name].downcase.sub("cloud", "")
43
- engine_code = string[:engine_name].underscore
44
- engine_name = string[:engine_name]
45
- bucket_name = string[:bucket_name]
46
- platform = string[:platform]
47
-
48
- available_locales.each do |lang|
49
-
50
- # translations path for lesli core
51
- file_path = Rails.root.join("config", "locales", bucket_name, "#{ bucket_name.gsub("/","_") }.#{ lang }.js")
52
-
53
- # translations path for translations for engines
54
- file_path = Rails.root.join("public", "tmp", "locales", "#{lang}.json")
55
-
56
- file_id = file_path.to_s.to_sym
57
-
58
- unless translations[lang].has_key? file_id
59
- translations[lang][file_id] = { }
60
- end
61
-
62
- unless translations[lang][file_id].has_key? module_name
63
- translations[lang][file_id][module_name] = { }
64
- end
65
-
66
- unless translations[lang][file_id][module_name].has_key? bucket_name
67
- translations[lang][file_id][module_name][bucket_name] = { }
68
- end
69
-
70
- # send debug message for missing translations
71
- #string[lang] = ":" + string.path + ":" if string[lang].blank?
72
-
73
- translations[lang][file_id][module_name][bucket_name][string.label] = string[lang]
74
-
75
- end
76
-
77
- end
78
-
79
- translation_files = []
80
-
81
- translations.each do |file_by_language|
82
-
83
- lang = file_by_language[0]
84
- file_by_controller = file_by_language[1]
85
-
86
- file_by_controller.each do |file|
87
-
88
- file_path = file[0].to_s
89
- translations = file[1]
90
-
91
- translation_files.push(file_path)
92
-
93
- # creates folder and subfolders
94
- FileUtils.makedirs(File.dirname(file_path))
95
-
96
- # creates translation file for every available language
97
- translation_file = File.new(file_path, "w+")
98
-
99
- translation_file.write({ "#{lang}": translations}.to_json)
100
-
101
- translation_file.close
102
-
103
- p "file added: #{ file_path }"
104
-
105
- end
106
-
107
- end
108
-
109
- LC::Response.service true, translation_files
110
-
111
- end
112
-
113
- end
114
- end
@@ -1,77 +0,0 @@
1
- module LesliBabel
2
- class TranslationsMiddlemanService
3
-
4
- def self.build(engine_id)
5
-
6
- # get all rails engines
7
- engines = Module.where(:id => engine_id).map(&:id)
8
-
9
- # get strings filtered by module (only rails translations)
10
- strings = TranslationsService.strings_for_apps(engines)
11
-
12
- indexes = {}
13
- translations = {}
14
- available_locales = Rails.application.config.lesli_settings["configuration"]["locales"]
15
-
16
- # add key for every available language (required by i18n Rails gem)
17
- available_locales.each do |lang|
18
- translations[lang] = { :path => '', :labels => {} }
19
- end
20
-
21
- strings.each do |string|
22
-
23
- module_name = string[:engine_name].downcase.sub("cloud", "")
24
- engine_name = string[:engine_name]
25
- bucket_name = string[:bucket_name]
26
- module_type = string[:platform]
27
-
28
- bucket_name_clean = bucket_name.gsub("/","_")
29
-
30
- available_locales.each do |lang|
31
-
32
- file_path = Rails.root.join(
33
- "public", "tmp", "babel", "middleman","locales", "#{lang}.yml"
34
- )
35
-
36
- translations[lang][:file] = file_path.to_s
37
-
38
- unless translations[lang][:labels].has_key? bucket_name
39
- translations[lang][:labels][bucket_name] = { }
40
- end
41
-
42
- # send debug message for missing translations
43
- string[lang] = ":" + string.path + ":" if string[lang].blank?
44
-
45
- translations[lang][:labels][bucket_name][string.label] = string[lang]
46
-
47
- end
48
-
49
- end
50
-
51
- translation_files = []
52
-
53
- # Create translations files for every available language
54
- translations.each do |translation|
55
-
56
- lang = translation[0]
57
- file = translation[1][:file]
58
- labels = translation[1][:labels]
59
-
60
- translation_files.push(file)
61
-
62
- # creates folder and subfolders
63
- FileUtils.makedirs(File.dirname(file))
64
-
65
- # creates translation file for every available language
66
- translation_file = File.new(file, "w+")
67
- translation_file.write({ "#{lang.to_s}": labels}.to_yaml)
68
- translation_file.close
69
-
70
- end
71
-
72
- LC::Response.service true, translation_files
73
-
74
- end
75
-
76
- end
77
- end
@@ -1,119 +0,0 @@
1
- module LesliBabel
2
- class TranslationsRailsService
3
-
4
- def self.build
5
-
6
- engines_installed = Rails.application.config.lesli_settings["engines"].map do |engine|
7
- engine[:name]
8
- end
9
-
10
- # get all rails engines to buil
11
- engines = Module
12
- .where("platform in ('rails_core', 'rails_builder', 'rails_engine', 'standard')")
13
- .where("name in (?)", engines_installed.push("Core","LesliMails"))
14
- .map do |engine|
15
- engine[:id]
16
- end
17
-
18
- # get strings filtered by module (only rails translations)
19
- strings = TranslationsService.strings(engines)
20
-
21
- strings = strings.select(
22
- :id,
23
- :label,
24
- :status,
25
- :context,
26
- :priority,
27
- :need_help,
28
- :need_translation,
29
- Rails.application.config.lesli_settings["configuration"]["locales"],
30
- "cloud_babel_modules.id as engine_id",
31
- "cloud_babel_buckets.id as bucket_id",
32
- "cloud_babel_buckets.name as bucket_name",
33
- "cloud_babel_modules.name as engine_name",
34
- "cloud_babel_modules.platform as platform",
35
- "'' as path"
36
- )
37
-
38
- translations = {}
39
-
40
- available_locales = Rails.application.config.lesli_settings["configuration"]["locales"]
41
-
42
- # add key for every available language (required by i18n Rails gem)
43
- available_locales.each do |lang|
44
- translations[lang] = { }
45
- end
46
-
47
- strings.each do |string|
48
- module_name = string[:engine_name].downcase.sub("cloud", "")
49
- engine_code = string[:engine_name].underscore
50
- engine_name = string[:engine_name]
51
- bucket_name = string[:bucket_name]
52
- platform = string[:platform]
53
-
54
- available_locales.each do |lang|
55
-
56
- # translations path for lesli core
57
- file_path = Rails.root.join("config", "locales", bucket_name, "#{ bucket_name.gsub("/","_") }.#{ lang }.yml")
58
-
59
- # translations path for translations for engines
60
- if platform == "rails_builder" || platform == "rails_engine" || platform == "standard"
61
- file_path = Rails.root.join("engines", engine_name, "config", "locales", bucket_name, "#{ bucket_name }.#{ lang }.yml")
62
- file_path = Rails.root.join("config", "locales", engine_code, bucket_name, "#{ bucket_name.gsub("/","_") }.#{ lang }.yml")
63
- end
64
-
65
- file_id = file_path.to_s.to_sym
66
-
67
- unless translations[lang].has_key? file_id
68
- translations[lang][file_id] = { }
69
- end
70
-
71
- unless translations[lang][file_id].has_key? module_name
72
- translations[lang][file_id][module_name] = { }
73
- end
74
-
75
- unless translations[lang][file_id][module_name].has_key? bucket_name
76
- translations[lang][file_id][module_name][bucket_name] = { }
77
- end
78
-
79
- # send debug message for missing translations
80
- string[lang] = ":" + string.path + ":" if string[lang].blank?
81
-
82
- translations[lang][file_id][module_name][bucket_name][string.label] = string[lang]
83
-
84
- end
85
-
86
- end
87
-
88
- translations.each do |file_by_language|
89
-
90
- lang = file_by_language[0]
91
- file_by_controller = file_by_language[1]
92
-
93
- file_by_controller.each do |file|
94
-
95
- file_path = file[0].to_s
96
- translations = file[1]
97
-
98
- # creates folder and subfolders
99
- FileUtils.makedirs(File.dirname(file_path))
100
-
101
- # creates translation file for every available language
102
- translation_file = File.new(file_path, "w+")
103
-
104
- translation_file.write({ "#{lang}": translations}.to_yaml)
105
-
106
- translation_file.close
107
-
108
- p "file added: #{ file_path }"
109
-
110
- end
111
-
112
- end
113
-
114
- LC::Response.service true, translations
115
-
116
- end
117
-
118
- end
119
- end
@@ -1,97 +0,0 @@
1
- =begin
2
-
3
- Lesli
4
-
5
- Copyright (c) 2020, all rights reserved.
6
-
7
- All the information provided by this platform is protected by international laws related to
8
- industrial property, intellectual property, copyright and relative international laws.
9
- All intellectual or industrial property rights of the code, texts, trade mark, design,
10
- pictures and any other information belongs to the owner of this platform.
11
-
12
- Without the written permission of the owner, any replication, modification,
13
- transmission, publication is strictly forbidden.
14
-
15
- For more information read the license file including with this software.
16
-
17
- // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
18
- // ·
19
-
20
- =end
21
- module LesliBabel
22
- class TranslationsService
23
-
24
- def self.restart_server
25
- return if Rails.env != "production"
26
- system "bundle exec rake i18n:js:export RAILS_ENV=production"
27
- FileUtils.touch Rails.root.join("tmp", "restart.txt")
28
- end
29
-
30
- def self.clean
31
-
32
- # store full path to translation files for every language
33
- files_to_delete = []
34
-
35
- # remove javascript translation cache
36
- files_to_delete.push(Rails.root.join("public", "javascripts", "translations.js"))
37
-
38
- # get translation files for engines only
39
- Lesli::engines.each do |engine|
40
- files_to_delete.push(Rails.root.join("engines", engine["name"], "config", "locales"))
41
- end
42
-
43
- # include translation files for lesli core
44
- files_to_delete.push(Rails.root.join("config", "locales"))
45
-
46
- # include external app translations
47
- files_to_delete.push(Rails.root.join("public", "tmp", "locales"))
48
-
49
- # delete all the translation files found
50
- files_to_delete.each do |file|
51
- FileUtils.rm_rf(file)
52
- end
53
-
54
- LC::Response.service true, files_to_delete
55
-
56
- end
57
-
58
- def self.strings engines_id=nil, buckets_id=nil
59
-
60
- # get strings with bucket and module information
61
- strings = String
62
- .joins("inner join cloud_babel_buckets on cloud_babel_buckets.id = cloud_babel_strings.cloud_babel_buckets_id and cloud_babel_buckets.deleted_at is NULL")
63
- .joins("inner join cloud_babel_modules on cloud_babel_modules.id = cloud_babel_buckets.cloud_babel_modules_id and cloud_babel_modules.deleted_at is NULL")
64
- .where("cloud_babel_modules.id in (?)", TranslationsService.installed_engines_id)
65
-
66
- # filter by specific engines
67
- if engines_id
68
- strings = strings.where("cloud_babel_modules.id in (?)", engines_id)
69
- end
70
-
71
- # filter by specific engine buckets
72
- if buckets_id
73
- strings = strings.where("cloud_babel_buckets.id in (?)", buckets_id)
74
- end
75
-
76
- strings
77
-
78
- end
79
-
80
- def self.strings_for_apps engines_id=nil, buckets_id=nil
81
-
82
- strings = strings(engines_id, buckets_id)
83
- strings = strings.select(
84
- :id,
85
- :label,
86
- "cloud_babel_modules.name as engine_name",
87
- "cloud_babel_buckets.name as bucket_name",
88
- "cloud_babel_modules.platform",
89
- Rails.application.config.lesli_settings["configuration"]["locales"]
90
- )
91
-
92
- strings
93
-
94
- end
95
-
96
- end
97
- end