Spaces:
Build error
Build error
File size: 3,559 Bytes
0bfe2e3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
export function formatBytes(bytes: number, k: 1024 | 1000): string {
if (bytes === 0) return '0 B';
const sizes =
k === 1024
? ['B', 'KiB', 'MiB', 'GiB', 'TiB']
: ['B', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
export function formatDuration(durationInMs: number): string {
const seconds = Math.floor(durationInMs / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
const formattedSeconds = seconds % 60;
const formattedMinutes = minutes % 60;
if (hours > 0) {
return `${hours}h:${formattedMinutes}m:${formattedSeconds}s`;
} else if (formattedSeconds > 0) {
return `${formattedMinutes}m:${formattedSeconds}s`;
} else {
return `${formattedMinutes}m`;
}
}
export function languageToEmoji(language: string): string | undefined {
return languageEmojiMap[language.toLowerCase()];
}
export function emojiToLanguage(emoji: string): string | undefined {
return Object.entries(languageEmojiMap).find(
([_, value]) => value === emoji
)?.[0];
}
export function codeToLanguage(code: string): string | undefined {
return codeLanguageMap[code];
}
/**
* A mapping of language names to their corresponding emoji flags.
*
* This mapping was adapted from the g0ldy/comet project.
* https://github.com/g0ldyy/comet/blob/de5413425ac30a9d88bc7176862a7ff02027eb7f/comet/utils/general.py#L19C1-L19C18
*/
const languageEmojiMap: Record<string, string> = {
multi: '๐',
english: '๐ฌ๐ง',
japanese: '๐ฏ๐ต',
chinese: '๐จ๐ณ',
russian: '๐ท๐บ',
arabic: '๐ธ๐ฆ',
portuguese: '๐ต๐น',
spanish: '๐ช๐ธ',
french: '๐ซ๐ท',
german: '๐ฉ๐ช',
italian: '๐ฎ๐น',
korean: '๐ฐ๐ท',
hindi: '๐ฎ๐ณ',
bengali: '๐ง๐ฉ',
punjabi: '๐ต๐ฐ',
marathi: '๐ฎ๐ณ',
gujarati: '๐ฎ๐ณ',
tamil: '๐ฎ๐ณ',
telugu: '๐ฎ๐ณ',
kannada: '๐ฎ๐ณ',
malayalam: '๐ฎ๐ณ',
thai: '๐น๐ญ',
vietnamese: '๐ป๐ณ',
indonesian: '๐ฎ๐ฉ',
turkish: '๐น๐ท',
hebrew: '๐ฎ๐ฑ',
persian: '๐ฎ๐ท',
ukrainian: '๐บ๐ฆ',
greek: '๐ฌ๐ท',
lithuanian: '๐ฑ๐น',
latvian: '๐ฑ๐ป',
estonian: '๐ช๐ช',
polish: '๐ต๐ฑ',
czech: '๐จ๐ฟ',
slovak: '๐ธ๐ฐ',
hungarian: '๐ญ๐บ',
romanian: '๐ท๐ด',
bulgarian: '๐ง๐ฌ',
serbian: '๐ท๐ธ',
croatian: '๐ญ๐ท',
slovenian: '๐ธ๐ฎ',
dutch: '๐ณ๐ฑ',
danish: '๐ฉ๐ฐ',
finnish: '๐ซ๐ฎ',
swedish: '๐ธ๐ช',
norwegian: '๐ณ๐ด',
malay: '๐ฒ๐พ',
latino: '๐๐ป',
Latino: '๐ฒ๐ฝ',
};
const codeLanguageMap: Record<string, string> = {
EN: 'english',
JA: 'japanese',
ZH: 'chinese',
RU: 'russian',
AR: 'arabic',
PT: 'portuguese',
ES: 'spanish',
FR: 'french',
DE: 'german',
IT: 'italian',
KO: 'korean',
HI: 'hindi',
BN: 'bengali',
PA: 'punjabi',
MR: 'marathi',
GU: 'gujarati',
TA: 'tamil',
TE: 'telugu',
KN: 'kannada',
ML: 'malayalam',
TH: 'thai',
VI: 'vietnamese',
ID: 'indonesian',
TR: 'turkish',
HE: 'hebrew',
FA: 'persian',
UK: 'ukrainian',
EL: 'greek',
LT: 'lithuanian',
LV: 'latvian',
ET: 'estonian',
PL: 'polish',
CS: 'czech',
SK: 'slovak',
HU: 'hungarian',
RO: 'romanian',
BG: 'bulgarian',
SR: 'serbian',
HR: 'croatian',
SL: 'slovenian',
NL: 'dutch',
DA: 'danish',
FI: 'finnish',
SV: 'swedish',
NO: 'norwegian',
MS: 'malay',
LA: 'latino',
MX: 'Latino',
};
|