Share this guide
Help more farmers discover useful tools
Save Time
Instant access
More Benefits
Apply for schemes
Better Decisions
Real-time data
Transparent & Safe
Official platforms
If you build an app for a farmer in Nashik or a trader in Haveri using standard English UI patterns, you’ve already lost. In the Indian agri-tech landscape, English isn't just a barrier; it’s a trust-killer. When we started building KhetiSetu, we knew that supporting Hindi, Marathi, and Kannada wasn't a "nice-to-have" feature—it was the core product requirement.
The challenge with multilingual apps in the Indian context isn't just swapping strings. It’s about handling varying script densities, managing "Hinglish" terminology that farmers actually use, and ensuring that a low-end Android device on a 3G connection doesn't choke on massive translation bundles.
Here is how we architected our Next.js App Router to handle high-performance localization across three major Indian languages.
The Architecture: Middleware-based Routing
We opted for a sub-path routing strategy (e.g., /hi/mandi, /kn/mandi). This is superior to cookie-only localization because it allows farmers to share links via WhatsApp that preserve the language context. If a farmer in Karnataka shares a crop listing with a peer, the recipient should see it in Kannada immediately.
In Next.js, we leverage the middleware.ts to intercept requests and redirect users based on their preferred language or geographic IP if no locale is present.
// middleware.ts
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { match as matchLocale } from '@formatjs/intl-localematcher';
import Negotiator from 'negotiator';
const locales = ['en', 'hi', 'mr', 'kn'];
const defaultLocale = 'hi';
function getLocale(request: NextRequest): string {
const negotiatorHeaders: Record<string, string> = {};
request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));
const languages = new Negotiator({ headers: negotiatorHeaders }).languages();
return matchLocale(languages, locales, defaultLocale);
}
export function middleware(request: NextRequest) {
const pathname = request.nextUrl.pathname;
const pathnameIsMissingLocale = locales.every(
(locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`
);
if (pathnameIsMissingLocale) {
const locale = getLocale(request);
return NextResponse.redirect(
new URL(`/${locale}${pathname.startsWith('/') ? '' : '/'}${pathname}`, request.url)
);
}
}
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
Solving the "Dictionary Debt"
In a marketplace like KhetiSetu, content is dynamic. We have static UI elements (buttons, labels) and dynamic data (crop names, variety names).
For static UI, we use a dictionary pattern. Instead of a heavy library that loads everything on the client, we fetch only the necessary JSON on the server side using the [locale] layout segment.
The Directory Structure
app/
[locale]/
layout.tsx
page.tsx
mandi/
page.tsx
dictionaries/
en.json
hi.json
mr.json
kn.json
We load these dictionaries using a simple asynchronous getter. This ensures that the Hindi translations aren't being sent to a user viewing the app in Kannada, keeping the payload small for users on spotty rural networks.
| Language | Script | Avg. Word Length (Relative) | Line Height Adjustment | | :--- | :--- | :--- | :--- | | English | Latin | 1.0x | Standard | | Hindi | Devanagari | 1.2x | +15% for Matras | | Marathi | Devanagari | 1.2x | +15% for Matras | | Kannada | Kannada | 1.1x | +20% for Ottu-aksharas |
The "Vernacular-First" UI Challenge
One of the biggest mistakes engineers make is assuming that a 16px font size works across all scripts. Devanagari (Hindi/Marathi) and Kannada scripts have complex "matras" (diacritics) and "ottu-aksharas" (stacked consonants).
If you use a standard line-height: 1.2, the top and bottom of the Kannada characters will often get clipped on mobile browsers. We had to implement script-specific CSS variables to handle this.
/* globals.css */
:lang(hi), :lang(mr) {
--base-font-size: 17px;
--base-line-height: 1.6;
}
:lang(kn) {
--base-font-size: 16px;
--base-line-height: 1.8;
}
.body-text {
font-size: var(--base-font-size);
line-height: var(--base-line-height);
}
Furthermore, "Translation" is often the wrong word. We focus on "Transcreation." For example, the word "Submit" doesn't have a direct, natural-sounding equivalent in a rural context. In Hindi, we use "आगे बढ़ें" (Move forward) or "जमा करें" (Deposit/Submit), depending on the action. Using overly formal Sanskritized Hindi makes the app feel like a government form rather than a tool for the community.
Handling Dynamic Data and SEO
For an agri-tech marketplace, SEO is vital. If a farmer searches for "सोयाबीन भाव" (Soybean price) in Marathi, we need our Marathi-specific pages to rank.
Next.js makes this easier with generateMetadata. We ensure that each page includes hreflang tags, telling Google that the /hi/, /mr/, and /kn/ versions of a page are equivalents.
export async function generateMetadata({ params: { locale } }) {
const baseUrl = 'https://khetisetu.com';
return {
alternates: {
canonical: `${baseUrl}/${locale}`,
languages: {
'hi-IN': `${baseUrl}/hi`,
'mr-IN': `${baseUrl}/mr`,
'kn-IN': `${baseUrl}/kn`,
},
},
};
}
Performance: The 2-Second Rule
Farmers are often using $100-150 Android phones. These devices have limited CPU power to parse large JavaScript bundles. By using Next.js Server Components, we move the localization logic—the heavy lifting of mapping keys to strings—to the server.
The client receives the final HTML with the correct Hindi or Kannada strings already rendered. There is no "flash of un-localized text" (FOUT) where the user sees "SUBMIT_BUTTON" for half a second before it turns into "जमा करें".
Conclusion: Engineering for Trust
Building for the Indian agricultural sector requires a shift in mindset. You aren't just writing code; you're building a bridge across a digital divide. By utilizing Next.js's middleware and server-side rendering, we've managed to provide a seamless experience for Hindi, Marathi, and Kannada speakers on KhetiSetu without sacrificing performance.
Localization in agri-tech isn't about translating words; it's about respecting the user's language enough to make the technology invisible. When a farmer sees their local Mandi prices in their own script, the barrier to entry vanishes. And in the world of Indian agriculture, that is the ultimate engineering goal.
Sell or Source Direct from Verified Farmers
Connect with verified buyers and sellers across Indian mandis with zero brokerage on KhetiSetu Marketplace.
Written by KhetiSetu Agronomy Research Team
Empowering Indian farmers with scientific agronomy, ICAR guidelines, and transparent digital tools.
