@jjlmoya/utils-shared 1.0.2 → 1.1.0
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/src/i18n.ts +100 -0
- package/src/index.ts +1 -0
- package/src/ui/Bibliography.astro +5 -2
- package/src/ui/FAQSection.astro +6 -3
package/package.json
CHANGED
package/src/i18n.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export const languages = {
|
|
2
|
+
es: "Español",
|
|
3
|
+
en: "English",
|
|
4
|
+
fr: "Français",
|
|
5
|
+
nl: "Nederlands",
|
|
6
|
+
de: "Deutsch",
|
|
7
|
+
it: "Italiano",
|
|
8
|
+
pt: "Português",
|
|
9
|
+
ja: "日本語",
|
|
10
|
+
zh: "中文",
|
|
11
|
+
ko: "한국어",
|
|
12
|
+
ru: "Русский",
|
|
13
|
+
pl: "Polski",
|
|
14
|
+
tr: "Türkçe",
|
|
15
|
+
sv: "Svenska",
|
|
16
|
+
hi: "हिन्दी",
|
|
17
|
+
} as const;
|
|
18
|
+
|
|
19
|
+
export type Language = keyof typeof languages;
|
|
20
|
+
|
|
21
|
+
export const defaultLanguage: Language = "es";
|
|
22
|
+
|
|
23
|
+
export const translations: Record<Language, { bibliographicReferences: string; faq: string }> = {
|
|
24
|
+
es: {
|
|
25
|
+
bibliographicReferences: "Referencias Bibliográficas",
|
|
26
|
+
faq: "Preguntas Frecuentes",
|
|
27
|
+
},
|
|
28
|
+
en: {
|
|
29
|
+
bibliographicReferences: "Bibliographic References",
|
|
30
|
+
faq: "Frequently Asked Questions",
|
|
31
|
+
},
|
|
32
|
+
fr: {
|
|
33
|
+
bibliographicReferences: "Références Bibliographiques",
|
|
34
|
+
faq: "Questions Fréquemment Posées",
|
|
35
|
+
},
|
|
36
|
+
nl: {
|
|
37
|
+
bibliographicReferences: "Bibliografische Referenties",
|
|
38
|
+
faq: "Veelgestelde Vragen",
|
|
39
|
+
},
|
|
40
|
+
de: {
|
|
41
|
+
bibliographicReferences: "Bibliographische Referenzen",
|
|
42
|
+
faq: "Häufig Gestellte Fragen",
|
|
43
|
+
},
|
|
44
|
+
it: {
|
|
45
|
+
bibliographicReferences: "Riferimenti Bibliografici",
|
|
46
|
+
faq: "Domande Frequenti",
|
|
47
|
+
},
|
|
48
|
+
pt: {
|
|
49
|
+
bibliographicReferences: "Referências Bibliográficas",
|
|
50
|
+
faq: "Perguntas Frequentes",
|
|
51
|
+
},
|
|
52
|
+
ja: {
|
|
53
|
+
bibliographicReferences: "参考文献",
|
|
54
|
+
faq: "よくある質問",
|
|
55
|
+
},
|
|
56
|
+
zh: {
|
|
57
|
+
bibliographicReferences: "参考文献",
|
|
58
|
+
faq: "常见问题",
|
|
59
|
+
},
|
|
60
|
+
ko: {
|
|
61
|
+
bibliographicReferences: "참고 문헌",
|
|
62
|
+
faq: "자주 묻는 질문",
|
|
63
|
+
},
|
|
64
|
+
ru: {
|
|
65
|
+
bibliographicReferences: "Библиографические ссылки",
|
|
66
|
+
faq: "Часто задаваемые вопросы",
|
|
67
|
+
},
|
|
68
|
+
pl: {
|
|
69
|
+
bibliographicReferences: "Referencje Bibliograficzne",
|
|
70
|
+
faq: "Najczęściej Zadawane Pytania",
|
|
71
|
+
},
|
|
72
|
+
tr: {
|
|
73
|
+
bibliographicReferences: "Bibliyografik Referanslar",
|
|
74
|
+
faq: "Sıkça Sorulan Sorular",
|
|
75
|
+
},
|
|
76
|
+
sv: {
|
|
77
|
+
bibliographicReferences: "Bibliografiska Referenser",
|
|
78
|
+
faq: "Vanliga Frågor",
|
|
79
|
+
},
|
|
80
|
+
hi: {
|
|
81
|
+
bibliographicReferences: "ग्रंथ सूची संदर्भ",
|
|
82
|
+
faq: "अक्सर पूछे जाने वाले प्रश्न",
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const getLanguageFromUrl = (url: URL | string): Language => {
|
|
87
|
+
const pathname = typeof url === "string" ? url : url.pathname;
|
|
88
|
+
const segments = pathname.split("/").filter(Boolean);
|
|
89
|
+
const firstSegment = segments[0];
|
|
90
|
+
|
|
91
|
+
if (firstSegment && firstSegment in translations) {
|
|
92
|
+
return firstSegment as Language;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return defaultLanguage;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const getTranslation = (language: Language, key: keyof (typeof translations)[Language]): string => {
|
|
99
|
+
return translations[language]?.[key] || translations[defaultLanguage][key];
|
|
100
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
import { Icon } from "astro-icon/components";
|
|
3
|
+
import { getLanguageFromUrl, getTranslation } from "../i18n";
|
|
3
4
|
|
|
4
5
|
interface Link {
|
|
5
6
|
name: string;
|
|
@@ -8,10 +9,12 @@ interface Link {
|
|
|
8
9
|
|
|
9
10
|
interface Props {
|
|
10
11
|
links: Link[];
|
|
11
|
-
title?: string;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const { links = []
|
|
14
|
+
const { links = [] } = Astro.props;
|
|
15
|
+
|
|
16
|
+
const language = getLanguageFromUrl(Astro.url);
|
|
17
|
+
const title = getTranslation(language, "bibliographicReferences");
|
|
15
18
|
---
|
|
16
19
|
|
|
17
20
|
<div class="bibliography">
|
package/src/ui/FAQSection.astro
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
import { Icon } from "astro-icon/components";
|
|
3
|
+
import { getLanguageFromUrl, getTranslation } from "../i18n";
|
|
3
4
|
|
|
4
5
|
interface FAQItem {
|
|
5
6
|
question: string;
|
|
@@ -8,11 +9,13 @@ interface FAQItem {
|
|
|
8
9
|
|
|
9
10
|
interface Props {
|
|
10
11
|
items: FAQItem[];
|
|
11
|
-
title?: string;
|
|
12
|
-
inLanguage?: string;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
|
-
const { items = []
|
|
14
|
+
const { items = [] } = Astro.props;
|
|
15
|
+
|
|
16
|
+
const language = getLanguageFromUrl(Astro.url);
|
|
17
|
+
const title = getTranslation(language, "faq");
|
|
18
|
+
const inLanguage = language === "es" ? "es-ES" : `${language}-${language.toUpperCase()}`;
|
|
16
19
|
|
|
17
20
|
const faqSchema = {
|
|
18
21
|
"@context": "https://schema.org",
|