whatisgithub

What is polyglot.js?

airbnb/polyglot.js — explained in plain English

Analysis updated 2026-07-03

3,721JavaScriptAudience · developerComplexity · 2/5Setup · easy

In one sentence

Lightweight JavaScript library from Airbnb for displaying text in multiple languages, handling variable substitution and complex plural forms across 30+ languages without complex setup.

Mindmap

mindmap
  root((Polyglot.js))
    What it does
      Phrase lookup by key
      Variable interpolation
      Pluralization
    Features
      30+ language support
      Multiple instances
      Locale-aware plural rules
    Tech stack
      JavaScript
      Node.js
      npm
    Use cases
      Web app i18n
      Server-side rendering
      Swap languages at runtime
    Setup
      npm install
      Load phrases
      Call lookup method
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Add multi-language support to a web app by loading translated phrase sets and looking them up by key at runtime

USE CASE 2

Handle pluralization correctly in languages like Russian or Czech by defining all plural forms in a single phrase string

USE CASE 3

Run multiple Polyglot instances on a server to serve different languages to different users simultaneously

USE CASE 4

Swap in a different language for a user by replacing the phrase set without changing any application code

What is it built with?

JavaScriptNode.jsnpm

How does it compare?

airbnb/polyglot.jsbritecharts/britechartsruipgil/scraperjs
Stars3,7213,7223,720
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasyeasymoderate
Complexity2/52/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

So what is it?

Polyglot.js is a small JavaScript library that helps web applications display text in multiple languages. It was built by Airbnb, which operates in 192 countries and translates its site into roughly 30 languages, so the need for a reliable translation tool came directly from that real-world scale. The library does not translate words for you. Instead, it manages the translated phrases you supply. You give it a set of key-to-phrase mappings for the user's language, and then ask it to look up a phrase by key at runtime. This keeps translation logic separate from your application code, and you can swap in different phrase sets for different users. Two features make Polyglot more useful than a plain lookup table. First, it supports interpolation, meaning you can insert variable values into phrases at the time of display. For example, a phrase like "Hello, %{name}" becomes "Hello, Maria" when you pass the name in. Second, it handles pluralization, which is trickier than it sounds because different languages have different rules. English has two forms ("1 car", "2 cars"), but Czech has three and Russian more still. Polyglot lets you define all the plural forms for a phrase in a single string, separated by a special delimiter, and then picks the right form based on a count you provide and the locale you have set. The library works both in a browser and in server-side JavaScript environments like Node. You can run multiple independent instances at the same time, which is useful on a server where different users might need different languages simultaneously. Setup is simple: install via npm, create a Polyglot instance, load your translated phrases into it, and call the lookup method wherever you need text in your UI. The library is intentionally minimal and does not try to do anything beyond phrase lookup, interpolation, and pluralization.

Copy-paste prompts

Prompt 1
Using airbnb polyglot.js, set up English and French translations for a React app so that the UI language switches based on the user's browser settings
Prompt 2
Show me how to define a phrase with variable interpolation and plural forms in polyglot.js for a notification like '1 new message' vs '3 new messages'
Prompt 3
How do I load polyglot.js in a Node.js API server so that each request handler renders text in the language specified in the request header?
Prompt 4
Using polyglot.js, write a helper function that accepts a locale string and returns a pre-configured Polyglot instance loaded with the right translations JSON file

Frequently asked questions

What is polyglot.js?

Lightweight JavaScript library from Airbnb for displaying text in multiple languages, handling variable substitution and complex plural forms across 30+ languages without complex setup.

What language is polyglot.js written in?

Mainly JavaScript. The stack also includes JavaScript, Node.js, npm.

How hard is polyglot.js to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is polyglot.js for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.