├── .env.local.example ├── src ├── lib │ ├── types │ │ └── types.d.ts │ ├── utils.ts │ └── hf.ts ├── app │ ├── icon.svg │ ├── sw.ts │ ├── api │ │ └── translate │ │ │ └── route.ts │ ├── manifest.ts │ ├── globals.css │ ├── about │ │ └── page.tsx │ ├── layout.tsx │ └── page.tsx └── components │ ├── home │ ├── tool-button.tsx │ ├── translate-button.tsx │ ├── lang-selector.tsx │ └── translation-fields.tsx │ └── header.tsx ├── .eslintrc.json ├── bun.lockb ├── public ├── icons │ ├── icon-192x192.png │ ├── icon-256x256.png │ ├── icon-384x384.png │ └── icon-512x512.png └── logo.svg ├── postcss.config.js ├── next.config.js ├── components.json ├── .gitignore ├── tsconfig.json ├── package.json ├── README.md └── tailwind.config.ts /.env.local.example: -------------------------------------------------------------------------------- 1 | HF_TOKEN= -------------------------------------------------------------------------------- /src/lib/types/types.d.ts: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xN1/translate-my/HEAD/bun.lockb -------------------------------------------------------------------------------- /public/icons/icon-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xN1/translate-my/HEAD/public/icons/icon-192x192.png -------------------------------------------------------------------------------- /public/icons/icon-256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xN1/translate-my/HEAD/public/icons/icon-256x256.png -------------------------------------------------------------------------------- /public/icons/icon-384x384.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xN1/translate-my/HEAD/public/icons/icon-384x384.png -------------------------------------------------------------------------------- /public/icons/icon-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0xN1/translate-my/HEAD/public/icons/icon-512x512.png -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /src/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import { type ClassValue, clsx } from "clsx" 2 | import { twMerge } from "tailwind-merge" 3 | 4 | export function cn(...inputs: ClassValue[]) { 5 | return twMerge(clsx(inputs)) 6 | } 7 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | 3 | const withSerwist = require("@serwist/next").default({ 4 | swSrc: "src/app/sw.ts", 5 | swDest: "public/sw.js", 6 | disable: process.env.NODE_ENV === "development", 7 | }); 8 | const nextConfig = {}; 9 | 10 | module.exports = withSerwist(nextConfig); 11 | -------------------------------------------------------------------------------- /components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "default", 4 | "rsc": true, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "tailwind.config.ts", 8 | "css": "src/app/globals.css", 9 | "baseColor": "zinc", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils" 16 | } 17 | } -------------------------------------------------------------------------------- /public/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/app/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | .yarn/install-state.gz 8 | 9 | # testing 10 | /coverage 11 | 12 | # next.js 13 | /.next/ 14 | /out/ 15 | 16 | # production 17 | /build 18 | 19 | # misc 20 | .DS_Store 21 | *.pem 22 | 23 | # debug 24 | npm-debug.log* 25 | yarn-debug.log* 26 | yarn-error.log* 27 | 28 | # local env files 29 | .env*.local 30 | 31 | # vercel 32 | .vercel 33 | 34 | # typescript 35 | *.tsbuildinfo 36 | next-env.d.ts 37 | 38 | # PWA 39 | /public/sw.js -------------------------------------------------------------------------------- /src/components/home/tool-button.tsx: -------------------------------------------------------------------------------- 1 | import { LucideProps } from "lucide-react"; 2 | 3 | const ToolButton = ({ 4 | icon: Icon, 5 | label, 6 | onClick, 7 | }: { 8 | icon: React.FC; 9 | label: string; 10 | onClick: () => void; 11 | }) => { 12 | return ( 13 | 20 | ); 21 | }; 22 | 23 | export default ToolButton; 24 | -------------------------------------------------------------------------------- /src/app/sw.ts: -------------------------------------------------------------------------------- 1 | import { defaultCache } from "@serwist/next/browser"; 2 | import type { PrecacheEntry } from "@serwist/precaching"; 3 | import { installSerwist } from "@serwist/sw"; 4 | 5 | declare const self: ServiceWorkerGlobalScope & { 6 | // Change this attribute's name to your `injectionPoint`. 7 | // `injectionPoint` is an InjectManifest option. 8 | // See https://serwist.pages.dev/docs/build/inject-manifest/configuring 9 | __SW_MANIFEST: (PrecacheEntry | string)[] | undefined; 10 | }; 11 | 12 | installSerwist({ 13 | precacheEntries: self.__SW_MANIFEST, 14 | skipWaiting: true, 15 | clientsClaim: true, 16 | navigationPreload: true, 17 | runtimeCaching: defaultCache, 18 | }); 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext", "webworker"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "noEmit": true, 9 | "esModuleInterop": true, 10 | "module": "esnext", 11 | "moduleResolution": "bundler", 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "jsx": "preserve", 15 | "incremental": true, 16 | "plugins": [ 17 | { 18 | "name": "next" 19 | } 20 | ], 21 | "paths": { 22 | "@/*": ["./src/*"] 23 | }, 24 | "types": ["@serwist/next/typings"] 25 | }, 26 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 27 | "exclude": ["node_modules"] 28 | } 29 | -------------------------------------------------------------------------------- /src/app/api/translate/route.ts: -------------------------------------------------------------------------------- 1 | import { NextRequest, NextResponse } from "next/server"; 2 | import { generateText } from "@/lib/hf"; 3 | 4 | export const maxDuration = 10; 5 | 6 | export async function GET(request: NextRequest) { 7 | const { searchParams } = new URL(request.url); 8 | 9 | const text = searchParams.get("text"); 10 | const lang = searchParams.get("lang"); 11 | 12 | if (!text || !lang) { 13 | return NextResponse.json( 14 | { 15 | error: "Missing text or language", 16 | }, 17 | { status: 400 }, 18 | ); 19 | } 20 | 21 | const res = await generateText({ text, lang }); 22 | 23 | if (!res) { 24 | return NextResponse.json( 25 | { 26 | error: "Failed to translate", 27 | }, 28 | { status: 500 }, 29 | ); 30 | } 31 | 32 | return NextResponse.json(res); 33 | } 34 | -------------------------------------------------------------------------------- /src/components/home/translate-button.tsx: -------------------------------------------------------------------------------- 1 | import { cn } from "@/lib/utils"; 2 | import { Languages } from "lucide-react"; 3 | 4 | const TranslateButton = ({ 5 | translate, 6 | mobile, 7 | }: { 8 | translate: () => Promise; 9 | mobile?: boolean; 10 | }) => { 11 | return ( 12 | 24 | ); 25 | }; 26 | 27 | export default TranslateButton; 28 | -------------------------------------------------------------------------------- /src/app/manifest.ts: -------------------------------------------------------------------------------- 1 | import { MetadataRoute } from "next"; 2 | 3 | export default function manifest(): MetadataRoute.Manifest { 4 | return { 5 | theme_color: "#F97316", 6 | background_color: "#ffffff", 7 | display: "standalone", 8 | orientation: "portrait", 9 | scope: "/", 10 | start_url: "/", 11 | name: "translateMY", 12 | short_name: "translateMY", 13 | description: 14 | "A translation tool for Malay and English with support for bahasa pasar and Manglish", 15 | icons: [ 16 | { 17 | src: "/icons/icon-192x192.png", 18 | sizes: "192x192", 19 | type: "image/png", 20 | }, 21 | { 22 | src: "/icons/icon-256x256.png", 23 | sizes: "256x256", 24 | type: "image/png", 25 | }, 26 | { 27 | src: "/icons/icon-384x384.png", 28 | sizes: "384x384", 29 | type: "image/png", 30 | }, 31 | { 32 | src: "/icons/icon-512x512.png", 33 | sizes: "512x512", 34 | type: "image/png", 35 | }, 36 | ], 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /src/components/home/lang-selector.tsx: -------------------------------------------------------------------------------- 1 | const LanguageSelector = ({ 2 | selectedLang, 3 | setSelectedLang, 4 | languages, 5 | }: { 6 | selectedLang: string; // Expect the value (e.g., "en", "ms") 7 | setSelectedLang: (value: string) => void; // Update the value 8 | languages: { label: string; value: string; experimental?: boolean }[]; 9 | }) => { 10 | return ( 11 | 29 | ); 30 | }; 31 | 32 | export default LanguageSelector; 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "translate-my", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@serwist/next": "^8.4.4", 13 | "@serwist/precaching": "^8.4.4", 14 | "@serwist/sw": "^8.4.4", 15 | "class-variance-authority": "^0.7.0", 16 | "clsx": "^2.1.0", 17 | "geist": "^1.1.0", 18 | "lucide-react": "^0.317.0", 19 | "next": "latest", 20 | "react": "latest", 21 | "react-dom": "latest", 22 | "react-use-websocket": "^4.5.0", 23 | "tailwind-merge": "^2.2.1", 24 | "tailwindcss-animate": "^1.0.7", 25 | "usehooks-ts": "^2.10.0", 26 | "uuid": "^9.0.1" 27 | }, 28 | "devDependencies": { 29 | "@gradio/client": "^0.8.1", 30 | "@types/node": "^20", 31 | "@types/react": "^18", 32 | "@types/react-dom": "^18", 33 | "autoprefixer": "^10.0.1", 34 | "eslint": "^8", 35 | "eslint-config-next": "latest", 36 | "postcss": "^8", 37 | "tailwind-scrollbar": "^3.0.5", 38 | "tailwindcss": "^3.3.0", 39 | "typescript": "^5" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/lib/hf.ts: -------------------------------------------------------------------------------- 1 | import { cache } from "react"; 2 | 3 | type PredictData = { 4 | text: string; 5 | lang: string; 6 | time?: number; 7 | }; 8 | 9 | export const generateText = async ({ text, lang }: PredictData) => { 10 | const response = await fetch( 11 | "https://api.mesolitica.com/translation/public", 12 | { 13 | method: "POST", 14 | headers: { 15 | "Content-Type": "application/json", 16 | }, 17 | body: JSON.stringify({ 18 | input: `${text}`, 19 | model: "base", 20 | to_lang: lang, 21 | top_k: 1, 22 | top_p: 1, 23 | repetition_penalty: 1.1, 24 | temperature: 0, 25 | }), 26 | }, 27 | ); 28 | 29 | const output = await response.json(); 30 | 31 | console.log("Response from API:", output); 32 | 33 | if (!output || !output.result) { 34 | throw new Error("Failed to generate text"); 35 | } 36 | 37 | return { 38 | text: output.result, 39 | lang: lang, 40 | usage: output.usage || {}, 41 | }; 42 | }; 43 | 44 | export const translateText = cache(async (text: string, lang: string) => { 45 | if (!text || !lang) { 46 | throw new Error("Missing text or language"); 47 | } 48 | 49 | const result = await generateText({ text, lang }); 50 | 51 | if (!result) { 52 | throw new Error("Failed to translate"); 53 | } 54 | 55 | return result; 56 | }); 57 | -------------------------------------------------------------------------------- /src/components/header.tsx: -------------------------------------------------------------------------------- 1 | import { BookOpen, Github, Settings } from "lucide-react"; 2 | import Link from "next/link"; 3 | import React from "react"; 4 | 5 | type Props = {}; 6 | 7 | const Header = (props: Props) => { 8 | return ( 9 |
10 |
11 | 12 |
13 | logo 14 | translateMY{" "} 15 |
16 | 17 | 18 | model by{" "} 19 | 25 | mesolitica 26 | 27 | 28 |
29 |
30 | 36 | 37 | 38 | 39 | 40 | 41 | {/* 42 | 43 | */} 44 |
45 |
46 | ); 47 | }; 48 | 49 | export default Header; 50 | -------------------------------------------------------------------------------- /src/app/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | * { 6 | min-width: 0; 7 | } 8 | 9 | @layer base { 10 | :root { 11 | --background: 0 0% 100%; 12 | --foreground: 240 10% 3.9%; 13 | 14 | --card: 0 0% 100%; 15 | --card-foreground: 240 10% 3.9%; 16 | 17 | --popover: 0 0% 100%; 18 | --popover-foreground: 240 10% 3.9%; 19 | 20 | --primary: 240 5.9% 10%; 21 | --primary-foreground: 0 0% 98%; 22 | 23 | --secondary: 240 4.8% 95.9%; 24 | --secondary-foreground: 240 5.9% 10%; 25 | 26 | --muted: 240 4.8% 95.9%; 27 | --muted-foreground: 240 3.8% 46.1%; 28 | 29 | --accent: 240 4.8% 95.9%; 30 | --accent-foreground: 240 5.9% 10%; 31 | 32 | --destructive: 0 84.2% 60.2%; 33 | --destructive-foreground: 0 0% 98%; 34 | 35 | --border: 240 5.9% 90%; 36 | --input: 240 5.9% 90%; 37 | --ring: 240 10% 3.9%; 38 | 39 | --radius: 0.5rem; 40 | } 41 | 42 | .dark { 43 | --background: 240 10% 3.9%; 44 | --foreground: 0 0% 98%; 45 | 46 | --card: 240 10% 3.9%; 47 | --card-foreground: 0 0% 98%; 48 | 49 | --popover: 240 10% 3.9%; 50 | --popover-foreground: 0 0% 98%; 51 | 52 | --primary: 0 0% 98%; 53 | --primary-foreground: 240 5.9% 10%; 54 | 55 | --secondary: 240 3.7% 15.9%; 56 | --secondary-foreground: 0 0% 98%; 57 | 58 | --muted: 240 3.7% 15.9%; 59 | --muted-foreground: 240 5% 64.9%; 60 | 61 | --accent: 240 3.7% 15.9%; 62 | --accent-foreground: 0 0% 98%; 63 | 64 | --destructive: 0 62.8% 30.6%; 65 | --destructive-foreground: 0 0% 98%; 66 | 67 | --border: 240 3.7% 15.9%; 68 | --input: 240 3.7% 15.9%; 69 | --ring: 240 4.9% 83.9%; 70 | } 71 | } 72 | 73 | @layer base { 74 | * { 75 | @apply border-border; 76 | } 77 | body { 78 | @apply bg-background text-foreground; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/app/about/page.tsx: -------------------------------------------------------------------------------- 1 | import Header from "@/components/header"; 2 | import Link from "next/link"; 3 | import React from "react"; 4 | 5 | type Props = {}; 6 | 7 | const AboutPage = (props: Props) => { 8 | return ( 9 |
10 |
11 |
12 |

about

13 |
14 |

15 | site built by{" "} 16 | 22 | 0xN1 23 | 24 |

25 |

26 | translation model by{" "} 27 | 33 | mesolitica 34 | 35 |

36 |

made in malaysia

37 |
38 |
39 |

ref:

40 | 41 | 47 | mesolitica translation 48 | 49 | 50 |

51 |
52 |
53 |
54 |
55 | ); 56 | }; 57 | 58 | export default AboutPage; 59 | -------------------------------------------------------------------------------- /src/components/home/translation-fields.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { cn } from "@/lib/utils"; 3 | 4 | const TranslationFields = ({ 5 | inputText, 6 | setInputText, 7 | translatedText, 8 | translate, 9 | horizontal, 10 | }: { 11 | inputText: string; 12 | setInputText: (text: string) => void; 13 | translatedText: string; 14 | translate: () => void; 15 | horizontal: boolean; 16 | }) => { 17 | return ( 18 |
26 |
27 | Input 28 |