add change language
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { ClassValue } from "clsx";
|
||||
import { clsx } from "clsx";
|
||||
import { getActiveI18n } from '@/i18n';
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
@@ -51,12 +52,18 @@ export function getImageAspectRatio(url: string): Promise<AspectInfo> {
|
||||
|
||||
|
||||
|
||||
const getRuntimeLocaleTag = () => {
|
||||
const locale = getActiveI18n()?.global.locale.value;
|
||||
return locale === 'vi' ? 'vi-VN' : 'en-US';
|
||||
};
|
||||
|
||||
export const formatBytes = (bytes?: number) => {
|
||||
if (!bytes) return '0 B';
|
||||
const k = 1024;
|
||||
const sizes = ['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];
|
||||
const value = parseFloat((bytes / Math.pow(k, i)).toFixed(2));
|
||||
return `${new Intl.NumberFormat(getRuntimeLocaleTag()).format(value)} ${sizes[i]}`;
|
||||
};
|
||||
|
||||
export const formatDuration = (seconds?: number) => {
|
||||
@@ -73,7 +80,7 @@ export const formatDuration = (seconds?: number) => {
|
||||
|
||||
export const formatDate = (dateString: string = "", dateOnly: boolean = false) => {
|
||||
if (!dateString) return '';
|
||||
return new Date(dateString).toLocaleDateString('en-US', {
|
||||
return new Date(dateString).toLocaleDateString(getRuntimeLocaleTag(), {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
|
||||
Reference in New Issue
Block a user