Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

i18n_get_translated()

Description

For field names / values using the i18n syntax, return the version in the current user's language. Format is ~en:Somename~es:Someothername

Parameters

ColumnTypeDefaultDescription
$text string

Return

void

Location

include/language_functions.php lines 40 to 73

Definition

 
function i18n_get_translated($text)
    {
    
$text=trim($text);
        
    global 
$language,$defaultlanguage;
    
$asdefaultlanguage=$defaultlanguage;
    if (!isset(
$asdefaultlanguage))
        
$asdefaultlanguage='en';
    
    
# Split
    
$s=explode("~",$text);

    
# Not a translatable field?
    
if (count($s)<2) {return $text;}

    
# Find the current language and return it
    
$default="";
    for (
$n=1;$n<count($s);$n++)
        {
        
# Not a translated string, return as-is
        
if (substr($s[$n],2,1)!=":" && substr($s[$n],5,1)!=":" && substr($s[$n],0,1)!=":") {return $text;}
        
        
# Support both 2 character and 5 character language codes (for example en, en-US).
        
$p=strpos($s[$n],':');
        
$textLanguage=substr($s[$n],0,$p);
        if (
$textLanguage==$language) {return substr($s[$n],$p+1);}
        
        if (
$textLanguage==$asdefaultlanguage || $p==|| $n==1) {$default=substr($s[$n],$p+1);}
        }    
    
    
# Translation not found? Return default language
    # No default language entry? Then consider this a broken language string and return the string unprocessed.
    
if ($default!="") {return $default;} else {return $text;}
    }

This article was last updated 26th November 2020 04:05 Europe/London time based on the source file dated 7th July 2020 14:31 Europe/London time.