DEV Community

Youngjun Yoon
Youngjun Yoon

Posted on

Three languages in one 372 KB HTML file: shipping ?lang= without a build step

I run a small VALORANT clip site, Baltalk (https://vtgo.gg), and last week it needed to speak English and Traditional Chinese. There is no framework, no bundler and no server code — it is a single index.html served by Firebase Hosting, with everything inline: styles, the clip renderer, the canvas crosshair preview, the FX panel. The file is about 372 KB.

This is how the language layer works, why I chose it, and the three costs I would fix next.

The whole language layer is a dictionary keyed by Korean

The markup is written in Korean. The dictionary maps a Korean source string to its English or Chinese replacement:

var DICT = {
  en: {
    '발톡': 'Baltalk',
    '홈': 'Home',
    '쇼츠': 'Shorts',
    '클립 랭킹': 'Clip ranking',
    // ...
  },
  zh: {
    '홈': '首頁',
    '쇼츠': '短影音',
    '클립 랭킹': '精華排行',
    // ...
  }
};
Enter fullscreen mode Exit fullscreen mode

A translateTree(document.body) pass walks text nodes and looks each string up. Anything marked data-noi18n is skipped — that is how the mixer keeps 85% as 85% instead of looking it up as a phrase.

Choosing a language: query string, then storage, then Korean

function initLang(){
  var q = new URLSearchParams(location.search).get('lang') || '';
  var saved = localStorage.getItem('vtgo.lang') || '';
  var l = (q || saved).toLowerCase();
  if (l === 'en') LANG = 'en';
  else if (l === 'zh' || l === 'zh-tw' || l === 'zh-hant' || l === 'zh_tw') LANG = 'zh';
  else LANG = 'ko';
}

function setLang(l){
  LANG = (l === 'en' ? 'en' : l === 'zh' ? 'zh' : 'ko');
  localStorage.setItem('vtgo.lang', LANG);
  var u = new URL(location.href);
  if (LANG === 'ko') u.searchParams.delete('lang');
  else u.searchParams.set('lang', LANG === 'zh' ? 'zh-tw' : 'en');
  history.replaceState(null, '', u.toString());
  restoreKo();   // reset the DOM to Korean before translating again
  paintLang();   // document.title, <html lang>, the KO/EN/繁體 buttons
  renderAll();   // re-render the feed so new nodes get translated too
}
Enter fullscreen mode Exit fullscreen mode

Order matters more than it looks. ?lang= wins over the saved value so that a shared link opens in the language it promises. history.replaceState keeps the URL shareable without reloading the page. And restoreKo() exists because switching EN → 繁體 without it would translate translations: Shortcuts would be looked up as a Korean key and missed.

The feed is rendered from data, so renderAll() has to run after every switch — text inside nodes created later is not in the tree the first pass walked.

Two smaller things live in paintLang():

  • document.title comes from a TITLES map, so the tab and the search result title follow the language.
  • Numbers go through Intl.NumberFormat: Korean shows 5.9만, English shows 5.9K, Chinese 5.9K with zh-TW grouping. A hardcoded toLocaleString() gets this wrong in one of the three every time.

Why one file instead of three builds

  • It is fast to change. No build step means the firebase deploy is the edit. For a solo project this is the difference between shipping and not shipping.
  • The switch is instant. Nothing reloads; the DOM is re-translated and re-rendered.
  • hreflang still points at real URLs. The <head> carries ko, en, zh-TW, zh-Hant and x-default, so the three entry points are declared even though they serve the same bytes.

The three costs, honestly

1. The raw HTML is always Korean. ?lang=en and ?lang=zh-tw return byte-identical documents — the same 372 KB, the same Korean <title>. Google renders JavaScript, so the rendered page is understood, but the initial response for the English URL says "발톡 | 발로란트 하이라이트 아레나" in title and description. Any crawler, social unfurl or preview bot that does not execute JS sees Korean. If organic search in English matters, the fix is per-locale static shells: three small HTML files with the right title, description and OG tags, all loading the same bundle.

2. Keys are source strings, so copy edits silently break translations. Rename '클립 올리기' to '클립 등록' and the English version instantly falls back to Korean with no error. A missing key is invisible by design — that is the right behaviour at runtime and the wrong one during a refactor. Stable ids (upload.submit) plus a coverage check in CI would catch it.

3. The dictionary rides along for everyone. All three languages ship in every page load. At this size it is a rounding error next to the inline CSS, but it is the kind of thing that stops being free at four languages and a few thousand strings.

What I would keep

The fallback chain ?lang= → localStorage → Korean and the "translate the DOM, re-render the data" split are worth reusing. They cost about 60 lines, work on top of any static host, and make a URL in a language a real, shareable thing instead of a hidden setting.

Baltalk (VTGO.GG) is an independent fan project and is not affiliated with Riot Games. VALORANT is a trademark of Riot Games, Inc.

Top comments (0)