Coding standards
Security in ResourceSpace
Developer reference
Database
User api session functions
Geolocation functions
Storage test functions
Cli functions
Lang translation functions

lang_translation_batches()

Description

Batch related strings across locales while limiting the translation count and estimated text size.

Parameters

ColumnTypeDefaultDescription
$strings array English entries keyed by locale and then language key.
$max_keys int 50 Maximum number of translations in one request.
$max_bytes int 12000 Approximate text budget, counting the English size for each requested translation.
$max_locales int Maximum number of locale contexts in one request.

Return

list<array> Non-empty batches in source order.

Location

include/lang_translation_functions.php lines 211 to 241

Definition

 
function lang_translation_batches(
    array 
$strings,
    
int $max_keys = 50,
    
int $max_bytes = 12000,
    
int $max_locales = 16
): array {
    
$batches = [];
    
$batch = [];
    
$bytes = 0;
    
$count = 0;
    foreach (
$strings as $locale => $entries) {
        foreach (
$entries as $key => $value) {
            
$size = strlen(json_encode([$key => $value], JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));
            if (
                
$batch !== [] && ($count >= $max_keys || $bytes + $size > $max_bytes
                    
|| (!isset($batch[$locale]) && count($batch) >= $max_locales))
            ) {
                
$batches[] = $batch;
                
$batch = [];
                
$bytes = $count = 0;
            }
            
$batch[$locale][$key] = $value;
            
$bytes += $size;
            ++
$count;
        }
    }
    if (
$batch !== []) {
        
$batches[] = $batch;
    }
    return 
$batches;
}

This article was last updated 27th November 2026 18:35 Europe/London time based on the source file dated 27th November 2026 17:15 Europe/London time.