Asper Header  1.0.14
The header injector extension
Loading...
Searching...
No Matches
messageProvider.ts File Reference

Comprehensive internationalization engine with intelligent language detection and message orchestration. More...

Go to the source code of this file.

Data Structures

class  MessageProvider
 Internationalization message provider with multi-language support and fallback mechanisms. More...
 

Variables

import *as vscode from vscode
 
 import { messages } from './messageReference'
 
const instance = new MessageProvider()
 Singleton instance of the MessageProvider for application-wide use.
 
export const getMessage = instance.get.bind(instance)
 Exported function for direct message retrieval.
 

Detailed Description

Comprehensive internationalization engine with intelligent language detection and message orchestration.

Author
Henry Letellier
Version
1.0.10
Since
1.0.0
Date
2025

This module serves as the central internationalization (i18n) engine for the AsperHeader extension, providing sophisticated message management with automatic language detection, dynamic parameter interpolation, and robust fallback mechanisms. It ensures consistent multilingual user experiences across all extension interfaces and interactions.

I18n Architecture:

  • Language Detection: Automatic detection from VS Code environment and user preferences
  • Message Dictionary: Centralized message repository via messageReference
  • Fallback Chain: Hierarchical fallback (user locale → English → first available)
  • Parameter System: Dynamic parameter interpolation with type safety
  • Caching Layer: Intelligent caching for frequently accessed messages
  • Error Recovery: Graceful handling of missing translations and malformed messages

Language Support Matrix:

  • English (en): Primary language with complete coverage (fallback language)
  • French (fr): Full translation coverage for all extension messages
  • Italian (it): Complete localization with cultural adaptations
  • Extensibility: Plugin architecture for additional language support

Message Types:

  • Static Messages: Simple string translations for UI elements
  • Parameterized Messages: Dynamic content with variable substitution
  • Function Messages: Complex messages with computation and formatting
  • Pluralization: Context-aware plural forms for different languages
  • Rich Content: HTML/Markdown support for formatted notifications

Parameter Interpolation System:

  • Named Parameters: {paramName} style parameter substitution
  • Positional Parameters: Sequential parameter replacement for simple messages
  • Type Safety: TypeScript support for parameter validation
  • Escaping: Automatic escaping for security in HTML contexts
  • Formatting: Number, date, and currency formatting per locale

Fallback Strategy:

  1. User Locale: Attempt to use detected VS Code language
  2. English Fallback: Default to English if user locale unavailable
  3. First Available: Use first available translation as last resort
  4. Debug Mode: Return message key with parameters for development
  5. Error Handling: Clear error messages for missing translations

Integration Points: This module provides localized content throughout the extension ecosystem:

  • User Interface: All VS Code notifications and webview content
  • Error Messages: Localized error reporting and diagnostic information
  • Configuration: Setting descriptions and validation messages
  • Header Content: Template text and generated content localization
  • Logging: Debug and information messages for development

Performance Optimization:

  • Lazy Loading: Language packs loaded only when needed
  • Message Caching: Frequently used messages cached in memory
  • Batch Operations: Efficient handling of bulk message requests
  • Memory Management: Automatic cleanup of unused language data

Definition in file messageProvider.ts.

Variable Documentation

◆ getMessage

export const getMessage = instance.get.bind(instance)

Exported function for direct message retrieval.

Parameters
messageKeyThe key identifying the message
optionsOrArgEither options object with language override or first message argument
argsAdditional arguments to pass to the message function
Returns
The localized message string

Bound method of the singleton MessageProvider instance for convenient access throughout the application. Provides the same functionality as calling instance.get() directly but with simplified import syntax.

Usage examples:

  • getMessage("headerWriteSuccess")
  • getMessage("fileLoaded", "/path/to/file")
  • getMessage("error", { language: "fr" }, "details")

Definition at line 232 of file messageProvider.ts.

◆ import

import { messages } from './messageReference'

Definition at line 86 of file messageProvider.ts.

◆ instance

const instance = new MessageProvider()

Singleton instance of the MessageProvider for application-wide use.

Single instance ensures consistent language settings and message caching across the entire extension. Automatically detects user's VS Code language preference on initialization.

Definition at line 214 of file messageProvider.ts.

◆ vscode

import* as vscode from vscode

Definition at line 85 of file messageProvider.ts.