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-9/

Multi-Language Content Retriever

Overview

Build a multi-language content retrieval system that supports fetching translations for various content types. The system should handle missing translations gracefully, support organized content namespaces, and provide fallback mechanisms.

Requirements

1. Translation Retrieval

Implement a ContentRetriever class that can:

  • Retrieve translations by key identifier
  • Support hierarchical key structures (e.g., accessing nested content)
  • Handle multiple content namespaces (common messages, user interface text, error messages)
  • Provide fallback values when translations are unavailable

2. Namespace Management

The system should organize translations into logical namespaces:

  • A default namespace for common content
  • Support for explicitly specifying which namespace to use
  • Ability to access content from multiple namespaces

3. Fallback Handling

Implement robust fallback mechanisms:

  • Try multiple alternative keys if the primary key is missing
  • Provide default text when no translation is found
  • Return appropriate content types (strings for text, objects for structured data)

4. Test Coverage

Write tests that verify:

  • Basic translation retrieval works correctly
  • Namespace-specific content is retrieved accurately
  • Fallback mechanisms work when translations are missing
  • Default values are returned appropriately

Dependencies { .dependencies }

i18next { .dependency }

Provides internationalization and translation support.

Implementation Details

Create the following files:

  • src/content-retriever.js - Main ContentRetriever class implementation
  • src/content-retriever.test.js - Test suite

The ContentRetriever class should:

  • Initialize with translation resources for multiple languages (at minimum: English and Spanish)
  • Provide a method to retrieve content by key
  • Support configuration of default language
  • Handle all requirement scenarios listed above

Test Cases

Test 1: Basic Translation Retrieval @test

// Given: A ContentRetriever initialized with English and Spanish translations
// When: Requesting a translation for key "welcome.message" in English
// Then: Should return the English translation text

Test 2: Namespace-Specific Content @test

// Given: A ContentRetriever with multiple namespaces (common, errors)
// When: Requesting content from the "errors" namespace using key "errors:validation.required"
// Then: Should return the error message from the errors namespace

Test 3: Fallback to Default Value @test

// Given: A ContentRetriever with limited translations
// When: Requesting a key that doesn't exist with a default value "Content not available"
// Then: Should return "Content not available"

Test 4: Multiple Fallback Keys @test

// Given: A ContentRetriever with some missing translations
// When: Requesting translation with fallback keys ["premium.feature", "basic.feature"]
// Then: Should return the translation from whichever key exists, checking in order

Expected Behavior

  • The system should initialize successfully with translation resources
  • All translation retrievals should be case-sensitive
  • Nested key structures should use standard hierarchical notation
  • Missing translations with no fallback should return a sensible default
  • The implementation should be testable and maintainable

Version

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