@ikas/storefront-next 4.0.0-alpha.10

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.
@@ -0,0 +1,52 @@
1
+ import { IkasThemeJsonFontFamily } from "@ikas/storefront-models";
2
+
3
+ export const getGoogleFontHref = (fontFamily: IkasThemeJsonFontFamily) => {
4
+ if (!fontFamily.name) return;
5
+
6
+ const fontName = fontFamily.name.replace(/ /g, "+");
7
+ let fontVariants = "";
8
+
9
+ if (fontFamily.variants) {
10
+ fontVariants += ":";
11
+ const isItalic = fontFamily.variants.some(
12
+ (variant) => variant === "italic"
13
+ );
14
+ if (isItalic) {
15
+ fontVariants += "ital,";
16
+ }
17
+
18
+ fontVariants += "wght@";
19
+
20
+ if (isItalic) {
21
+ const search = "italic";
22
+ const checkItalic = new RegExp(search, "i");
23
+ fontVariants += fontFamily.variants.reduce((str, variant) => {
24
+ if (!checkItalic.test(variant)) {
25
+ return str + `0,${variant.replace("regular", "400")};`;
26
+ } else {
27
+ return str;
28
+ }
29
+ }, "");
30
+
31
+ fontVariants += fontFamily.variants.reduce((str, variant) => {
32
+ if (checkItalic.test(variant)) {
33
+ return (
34
+ str +
35
+ `1,${variant === "italic" ? "400" : variant.replace("italic", "")};`
36
+ );
37
+ } else {
38
+ return str;
39
+ }
40
+ }, "");
41
+ } else {
42
+ fontVariants += fontFamily.variants.reduce((str, variant) => {
43
+ return str + `${variant.replace("regular", "400")};`;
44
+ }, "");
45
+ }
46
+
47
+ fontVariants = fontVariants.substring(0, fontVariants.length - 1);
48
+ fontVariants += "&display=swap";
49
+ }
50
+
51
+ return `https://fonts.googleapis.com/css2?family=${fontName}${fontVariants}`;
52
+ };
@@ -0,0 +1,80 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export const CHECKOUT_TRANSLATION_NAMESPACE = "checkout-page";
5
+
6
+ export class I18NFileReader {
7
+ locale: string;
8
+ namespaces: string[];
9
+ localePath?: string;
10
+
11
+ constructor(locale: string, namespaces: string[], localePath?: string) {
12
+ this.locale = locale;
13
+ this.namespaces = namespaces;
14
+ this.localePath = localePath;
15
+ }
16
+
17
+ async read(): Promise<Record<string, any>> {
18
+ const translations: Record<string, any> = {};
19
+
20
+ for (const namespace of this.namespaces) {
21
+ try {
22
+ const filePath = this.localePath
23
+ ? path.join(this.localePath, this.locale, namespace + ".json")
24
+ : path.join(
25
+ process.cwd(),
26
+ "public",
27
+ "locales",
28
+ this.locale,
29
+ namespace + ".json"
30
+ );
31
+ const fileExists = fs.existsSync(filePath);
32
+
33
+ if (fileExists) {
34
+ const localeTranslation = await this.readLocaleFile(filePath);
35
+ translations[namespace] = localeTranslation;
36
+ } else if (namespace === CHECKOUT_TRANSLATION_NAMESPACE) {
37
+ let checkoutTranslation: Record<string, any> = {};
38
+
39
+ if (this.locale === "tr") {
40
+ const imported = await import(
41
+ //@ts-ignore
42
+ "@ikas/storefront-assets/checkout/tr.js"
43
+ );
44
+ checkoutTranslation = imported.default;
45
+ } else {
46
+ const imported = await import(
47
+ //@ts-ignore
48
+ "@ikas/storefront-assets/checkout/en.js"
49
+ );
50
+ checkoutTranslation = imported.default;
51
+ }
52
+
53
+ translations[namespace] = checkoutTranslation;
54
+ }
55
+ } catch (err) {
56
+ console.error(err);
57
+ }
58
+ }
59
+
60
+ return translations;
61
+ }
62
+
63
+ private async readLocaleFile(filePath: string): Promise<Record<string, any>> {
64
+ return new Promise((resolve, reject) => {
65
+ fs.readFile(
66
+ filePath,
67
+ {
68
+ flag: "r",
69
+ },
70
+ function (err, file) {
71
+ if (err) {
72
+ return reject(err);
73
+ }
74
+ const result = file.length ? JSON.parse(file.toString()) : {};
75
+ resolve(result);
76
+ }
77
+ );
78
+ });
79
+ }
80
+ }