anote-server-libs 0.11.5 → 0.11.6
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.
- package/package.json +1 -1
- package/services/utils.js +11 -5
- package/services/utils.ts +19 -12
package/package.json
CHANGED
package/services/utils.js
CHANGED
|
@@ -233,9 +233,8 @@ function replacePlaceholders(data, keys, depth) {
|
|
|
233
233
|
function getHtml(template, translationKeyValue) {
|
|
234
234
|
if (!template)
|
|
235
235
|
return undefined;
|
|
236
|
-
const pattern = new RegExp('{{\\s*([
|
|
237
|
-
const replacer = (_, key) => replacePlaceholders(translationKeyValue, key.split('.'), 0) ??
|
|
238
|
-
template = template.replace(pattern, replacer);
|
|
236
|
+
const pattern = new RegExp('{{\\s*([^{}]+?)\\s*}}', 'g');
|
|
237
|
+
const replacer = (_, key) => replacePlaceholders(translationKeyValue, key.split('.'), 0) ?? key;
|
|
239
238
|
template = template.replace(pattern, replacer);
|
|
240
239
|
template = template.replace(pattern, replacer);
|
|
241
240
|
template = template.replace(new RegExp('\\[\\[\\s*([a-zA-Z._0-9:]+)\\s*\\]\\]', 'g'), (_, key) => {
|
|
@@ -252,9 +251,16 @@ function getHtml(template, translationKeyValue) {
|
|
|
252
251
|
return template;
|
|
253
252
|
}
|
|
254
253
|
function getHtmlReplaced(config, templates, key, lang, defaultTemplateTranslations = {}, projectSpecificTranslations = {}, envSpecificTranslations, extraData, newPage) {
|
|
254
|
+
const asTranslationMap = (value) => value && typeof value === 'object' ? value : {};
|
|
255
255
|
const defaultTranslations = defaultTemplateTranslations?.[lang] || defaultTemplateTranslations?.[0] || {};
|
|
256
|
-
const projectSpecificTrans =
|
|
257
|
-
|
|
256
|
+
const projectSpecificTrans = {
|
|
257
|
+
...asTranslationMap(projectSpecificTranslations?.[config.app.product]?.[lang] || projectSpecificTranslations?.[config.app.name]?.[0]),
|
|
258
|
+
...asTranslationMap(projectSpecificTranslations?.[config.app.product]?.[key]?.[lang] || projectSpecificTranslations?.[config.app.name]?.[key]?.[0])
|
|
259
|
+
};
|
|
260
|
+
const envSpecificTrans = {
|
|
261
|
+
...asTranslationMap(envSpecificTranslations?.[config.app.name]?.[lang] || envSpecificTranslations?.[config.app.name]?.[0]),
|
|
262
|
+
...asTranslationMap(envSpecificTranslations?.[config.app.name]?.[key]?.[lang] || envSpecificTranslations?.[config.app.name]?.[key]?.[0])
|
|
263
|
+
};
|
|
258
264
|
extraData = Object.fromEntries(Object.entries(extraData || {}).map(([k, v]) => [k, `{{${v}}}`]));
|
|
259
265
|
const translationKeyValue = {
|
|
260
266
|
...defaultTranslations,
|
package/services/utils.ts
CHANGED
|
@@ -211,9 +211,8 @@ export function replacePlaceholders(data: Record<string, any>, keys: string[], d
|
|
|
211
211
|
|
|
212
212
|
function getHtml(template: string, translationKeyValue: Record<string, any>): string | undefined {
|
|
213
213
|
if(!template) return undefined;
|
|
214
|
-
const pattern = new RegExp('{{\\s*([
|
|
215
|
-
const replacer = (_: string, key: string) => replacePlaceholders(translationKeyValue, key.split('.'), 0) ??
|
|
216
|
-
template = template.replace(pattern, replacer);
|
|
214
|
+
const pattern = new RegExp('{{\\s*([^{}]+?)\\s*}}', 'g');
|
|
215
|
+
const replacer = (_: string, key: string) => replacePlaceholders(translationKeyValue, key.split('.'), 0) ?? key;
|
|
217
216
|
template = template.replace(pattern, replacer);
|
|
218
217
|
template = template.replace(pattern, replacer);
|
|
219
218
|
template = template.replace(new RegExp('\\[\\[\\s*([a-zA-Z._0-9:]+)\\s*\\]\\]', 'g'), (_, key) => {
|
|
@@ -230,17 +229,25 @@ function getHtml(template: string, translationKeyValue: Record<string, any>): st
|
|
|
230
229
|
return template;
|
|
231
230
|
}
|
|
232
231
|
|
|
233
|
-
export function getHtmlReplaced(config: {frontend: string, app: {product: string, name: string, emailConfig: Record<string,
|
|
232
|
+
export function getHtmlReplaced(config: {frontend: string, app: {product: string, name: string, emailConfig: Record<string, string>}},
|
|
234
233
|
templates: Record<string, string>,
|
|
235
234
|
key: string, lang: number,
|
|
236
|
-
defaultTemplateTranslations: Record<number,
|
|
237
|
-
projectSpecificTranslations: Record<string, Record<number,
|
|
238
|
-
envSpecificTranslations?: Record<string, Record<number,
|
|
235
|
+
defaultTemplateTranslations: Record<number, Record<string | number, string>> = {},
|
|
236
|
+
projectSpecificTranslations: Record<string, Record<string | number, Record<string | number, string>>> = {},
|
|
237
|
+
envSpecificTranslations?: Record<string, Record<string | number, Record<string | number, string>>>,
|
|
239
238
|
extraData?: Record<string, any>,
|
|
240
239
|
newPage?: boolean): string {
|
|
240
|
+
const asTranslationMap = (value: unknown): Record<string | number, string> =>
|
|
241
|
+
value && typeof value === 'object' ? value as Record<string | number, string> : {};
|
|
241
242
|
const defaultTranslations = defaultTemplateTranslations?.[lang] || defaultTemplateTranslations?.[0] || {};
|
|
242
|
-
const projectSpecificTrans =
|
|
243
|
-
|
|
243
|
+
const projectSpecificTrans = {
|
|
244
|
+
...asTranslationMap(projectSpecificTranslations?.[config.app.product]?.[lang] || projectSpecificTranslations?.[config.app.name]?.[0]),
|
|
245
|
+
...asTranslationMap(projectSpecificTranslations?.[config.app.product]?.[key]?.[lang] || projectSpecificTranslations?.[config.app.name]?.[key]?.[0])
|
|
246
|
+
};
|
|
247
|
+
const envSpecificTrans = {
|
|
248
|
+
...asTranslationMap(envSpecificTranslations?.[config.app.name]?.[lang] || envSpecificTranslations?.[config.app.name]?.[0]),
|
|
249
|
+
...asTranslationMap(envSpecificTranslations?.[config.app.name]?.[key]?.[lang] || envSpecificTranslations?.[config.app.name]?.[key]?.[0])
|
|
250
|
+
};
|
|
244
251
|
// Add {{}} around all extraData values so that they will be auto translated in the template if needed
|
|
245
252
|
extraData = Object.fromEntries(Object.entries(extraData || {}).map(([k, v]) => [k, `{{${v}}}`]));
|
|
246
253
|
const translationKeyValue = {
|
|
@@ -269,9 +276,9 @@ export function getHtmlReplaced(config: {frontend: string, app: {product: string
|
|
|
269
276
|
|
|
270
277
|
export function getEmailTitle(config: {frontend: string, app: {product: string, name: string, emailConfig: Record<string, any>}},
|
|
271
278
|
key: string, lang: number,
|
|
272
|
-
defaultTitles: Record<number,
|
|
273
|
-
projectSpecificTitles: Record<string, Record<number,
|
|
274
|
-
envSpecificTitles: Record<string, Record<number,
|
|
279
|
+
defaultTitles: Record<number, Record<string | number, string>> = {},
|
|
280
|
+
projectSpecificTitles: Record<string, Record<number, Record<string | number, string>>> = {},
|
|
281
|
+
envSpecificTitles: Record<string, Record<number, Record<string | number, string>>> = {},
|
|
275
282
|
extraData: Record<string, string> = {}): string | undefined {
|
|
276
283
|
const pattern = new RegExp('{{\\s*([a-zA-Z._0-9]+)\\s*}}', 'g');
|
|
277
284
|
const title = envSpecificTitles?.[config.app.name]?.[lang]?.[key]
|