Skip to content

Commit 5aec13c

Browse files
Add files via upload
Signed-off-by: FireMoonStudio <firemoongamesstudio@gmail.com>
1 parent f776b7a commit 5aec13c

19 files changed

+941
-0
lines changed

i18n/translate.ts

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import { get } from '../helpers/object';
2+
import { logger } from '../logging/logger';
3+
import type { Translation } from '../models/i18n/translation';
4+
import { translation as langAr } from './translations/lang-ar';
5+
import { translation as langCs } from './translations/lang-cs';
6+
import { translation as langDe } from './translations/lang-de';
7+
import { translation as langEn } from './translations/lang-en';
8+
import { translation as langEs } from './translations/lang-es';
9+
import { translation as langFr } from './translations/lang-fr';
10+
import { translation as langId } from './translations/lang-id';
11+
import { translation as langIt } from './translations/lang-it';
12+
import { translation as langJa } from './translations/lang-ja';
13+
import { translation as langKo } from './translations/lang-ko';
14+
import { translation as langNl } from './translations/lang-nl';
15+
import { translation as langPl } from './translations/lang-pl';
16+
import { translation as langPtBr } from './translations/lang-pt-br';
17+
import { translation as langPtPt } from './translations/lang-pt-pt';
18+
import { translation as langRu } from './translations/lang-ru';
19+
import { translation as langUk } from './translations/lang-uk';
20+
import { translation as langZhCn } from './translations/lang-zh-cn';
21+
import { translation as langZhTw } from './translations/lang-zh-tw';
22+
23+
24+
let currentTranslation: Translation;
25+
let fallbackTranslation: Translation;
26+
27+
const placeholder = '%';
28+
29+
/** Initialize the translations */
30+
export const initTranslations = async (language: string) => {
31+
try {
32+
currentTranslation = await loadTranslation(language);
33+
fallbackTranslation = await loadTranslation('en');
34+
logger.info('Translations initialized.');
35+
} catch (error) {
36+
logger.error(error);
37+
}
38+
};
39+
40+
/** Load the required translation */
41+
const loadTranslation = async (language: string) => {
42+
try {
43+
return await getTranslationObject(language);
44+
} catch {
45+
return await getTranslationObject('en');
46+
}
47+
};
48+
49+
/** Get the translation object of the separated translation files */
50+
const getTranslationObject = async (language: string): Promise<Translation> => {
51+
switch (language) {
52+
case 'ar':
53+
return langAr;
54+
case 'cs':
55+
return langCs;
56+
case 'de':
57+
return langDe;
58+
case 'en':
59+
return langEn;
60+
case 'es':
61+
return langEs;
62+
case 'fr':
63+
return langFr;
64+
case 'id':
65+
return langId;
66+
case 'it':
67+
return langIt;
68+
case 'ja':
69+
return langJa;
70+
case 'ko':
71+
return langKo;
72+
case 'nl':
73+
return langNl;
74+
case 'pl':
75+
return langPl;
76+
case 'pt-br':
77+
return langPtBr;
78+
case 'pt-pt':
79+
return langPtPt;
80+
case 'ru':
81+
return langRu;
82+
case 'uk':
83+
return langUk;
84+
case 'zh-cn':
85+
return langZhCn;
86+
case 'zh-tw':
87+
return langZhTw;
88+
default:
89+
return langEn;
90+
}
91+
};
92+
93+
/**
94+
* We look up the matching translation in the translation files.
95+
* If we cannot find a matching key in the file we use the fallback.
96+
* With optional parameters you can configure both the translations
97+
* and the fallback (required for testing purposes).
98+
* */
99+
export const getTranslationValue = (
100+
key: string,
101+
translations = currentTranslation,
102+
fallback = fallbackTranslation
103+
): string | undefined => {
104+
return get(translations, key) ?? get(fallback, key);
105+
};
106+
107+
/**
108+
* The instant method is required for the translate pipe.
109+
* It helps to translate a word instantly.
110+
*/
111+
export const translate = (key: string, ...variables: string[]): string => {
112+
const translation = getTranslationValue(key);
113+
114+
if (variables.length === 0) return translation ?? key;
115+
return replace(translation, ...variables);
116+
};
117+
118+
/**
119+
* The replace function will replace the current placeholder with the
120+
* data parameter from the translation. You can give it one or more optional
121+
* parameters ('variables').
122+
*/
123+
export const replace = (value: string = '', ...variables: string[]) => {
124+
let translation: string = value;
125+
variables.forEach((variable, i) => {
126+
translation = translation.replace(`${placeholder}${i}`, variable);
127+
});
128+
129+
return translation;
130+
};

