Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

i18n_merge_translations()

Description

Merge values for across multiple translation strings.
Where a value is missing for a language used elsewhere i18n_get_translated will be used.
If no value is provided and no English (en) string is found then blank will be returned.

Example input: ["~en:cheese~fr:fromage","~en:bread~fr:pain"]

Example output: ["~en:cheese, bread","~fr:fromage, pain"]

Parameters

ColumnTypeDefaultDescription
$values: array 1
$values array Translation strings to merge.

Return

array Each language string as a comma separated list.

Location

include/language_functions.php lines 770 to 799

Definition

 
function i18n_merge_translations(array $values): array
{
    if(
count($values)<=1) {
        return 
$values;
    }

    
$values_split array_map('i18n_get_translations',$values);

    
$languages = [];
    foreach (
$values_split as $value) {
        
$languages array_unique(array_merge($languages,array_keys($value)));
    }

    
$options = [];
    foreach (
$values_split as $value) {
        foreach (
$languages as $language) {
            if (
key_exists($language,$value)) {
                
$options[$language][]=$value[$language];
            } else {
                
$options[$language][]=i18n_get_translated($value['en']??"");
            }
        }
    }

    return 
array_map(
        fn(
string $lang, array $values): string => "~$lang:" implode(", ",$values),
        
array_keys($options),
        
array_values($options)
    );
}

This article was last updated 8th December 2024 20:35 Europe/London time based on the source file dated 27th November 2024 15:30 Europe/London time.