PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / v3 / src / assets / js / public / translation.js
ameliabooking / v3 / src / assets / js / public Last commit date
actions.js 5 days ago booking.js 5 days ago cabinet.js 5 days ago cart.js 5 days ago catalog.js 5 days ago coupon.js 5 days ago customFields.js 5 days ago events.js 5 days ago facebookPixel.js 5 days ago ivy.js 5 days ago package.js 5 days ago panel.js 5 days ago public.js 5 days ago renderActions.js 5 days ago restore.js 5 days ago slots.js 5 days ago translation.js 5 days ago user.js 5 days ago
translation.js
196 lines
1 import { longLocale, shortLocale } from '../../../plugins/settings.js'
2
3 function checkTranslations(entity, type) {
4 let nameTranslations =
5 type !== '' ? JSON.parse(entity.translations)[type] : JSON.parse(entity.translations)
6
7 if (shortLocale in nameTranslations) {
8 return nameTranslations[shortLocale]
9 }
10
11 let availableTranslations = Object.keys(nameTranslations)
12 let availableTranslationsShort = Object.keys(nameTranslations).map((key) =>
13 key.length > 2 ? key.slice(0, 2) : key,
14 )
15
16 let name = ''
17
18 for (let i = 0; i < availableTranslationsShort.length; i++) {
19 if (longLocale === availableTranslations[i] && nameTranslations[availableTranslations[i]]) {
20 name = nameTranslations[availableTranslations[i]]
21
22 break
23 }
24 if (
25 availableTranslationsShort[i] === shortLocale &&
26 nameTranslations[availableTranslations[i]]
27 ) {
28 name = nameTranslations[availableTranslations[i]]
29 }
30 }
31
32 return name
33 }
34
35 function getTranslated(entity, type) {
36 if (
37 entity.translations &&
38 JSON.parse(entity.translations)[type] &&
39 checkTranslations(entity, type)
40 ) {
41 return checkTranslations(entity, type)
42 }
43
44 return entity[type]
45 }
46
47 function getNameTranslated(entity) {
48 if (
49 entity.translations &&
50 JSON.parse(entity.translations)['name'] &&
51 checkTranslations(entity, 'name')
52 ) {
53 return checkTranslations(entity, 'name')
54 }
55
56 return entity.name
57 }
58
59 function getTicketTranslated(entity) {
60 if (entity.translations) {
61 const parsedTranslations = JSON.parse(entity.translations)
62 if (parsedTranslations.name) {
63 const translatedName = checkTranslations(entity, 'name')
64 if (translatedName) {
65 return translatedName
66 }
67 }
68 }
69
70 return entity.name
71 }
72
73 function getBadgeTranslated(entity) {
74 if (entity.translations && checkTranslations(entity, '')) {
75 return checkTranslations(entity, '')
76 }
77
78 return entity.content
79 }
80
81 function getCfLabelTranslated(entity) {
82 if (entity.translations && checkTranslations(entity, 'name')) {
83 return checkTranslations(entity, 'name')
84 }
85
86 return entity.label
87 }
88
89 function getCfOptionTranslated(entity) {
90 if (entity.translations && checkTranslations(entity, '')) {
91 return checkTranslations(entity, '')
92 }
93
94 return entity.label
95 }
96
97 function getDescriptionTranslated(entity) {
98 if (
99 entity.translations &&
100 JSON.parse(entity.translations)['description'] &&
101 checkTranslations(entity, 'description')
102 ) {
103 return checkTranslations(entity, 'description')
104 }
105
106 return entity.description
107 }
108
109 function useTranslateEntities(entities) {
110 if (entities.services && entities.services.length) {
111 entities.services.forEach((service) => {
112 service.name = getNameTranslated(service)
113 service.description = getDescriptionTranslated(service)
114 service.extras.forEach((extra) => {
115 extra.name = getNameTranslated(extra)
116 extra.description = getDescriptionTranslated(extra)
117 })
118 })
119 }
120
121 if (entities.locations && entities.locations.length) {
122 entities.locations.forEach((location) => {
123 location.name = getNameTranslated(location)
124 location.description = getDescriptionTranslated(location)
125 })
126 }
127
128 if (entities.packages && entities.packages.length) {
129 entities.packages.forEach((pack) => {
130 pack.name = getNameTranslated(pack)
131 pack.description = getDescriptionTranslated(pack)
132 pack.bookable.forEach((bookable) => {
133 bookable.service.name = getNameTranslated(bookable.service)
134 bookable.service.description = getDescriptionTranslated(bookable.service)
135 if ('extras' in bookable.service) {
136 bookable.service.extras.forEach((extra) => {
137 extra.name = getNameTranslated(extra)
138 extra.description = getDescriptionTranslated(extra)
139 })
140 }
141 })
142 })
143 }
144
145 if (entities.categories && entities.categories.length) {
146 entities.categories.forEach((category) => {
147 category.name = getNameTranslated(category)
148
149 category.serviceList.forEach((service) => {
150 service.name = getNameTranslated(service)
151 service.description = getDescriptionTranslated(service)
152 service.extras.forEach((extra) => {
153 extra.name = getNameTranslated(extra)
154 extra.description = getDescriptionTranslated(extra)
155 })
156 })
157 })
158 }
159
160 if (entities.events && entities.events.length) {
161 entities.events.forEach((event) => {
162 event.name = getNameTranslated(event)
163 event.description = getDescriptionTranslated(event)
164 event.extras.forEach((extra) => {
165 extra.name = getNameTranslated(extra)
166 extra.description = getDescriptionTranslated(extra)
167 })
168 })
169 }
170
171 if (entities.customFields && entities.customFields.length) {
172 entities.customFields.forEach((customField) => {
173 customField.label = getCfLabelTranslated(customField)
174 customField.options.forEach((option) => {
175 option.label = getCfOptionTranslated(option)
176 })
177 })
178 }
179
180 if (entities.employees && entities.employees.length) {
181 entities.employees.forEach((employee) => {
182 employee.firstName = getTranslated(employee, 'firstName')
183 employee.lastName = getTranslated(employee, 'lastName')
184 employee.description = getTranslated(employee, 'description')
185 })
186 }
187 }
188
189 export {
190 getNameTranslated,
191 getDescriptionTranslated,
192 getTicketTranslated,
193 getBadgeTranslated,
194 useTranslateEntities,
195 }
196