Add multi-language support to a web app by loading translated phrase sets and looking them up by key at runtime
Handle pluralization correctly in languages like Russian or Czech by defining all plural forms in a single phrase string
Run multiple Polyglot instances on a server to serve different languages to different users simultaneously
Swap in a different language for a user by replacing the phrase set without changing any application code
| airbnb/polyglot.js | britecharts/britecharts | ruipgil/scraperjs | |
|---|---|---|---|
| Stars | 3,721 | 3,722 | 3,720 |
| Language | JavaScript | JavaScript | JavaScript |
| Setup difficulty | easy | easy | moderate |
| Complexity | 2/5 | 2/5 | 2/5 |
| Audience | developer | developer | developer |
Figures from each repo's GitHub metadata at analysis time.
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.
Lightweight JavaScript library from Airbnb for displaying text in multiple languages, handling variable substitution and complex plural forms across 30+ languages without complex setup.
Mainly JavaScript. The stack also includes JavaScript, Node.js, npm.
Setup difficulty is rated easy, with roughly 5min to a first successful run.
Mainly developer.
This repo across BitVibe Labs
Verify against the repo before relying on details.