Back

gt-next@6.11.0

Ernest McCarter avatarErnest McCarter
gt-next6.11.0maxcharscharacter-limits

Overview

gt-next@6.11.0 adds support for the $maxChars parameter to translation functions, building on the formatCutoff() functionality introduced in generaltranslation@8.1.0.


Usage

The $maxChars parameter can be used with any string translation call:

gt('Welcome to our application', { $maxChars: 20 })
// AI attempts translation within 20 chars: "Bienvenido a app"

Character Limit Handling

The $maxChars parameter triggers two distinct mechanisms:

  1. AI Translation Optimisation: The AI receives the character limit and attempts to produce a translation that fits within the specified length.

  2. Library Truncation: If any translation (from AI or cache) exceeds the character limit, the library applies locale-aware truncation to enforce the limit.

gt('Long description text', { $maxChars: 15 })
// AI attempts concise translation: "Texto breve"
// If result exceeds limit: "Texto de desc…" (truncated)

Integration

Works with your existing translation options:

gt('User notification', {
  $context: 'mobile-alert',
  $maxChars: 30
})
// AI attempts translation within 30 chars: "Notificación usuario"
// Library truncates if needed: "Notificación del usuario…"

This parameter affects translation hashing, ensuring that different character limits result in separate translation entries.