i18n/translations/lang-ar.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import type { Translation } from '../../models/i18n/translation';
2+
3+
export const translation: Translation = {
4+
activate: 'تفعيل',
5+
activated: 'تم تفعيل Material Icon Theme.',
6+
iconPacks: {
7+
selectPack: 'اختر حزمة الأيقونات',
8+
description: "اختر حزمة الأيقونات '%0'",
9+
disabled: 'تعطيل حزم الأيقونات',
10+
},
11+
folders: {
12+
toggleIcons: 'اختر سمة المجلد',
13+
disabled: 'بدون أيقونات مجلدات',
14+
theme: {
15+
description: "اختر سمة المجلد '%0'",
16+
},
17+
},
18+
colorSelect: {
19+
color: 'اختر لونًا',
20+
hexCode: 'أدخل كود لون HEX',
21+
wrongHexCode: 'كود HEX غير صالح!',
22+
},
23+
opacity: {
24+
inputPlaceholder: 'قيمة الشفافية (بين 0 و 1)',
25+
wrongValue: 'يرجى إدخال رقم عشري بين 0 و 1.',
26+
},
27+
toggleSwitch: {
28+
on: 'تشغيل',
29+
off: 'إيقاف',
30+
},
31+
explorerArrows: {
32+
toggle: 'تبديل أسهم المجلدات في المستكشف',
33+
enable: 'إظهار أسهم المجلدات في المستكشف',
34+
disable: 'إخفاء أسهم المجلدات في المستكشف',
35+
},
36+
grayscale: {
37+
toggle: 'تبديل الأيقونات الرمادية',
38+
enable: 'تفعيل الأيقونات الرمادية',
39+
disable: 'تعطيل الأيقونات الرمادية',
40+
},
41+
saturation: {
42+
inputPlaceholder: 'قيمة التشبع (بين 0 و 1)',
43+
wrongValue: 'يرجى إدخال رقم عشري بين 0 و 1.',
44+
},
45+
46+
};

i18n/translations/lang-cs.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { Translation } from '../../models/i18n/translation';
2+
3+
export const translation: Translation = {
4+
activate: 'Aktivovat',
5+
activated: 'Material Icon Téma je aktivní.',
6+
iconPacks: {
7+
selectPack: 'Vyberte sadu ikon',
8+
description: "Vyberte sadu ikon '%0'",
9+
disabled: 'Zakázat balíčky ikon',
10+
},
11+
folders: {
12+
toggleIcons: 'Vyberte motiv složky',
13+
disabled: 'Žádné ikony složek',
14+
theme: {
15+
description: "Vyberte motiv složky '%0'",
16+
},
17+
},
18+
colorSelect: {
19+
color: 'Vyberte barvu',
20+
hexCode: 'Vložte hexadecimální kód barvy',
21+
wrongHexCode: 'Neplatný hexadecimální kód barvy!',
22+
},
23+
opacity: {
24+
inputPlaceholder: 'Hodnota průhlednosti (od 0 do 1)',
25+
wrongValue: 'Zadejte desetinné číslo mezi 0 a 1.',
26+
},
27+
toggleSwitch: {
28+
on: 'ZAPNUTO',
29+
off: 'VYPNUTO',
30+
},
31+
explorerArrows: {
32+
toggle: 'Šipky složek v průzkumníkovi',
33+
enable: 'Zobrazit šipky složek v Průzkumníkovi',
34+
disable: 'Skrýt šipky složek v Průzkumníkovi',
35+
},
36+
grayscale: {
37+
toggle: 'Zobrazovat ikony ve stupních šedi',
38+
enable: 'Povolit ikony ve stupních šedi',
39+
disable: 'Zakázat ikony ve stupních šedi',
40+
},
41+
saturation: {
42+
inputPlaceholder: 'Hodnota sytosti (mezi 0 a 1)',
43+
wrongValue: 'Zadejte desetinné číslo mezi 0 a 1.',
44+
},
45+
};

