Skip to content

Commit

Permalink
fixing moment locale
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasheartcliff committed Feb 26, 2024
1 parent ee315f4 commit fff59f9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
86 changes: 43 additions & 43 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import moment from 'moment';
import moment from "moment";

export const secondToHours = (value: number) => value * (1 / 3600);
export const formatTime = (seconds: number) => {
Expand All @@ -9,48 +9,48 @@ export const formatTime = (seconds: number) => {
return formattedTime;
};
export const capitalize = (text: string) => {
if (!text) return '';
if (!text) return "";
return text
.split(' ')
.split(" ")
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
.join(" ");
};

const languageColors: { [key: string]: string } = {
C: '#555555',
'C++': '#f34b7d',
JAVA: '#b07219',
PYTHON: '#3572A5',
JAVASCRIPT: '#f1e05a',
HTML: '#e34c26',
CSS: '#563d7c',
RUBY: '#701516',
SWIFT: '#ffac45',
KOTLIN: '#F18E33',
GO: '#00ADD8',
TYPESCRIPT: '#2b7489',
PHP: '#4F5D95',
MATLAB: '#e16737',
PERL: '#0298c3',
R: '#198ce7',
SHELL: '#89e051',
SQL: '#e38c33',
RUST: '#dea584',
LUA: '#000080',
C: "#555555",
"C++": "#f34b7d",
JAVA: "#b07219",
PYTHON: "#3572A5",
JAVASCRIPT: "#f1e05a",
HTML: "#e34c26",
CSS: "#563d7c",
RUBY: "#701516",
SWIFT: "#ffac45",
KOTLIN: "#F18E33",
GO: "#00ADD8",
TYPESCRIPT: "#2b7489",
PHP: "#4F5D95",
MATLAB: "#e16737",
PERL: "#0298c3",
R: "#198ce7",
SHELL: "#89e051",
SQL: "#e38c33",
RUST: "#dea584",
LUA: "#000080",
};

export const getLanguageColor = (lang: string) =>
languageColors[lang?.toUpperCase()] || '#000000';
languageColors[lang?.toUpperCase()] || "#000000";

export const isProgrammingLanguage = (lang: string) => {
return lang ? lang.toUpperCase() in languageColors : false;
};

const platformsColor: { [k: string]: string } = {
ALURA: '#5ea3d0',
UDEMY: '#A435F0',
CISCO: '#049fd9',
OTHERS: '#049fd9',
ALURA: "#5ea3d0",
UDEMY: "#A435F0",
CISCO: "#049fd9",
OTHERS: "#049fd9",
};

export const getPlatformColor = (platform: string) => {
Expand All @@ -60,30 +60,30 @@ export const getPlatformColor = (platform: string) => {

export function mapLocaleToMoment(i18nLocale: string | undefined) {
const localeMap: { [k: string]: string } = {
pt: 'pt-br',
en: 'en',
fr: 'fr',
es: 'es',
ko: 'ko',
ja: 'ja',
de: 'de',
it: 'it',
zh: 'zh-cn',
ar: 'ar-sa',
pt: "pt-br",
en: "en",
fr: "fr",
es: "es",
ko: "ko",
ja: "ja",
de: "de",
it: "it",
zh: "zh-cn",
ar: "ar-sa",
};
const i = i18nLocale || 'en';
const i = i18nLocale || "en";

return i in localeMap ? localeMap[i] : localeMap.en; // Default to English if no matching locale found
}

export async function setLocale(locale?: string) {
const momentLocale = mapLocaleToMoment(locale) as string;
if (!locale || locale === 'en') {
if (!locale || locale === "en") {
moment.locale(locale);
} else {
const localeData =(await import(`moment/locale/${momentLocale}`)).default;
const localeData = (await import(`moment/locale/${momentLocale}`)).default;
// Set the locale for Moment.js
moment.updateLocale(momentLocale, localeData);
// moment.updateLocale(momentLocale, localeData);
moment.locale(momentLocale);
}
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"allowUnreachableCode": false,
"noFallthroughCasesInSwitch": true,

Expand Down

0 comments on commit fff59f9

Please sign in to comment.