Oihana PHP Arango

aqlFieldTranslate.php

Table of Contents

Functions

aqlFieldTranslate()  : string
Generates an AQL key/value expression for a translated document field.

Functions

aqlFieldTranslate()

Generates an AQL key/value expression for a translated document field.

aqlFieldTranslate(string $key[, string $doc = AQL::DOC ][, string|null $keyName = null ][, string|array<string|int, mixed>|null $lang = null ]) : string

This helper constructs an expression suitable for inclusion in a RETURN { ... } block. It returns the translated value of a field using the TRANSLATE() function if a language code is provided. Otherwise, it falls back to the original field value.

Behavior:

  • $key is used as the key in the resulting AQL object.
  • $doc is the document variable or expression containing the field.
  • $keyName allows specifying a different property name in the document; defaults to $key.
  • $lang is the optional language code for translation; if null, the original value is returned.

Note: the language is the FOURTH argument; the third is $keyName.

Example usage:

// Translate the "title" field to French (lang is the 4th argument)
aqlFieldTranslate('title', 'doc', null, 'fr');
// Produces: title:TRANSLATE("fr",doc.title,"")

// No translation (lang null) → original field
aqlFieldTranslate('description', 'doc');
// Produces: description:doc.description

// Different property name ($keyName) AND a language
aqlFieldTranslate('label', 'doc', 'name', 'en');
// Produces: label:TRANSLATE("en",doc.name,"")
Parameters
$key : string

The logical key to use in the AQL return object.

$doc : string = AQL::DOC

The document variable or alias (default: AQL::DOC).

$keyName : string|null = null

Optional property name in the document if different from $key.

$lang : string|array<string|int, mixed>|null = null

Optional language code for translation; if null, returns the original field.

Tags
since
1.0.0
author

Marc Alcaraz

Return values
string

AQL key/value snippet for the translated field.

On this page

Search results