i18n/translations/lang-de.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { Translation } from '../../models/i18n/translation';
2+
3+
export const translation: Translation = {
4+
activate: 'Aktivieren',
5+
activated: 'Material Icon Theme ist jetzt aktiviert.',
6+
iconPacks: {
7+
selectPack: 'Icon Pack auswählen',
8+
description: "Das '%0' Icon Pack auswählen",
9+
disabled: 'Icon Packs deaktivieren',
10+
},
11+
folders: {
12+
toggleIcons: 'Wähle ein Ordner Design',
13+
disabled: 'Keine Ordner Icons',
14+
theme: {
15+
description: "Wähle das '%0' Design",
16+
},
17+
},
18+
colorSelect: {
19+
color: 'Wähle eine Farbe',
20+
hexCode: 'Gebe einen HEX Farbcode ein',
21+
wrongHexCode: 'Ungültiger HEX Farbcode',
22+
},
23+
opacity: {
24+
inputPlaceholder: 'Wert der Deckkraft (zwischen 0 und 1)',
25+
wrongValue: 'Der Wert muss zwischen 0 und 1 liegen!',
26+
},
27+
toggleSwitch: {
28+
on: 'EIN',
29+
off: 'AUS',
30+
},
31+
explorerArrows: {
32+
toggle: 'Pfeile im Explorer anpassen',
33+
enable: 'Explorer Pfeile anzeigen',
34+
disable: 'Explorer Pfeile ausblenden',
35+
},
36+
grayscale: {
37+
toggle: 'Schaltet graustufige Icons um',
38+
enable: 'Aktiviert graustufige Icons',
39+
disable: 'Deaktiviert graustufige Icons',
40+
},
41+
saturation: {
42+
inputPlaceholder: 'Wert der Sättigung (zwischen 0 und 1)',
43+
wrongValue: 'Der Wert muss zwischen 0 und 1 liegen!',
44+
},
45+
};

i18n/translations/lang-en.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { Translation } from '../../models/i18n/translation';
2+
3+
export const translation: Translation = {
4+
activate: 'Activate',
5+
activated: 'Material Icon Theme is active.',
6+
iconPacks: {
7+
selectPack: 'Select an icon pack',
8+
description: "Select the '%0' icon pack",
9+
disabled: 'Disable icon packs',
10+
},
11+
folders: {
12+
toggleIcons: 'Pick a folder theme',
13+
disabled: 'No folder icons',
14+
theme: {
15+
description: "Select the '%0' folder theme",
16+
},
17+
},
18+
colorSelect: {
19+
color: 'Choose a color',
20+
hexCode: 'Insert a HEX color code',
21+
wrongHexCode: 'Invalid HEX color code!',
22+
},
23+
opacity: {
24+
inputPlaceholder: 'Opacity value (between 0 and 1)',
25+
wrongValue: 'Please enter a floating-point number between 0 and 1.',
26+
},
27+
toggleSwitch: {
28+
on: 'ON',
29+
off: 'OFF',
30+
},
31+
explorerArrows: {
32+
toggle: 'Toggle folder arrows in Explorer',
33+
enable: 'Show folder arrows in Explorer',
34+
disable: 'Hide folder arrows in Explorer',
35+
},
36+
grayscale: {
37+
toggle: 'Toggle grayscale icons',
38+
enable: 'Enable grayscale icons',
39+
disable: 'Disable grayscale icons',
40+
},
41+
saturation: {
42+
inputPlaceholder: 'Saturation value (between 0 and 1)',
43+
wrongValue: 'Please enter a floating-point number between 0 and 1.',
44+
},
45+
};

i18n/translations/lang-es.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { Translation } from '../../models/i18n/translation';
2+
3+
export const translation: Translation = {
4+
activate: 'Activar',
5+
activated: 'Material Icon Theme está activado.',
6+
iconPacks: {
7+
selectPack: 'Seleccione un paquete de iconos',
8+
description: "Seleccione el paquete de iconos '%0'",
9+
disabled: 'Desactivar paquetes de iconos',
10+
},
11+
folders: {
12+
toggleIcons: 'Cambiar activación de iconos de carpetas',
13+
disabled: 'Sin iconos de carpeta',
14+
theme: {
15+
description: "Iconos de carpeta '%0'",
16+
},
17+
},
18+
colorSelect: {
19+
color: 'Elija un color',
20+
hexCode: 'Insertar un código de color HEX',
21+
wrongHexCode: '¡Código de color HEX inválido!',
22+
},
23+
opacity: {
24+
inputPlaceholder: 'Valor de opacidad (entre 0 y 1)',
25+
wrongValue: '¡El valor debe estar entre 0 y 1!',
26+
},
27+
toggleSwitch: {
28+
on: 'ON',
29+
off: 'OFF',
30+
},
31+
explorerArrows: {
32+
toggle: 'Conmutar las flechas de carpetas',
33+
enable: 'Mostrar flechas de carpeta',
34+
disable: 'Ocultar las flechas de carpetas',
35+
},
36+
grayscale: {
37+
toggle: 'Alternar los iconos en escala de grises',
38+
enable: 'Activar los iconos en escala de grises',
39+
disable: 'Desactivar los iconos en escala de grises',
40+
},
41+
saturation: {
42+
inputPlaceholder: 'Valor de saturación (entre 0 y 1)',
43+
wrongValue: 'El valor debe estar entre 0 y 1.',
44+
},
45+
};

0 commit comments

Comments
 (0)