CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-i18next-client

DEPRECATED client-side JavaScript internationalization library with translation, pluralization, and localization support.

69

1.07x
Overview
Eval results
Files

task.mdevals/scenario-7/

Language-Aware Translation Manager

Build a translation manager that dynamically handles language switching, detection, and text direction for internationalized applications.

Requirements

Your implementation should provide a translation manager with the following capabilities:

Language Initialization

Initialize the translation system with English as the default language and Spanish as a fallback. The system should load translation resources from a simple in-memory resource store.

Dynamic Language Switching

Implement functionality to switch between languages at runtime. When the language is changed, the system should:

  • Update the active language
  • Reload translations for the new language
  • Return confirmation that the language has been changed

Language Detection

Provide the ability to retrieve the currently active language code. This allows the application to know which language is being used at any given time.

Text Direction Support

Support retrieving the text direction (left-to-right or right-to-left) for the current language. This is essential for properly rendering languages like Arabic and Hebrew.

Translation Retrieval

Provide a function to retrieve translated strings for the current language using translation keys.

Test Cases

  • Initializing with default language 'en' sets the current language to 'en' @test
  • Changing language to 'es' updates the current language to 'es' @test
  • Getting the current language returns the active language code @test
  • Getting text direction for 'en' returns 'ltr' @test
  • Getting text direction for 'ar' (Arabic) returns 'rtl' @test

Implementation

@generates

API

/**
 * Initialize the translation manager with configuration
 * @param {Object} options - Configuration options
 * @param {string} options.lng - Default language code
 * @param {string} options.fallbackLng - Fallback language code
 * @param {Object} options.resources - Translation resources by language
 * @param {Function} callback - Callback function called after initialization
 */
function init(options, callback) {
  // Implementation
}

/**
 * Change the current language
 * @param {string} lng - Language code to switch to
 * @param {Function} callback - Callback function called after language change
 */
function changeLanguage(lng, callback) {
  // Implementation
}

/**
 * Get the current active language code
 * @returns {string} Current language code
 */
function getCurrentLanguage() {
  // Implementation
}

/**
 * Get text direction for the current language
 * @returns {string} 'ltr' for left-to-right, 'rtl' for right-to-left
 */
function getTextDirection() {
  // Implementation
}

/**
 * Translate a key using the current language
 * @param {string} key - Translation key
 * @returns {string} Translated string
 */
function translate(key) {
  // Implementation
}

module.exports = {
  init,
  changeLanguage,
  getCurrentLanguage,
  getTextDirection,
  translate
};

Dependencies { .dependencies }

i18next { .dependency }

Provides internationalization and translation management.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-i18next-client

tile.json