The name of your .mo file must match the $domain, e.g. name your files messages.mo and call bindtextdomain("messages", $directory).(PHP 4, PHP 5, PHP 7, PHP 8)
bindtextdomain — Spécifie ou récupère le chemin d'un domaine
La fonction bindtextdomain() définit ou récupère le chemin d'un domaine.
Le chemin complet pour le domain actuellement défini,
ou false si une erreur survient.
false est également retourné si directory n'existe pas.
Lève une ValueError si domain
est une string vide ou dépasse 1024 octets.
Lève une ValueError si domain
ou directory contient des octets nuls.
| Version | Description |
|---|---|
| 8.4.4 |
Lève désormais une ValueError si domain
ou directory contient des octets nuls.
|
| 8.4.0 |
directory est désormais facultatif.
Auparavant, ce paramètre devait toujours être spécifié.
|
| 8.0.3 |
directory est désormais nullable.
Auparavant, il n'était pas possible de récupérer le dossier actuellement défini.
|
| 8.0.0 |
Lève désormais une ValueError si domain
est une string vide ou trop long. Auparavant, une
E_WARNING était émise et false était retourné.
|
Exemple #1 Exemple avec bindtextdomain()
<?php
$domain = 'myapp';
echo bindtextdomain($domain, '/usr/share/myapp/locale');
?>L'exemple ci-dessus va afficher :
/usr/share/myapp/locale
Note:
L'information bindtextdomain() est maintenue par process, et non par thread.
The name of your .mo file must match the $domain, e.g. name your files messages.mo and call bindtextdomain("messages", $directory).I recommend using absolute paths in the $directory parameter. This caused me several hours to debug as Ajax calls to my localization functions messed up the path. And since no error if thrown if the path in $directory cannot be found, one should check the result always:
<?php
// Imagine the path for this file is "/localization" and your locales are in the "/locale" directory.
$pathToDomain = __DIR__ . "/../locale";
if ($pathToDomain != bindtextdomain($domain, $pathToDomain)) {
// Error handling.
}
?>