i18n

Internationalization and localization utilities for multi-language support, including translations, pluralization, date/number formatting, and relative time.

Functions

Function
Description
Example

setLocale

Set current locale

dphelper.i18n.setLocale('it')

getLocale

Get current locale

dphelper.i18n.getLocale()

t

Translate a key

dphelper.i18n.t('hello', { name: 'World' })

addTranslations

Add translation strings

dphelper.i18n.addTranslations('it', { hello: 'Ciao!' })

pluralize

Get pluralized string

dphelper.i18n.pluralize(5, { one: 'item', other: 'items' })

number

Format number by locale

dphelper.i18n.number(1234.56, 'de-DE', { currency: 'EUR' })

date

Format date by locale

dphelper.i18n.date(new Date(), 'en-US', { dateStyle: 'long' })

relativeTime

Get relative time string

dphelper.i18n.relativeTime(Date.now() - 3600000)

list

Format list by locale

dphelper.i18n.list(['a', 'b', 'c'], 'en')

getSupportedLocales

Get list of locales

dphelper.i18n.getSupportedLocales()

Description

Complete internationalization module featuring:

  • Translation System - Key-based translations with variable interpolation

  • Pluralization - Support for multiple plural forms (zero, one, two, few, many, other)

  • Locale-aware Formatting - Numbers, dates, and lists formatted per locale

  • Relative Time - "2 hours ago", "in 5 minutes" style strings

  • Auto-detection - Automatic browser locale detection

  • Extensible - Add custom translations for any language

Usage Examples

Basic Translation

Adding Custom Translations

Pluralization

Number Formatting

Date Formatting

Relative Time

List Formatting

Advanced Usage

Complete i18n Setup

Dynamic Locale Switching

React-like Translation Component

Details

  • Author: Dario Passariello

  • Version: 0.0.1

  • Creation Date: 20260313

  • Last Modified: 20260313

  • Environment: Works in both client and server environments


Automatically generated document

Last updated