İçeriğe git
JavaScript i18n

JavaScript i18n: Intl API ile Tarayıcıya Özel Uluslararasılaştırma

JavaScript, sayıları, tarihleri ve listeleri biçimlendirmek ve farklı dil ayarlarında çoğullaşma kurallarını işlemek için yerleşik bir standart olarak Intl API'sini içerir.

Package
lefine/strings
Runs in
Browsers · Node · Deno · Bun · Workers
lefine
01Terminal
npm install lefine
02i18n.js
import { createTranslator } from 'lefine/strings'import messages from './locales/en.json' with { type: 'json' }// messages is { namespace: { key: text } }, as pull wrote itexport const t = createTranslator({  locale: 'en',  messages,  namespace: 'home',})
03main.js
import { t } from './i18n.js'document.querySelector('h1').textContent = t('title')// ICU values work too: "Hello, {name}"document.querySelector('p').textContent = t('greeting', { name: 'World' })
t('title')
Welcome
01/Overview

Harici kütüphanelere gerek yoktur. API, tüm modern tarayıcılarda ve Node.js'de desteklenir ve dil ayarına duyarlı dize karşılaştırması, bölme ve göreceli zaman biçimlendirme özelliklerini kullanıma hazır olarak sunar.

02/Setup

Basit JavaScript'e i18n'i üç adımda ekleyin

Yüklemeniz gereken JavaScript’e özgü bir paket yoktur: @better-i18n/core burada saran diğer her SDK’nın sade JavaScript istemcisidir.

  1. 01

    İstemciyi yükleyin

    Bağımlılıksız tek paket. Tarayıcılarda, Node, Deno, Bun ve Cloudflare Workers'ta çalışır.

    terminalbash
    npm install lefinenpx lefine loginnpx lefine strings pull -o locales# lefine/strings has no framework dependency.# pull writes locales/en.json, de.json, ...
  2. 02

    İstemciyi bir kez oluşturun

    Modül kapsamında örnekleyin ve ihtiyaç duyduğunuz her yerde içe aktarın: tek istemci, tek yapılandırma ve her çağrı aynı bellek içi önbelleği paylaşır.

    i18n.js
    import { createTranslator } from 'lefine/strings'import messages from './locales/en.json' with { type: 'json' }// messages is { namespace: { key: text } }, as pull wrote itexport const t = createTranslator({  locale: 'en',  messages,  namespace: 'home',})
  3. 03

    Read a message

    getMessages basit iç içe geçmiş bir nesne döner, böylece dört satırlık bir arama yardımcısı tek ihtiyaç duyduğunuz çalışma zamanı olur.

    main.js
    import { t } from './i18n.js'document.querySelector('h1').textContent = t('title')// ICU values work too: "Hello, {name}"document.querySelector('p').textContent = t('greeting', { name: 'World' })
03/Two ways

İstemciyle veya fetch ile

İstemci önbellekleme, yeniden denemeler ve yedek zinciri ekler. Bunu kendiniz yapmak isterseniz, CDN sade JSON uç noktasıdır.

locale.js
import { createTranslator } from 'lefine/strings'let t = createTranslator({ locale: 'en', messages: await load('en'), namespace: 'home' })async function load(locale) {  const res = await fetch(`/locales/${locale}.json`) // the files pull wrote  return res.json()}export async function setLocale(next) {  t = createTranslator({ locale: next, messages: await load(next), namespace: 'home' })  document.documentElement.lang = next  render()}
04/Formatting

Uygulamada JavaScript Intl API

Modern tarayıcı veya Node.js çalışma ortamında yerleşik Intl yapıcılarını kullanarak para birimlerini, tarihleri ve sıralı sayıları yerel ayara özgü çıktıyla biçimlendirin.

format.js
// Using the built-in Intl APIconst formatter = new Intl.NumberFormat('de-DE', {  style: 'currency',  currency: 'EUR',});console.log(formatter.format(1234.56)); // "1.234,56 €"// Date formattingconst date = new Intl.DateTimeFormat('ja-JP', {  year: 'numeric',  month: 'long',  day: 'numeric',});console.log(date.format(new Date())); // "2026年3月2日"// Pluralizationconst plural = new Intl.PluralRules('en');const suffixes = { one: 'st', two: 'nd', few: 'rd', other: 'th' };function ordinal(n) {  return `${n}${suffixes[plural.select(n)]}`;}
05/Capabilities

JavaScript Intl API Özellikleri

  • Temel i18n işlemleri için harici bağımlılık gerektirmeyen yerleşik Intl API
  • Yerel ayara duyarlı para birimi, yüzde ve birim biçimlendirmesi için Intl.NumberFormat
  • Yerel ayarlara özgü tarih ve saat görüntüleme biçimleri için Intl.DateTimeFormat
  • 100'den fazla dil ve bölgede sıralı ve sayısal sıfatların çoğul hale getirilmesine ilişkin Uluslararası Çoğul Kuralları
  • Çoğullar, seçimler ve iç içe geçirme için ICU MessageFormat; intl-messageformat gibi bir kütüphane aracılığıyla (Intl'e yerleşik değildir)
  • İnsanın okuyabileceği göreli tarihler için Intl.RelativeTimeFormat (ör. "3 gün önce")
  • Yerel ayarlara duyarlı birleştirme ve ayırma listeleri için Intl.ListFormat
  • Yerel ayarlara duyarlı dize sıralama ve karşılaştırma için Uluslararası Sıralayıcı
  • Kelime, cümle ve grafem sınırlarının tespitine yönelik Uluslararası Segmentleyici
How it works

Bir JavaScript dizisi nereden gelir

Derleme adımı ve paketlenmiş yerel dosya yok: istemci çalışma zamanında bir yerel ayar çözüyor ve edge buna yanıt veriyor.

Read path — every locale load
Your JavaScript app

Reads from the plain object the pulled JSON file already gave.

0 network calls per render

lefine

getMessages(locale) — served from the in-memory cache if it is warm.

60 s cache · 0 deps

CDN edge

Cloudflare worker answers from the nearest edge cache.

max-age=60 · never a 5xx

R2 object store

The published translation files the sync worker wrote.

source of truth

Fallback chain — tried in order when a hop fails
  • 01In-memory TTL cache
  • 02CDN fetch, with timeout and one retry
  • 03Persistent storage, if configured
  • 04staticData bundled with the app
  • 05Throw — after everything above missed
Write path — dashboard to app
AI or translator

Proposal reviewed in the dashboard, glossary enforced.

MCP · dashboard · CLI

Publish

Sync worker writes the locale files to R2.

lefine strings publish

CDN purge

Fire-and-forget purge of the affected keys and the manifest.

non-critical by design

Live in the app

The next getMessages() past the TTL returns the new copy.

~5 min worst case

0dependencies in core
5 minSDK cache in production; edge 60s
200CDN status, even on failure
5fallback layers before an error
Get started

Ücretsiz başla.

JavaScript i18n'e Bugün Başlayın

JavaScript çevirilerinizi yapay zeka destekli iş akışları, CLI senkronizasyonu ve edge CDN teslimatıyla yönetin.