CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-i18next-client

tessl install tessl/npm-i18next-client@1.11.0

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

Agent Success

Agent success rate when using this tile

69%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.08x

Baseline

Agent success rate without this tile

64%

task.mdevals/scenario-10/

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

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/i18next-client@1.11.x
tile.json