Skip to content

Replace API language calls with distribution languages.json for improved performance #322

@andrii-bodnar

Description

@andrii-bodnar

Replace the current /api/v2/languages API calls with the new languages.json file available in distribution CDN to improve SDK performance and reduce API load.

Current Implementation

The SDK currently fetches language information through:

  • API Call: CrowdinApi.getLanguagesInfo()/api/v2/languages
  • Caching: Languages are cached via DataManager.getSupportedLanguages()
  • Custom Languages: Uses custom_languages field from manifest.json which will be deprecated
  • Usage: Language info is used in multiple repositories:
    • StringDataRemoteRepository (lines 74, 84-85)
    • TranslationDataRepository (lines 60, 72-73)
    • RealTimeUpdateManager (line 63)

Proposed Solution

Utilize the new distribution file: https://distributions.crowdin.net/<hash>/languages.json

Benefits:

  • Performance: No additional API calls needed
  • Reduced API Load: Fewer requests to Crowdin platform
  • Future-Proof: Removes dependency on deprecated custom_languages
  • Consistency: Same data format as current List Languages API response

Implementation Strategy:

1. Add Distribution Languages API

Add new endpoint to CrowdinDistributionApi.kt:

@GET("/{distributionHash}/languages.json")
fun getLanguages(
    @Path("distributionHash") distributionHash: String,
    @Query("timestamp") timeStamp: Long
): Call<LanguagesInfo>

2. Update Language Fetching Logic

  • Modify DataManager.getSupportedLanguages() to fetch from distribution instead of API
  • Update CrowdingRepository.getSupportedLanguages() to use distribution endpoint
  • Implement timestamp-based validation using existing SyncData mechanism

3. Remove Custom Languages Dependency

Update language resolution in:

  • StringDataRemoteRepository.getSafeLanguageCode()
  • TranslationDataRepository.onManifestDataReceived()
  • Extensions.getMatchedCode()

4. Leverage Existing Caching

Use current timestamp-based caching strategy (already implemented in StringDataRemoteRepository):

  • Compare manifest.timestamp with cached timestamp
  • Cache remains valid if timestamp unchanged
  • Extends TTL for unchanged data

Technical Details:

  • Data Format: Same as current LanguagesInfo model (trimmed List Languages response)
  • Caching Key: Based on manifest.timestamp (existing pattern)
  • Fallback: Maintain current API as fallback for backward compatibility during transition
  • Testing: Update TestCommon.kt to include languages.json test data

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions