@olenbetong/appframe-core 2.0.1 → 2.0.3
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/dist/esm/af.common.js +19 -19
- package/dist/esm/af.common.legacy.js +19 -19
- package/dist/esm/af.common.legacy.min.js +3 -3
- package/dist/esm/af.common.legacy.min.js.map +4 -4
- package/dist/esm/af.common.min.js +3 -3
- package/dist/esm/af.common.min.js.map +4 -4
- package/dist/iife/af.common.js +19 -19
- package/dist/iife/af.common.legacy.js +19 -19
- package/dist/iife/af.common.legacy.min.js +3 -3
- package/dist/iife/af.common.legacy.min.js.map +4 -4
- package/dist/iife/af.common.min.js +3 -3
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/getLocalizedString.js +12 -5
- package/es/index.js +1 -1
- package/package.json +2 -2
- package/src/getLocalizedString.ts +17 -17
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { has } from "./has";
|
|
2
|
+
|
|
3
|
+
async function getLocalizedStringAsync(text: string) {
|
|
2
4
|
try {
|
|
3
|
-
let response = await fetch(
|
|
4
|
-
body: JSON.stringify({
|
|
5
|
+
let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
|
|
6
|
+
body: JSON.stringify({ text }),
|
|
5
7
|
headers: {
|
|
6
8
|
Accept: "application/json; */*",
|
|
7
9
|
"Content-Type": "application/json",
|
|
@@ -15,18 +17,22 @@ async function getLocalizedStringAsync(string: string) {
|
|
|
15
17
|
}
|
|
16
18
|
} catch (error) {}
|
|
17
19
|
|
|
18
|
-
return
|
|
20
|
+
return text;
|
|
19
21
|
}
|
|
20
22
|
|
|
23
|
+
function afGetLocalizedString(string: undefined | null): undefined | null;
|
|
21
24
|
function afGetLocalizedString(string: string): string;
|
|
22
25
|
function afGetLocalizedString(string: string, wait: false): string;
|
|
23
26
|
function afGetLocalizedString(string: string, wait: true): Promise<string>;
|
|
24
|
-
function afGetLocalizedString(
|
|
25
|
-
string
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
function afGetLocalizedString(string: string | undefined | null, wait?: boolean): string | undefined | null | Promise<string> {
|
|
28
|
+
if(typeof string === "string" && string.trim().length === 0) {
|
|
29
|
+
return string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (string === undefined || string === '' || string === null) { return; }
|
|
33
|
+
|
|
28
34
|
if (af?.article?.i18n !== undefined) {
|
|
29
|
-
if (!
|
|
35
|
+
if (!has(af.article.i18n, string)) {
|
|
30
36
|
af.article.i18n[string] = string;
|
|
31
37
|
|
|
32
38
|
let promise = getLocalizedStringAsync(string).then((text) => {
|
|
@@ -101,17 +107,11 @@ function addDeveloperUtils() {
|
|
|
101
107
|
if (string) {
|
|
102
108
|
const escaped = string.replace(/'/g, "\\'");
|
|
103
109
|
if (forCustomRoute) {
|
|
104
|
-
const localized = afGetLocalizedString(string).replaceAll(
|
|
105
|
-
/'/g,
|
|
106
|
-
"\\'"
|
|
107
|
-
);
|
|
110
|
+
const localized = afGetLocalizedString(string).replaceAll(/'/g, "\\'");
|
|
108
111
|
strings.push(`'${escaped}': '${localized}',`);
|
|
109
112
|
} else {
|
|
110
113
|
strings.push(
|
|
111
|
-
`s['${escaped}'] = @Html(@context.AddLocalizableString("${string.replaceAll(
|
|
112
|
-
'"',
|
|
113
|
-
'\\"'
|
|
114
|
-
)}"));`
|
|
114
|
+
`s['${escaped}'] = @Html(@context.AddLocalizableString("${string.replaceAll('"', '\\"')}"));`
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
117
|
}
|