Difference between revisions of "Custom Transliteration"

From WHMCS Documentation

(Created page with 'Transliteration is the practice of converting a text from one writing system into another in a systematic way. In WHMCS this is supported & can be used to automatically replace …')
 
m (Custom Transliteration Function)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Transliteration is the practice of converting a text from one writing system into another in a systematic way.
+
==Transliteration in WHMCS==
 +
Transliteration is the practice of converting text from one writing system into another in a systematic way.
  
In WHMCS this is supported & can be used to automatically replace characters in a clients profile data that would otherwise cause third party systems such as hosting control panels and domain registrars to reject the automated API requests containing those characters.
+
You can use this with WHMCS to automatically replace characters in [[Client_Management|client profile data]] that third-party systems may reject. For example, a domain registrar's API might automatically reject certain characters in received requests.
  
A default function included in WHMCS will automatically take care of and replace the most common special characters that cause problems for users but if you need to tailor it to your specific needs, then you can do so by creating a hook file as follows to override the default function, and specify your own custom character replacement process within it.
+
==Custom Transliteration Function==
 +
WHMCS includes a default function to find and replace the most common special characters that cause problems. If you need to tailor this to your unique needs, you can define a <tt>hook_transliterate</tt> function in the <tt>/includes/hooks/</tt> directory. This will override the default function and allow you to specify your own character replacements.
  
<?php
+
<div class="source-cli">
+
<?php
function hook_transliterate($string) {
+
<br/>
    $string = str_replace("ž","z",$string);
+
<br/>function hook_transliterate($string) {
    return $string;
+
<br/>    $string = str_replace("ž","z",$string);
}
+
<br/>    $string = str_replace("é","e",$string);
+
<br/>    return $string;
add_hook("Transliteration",1,"hook_transliterate");
+
<br/>}
+
<br/>
?>
+
<br/>?>
 +
</div>
  
The code above can simply be copied and pasted into a new file and saved into the /includes/hooks/ folder with any name to take effect, and you can then customise the character replacements done by that function as desired and just need to return the converted string at the end of the call.
+
An example of the above being used: a client with the name Jéssé žuckérbérg would be converted to Jesse Zuckerberg when performing a request using a module, such as a domain registrar.
 +
 
 +
Copy-and-paste the code above into a new file and save it in the <tt>/includes/hooks/</tt> directory. Then, you can customise the character replacements. You must specifically define this as the <tt>hook_transliterate</tt> function.
 +
 
 +
To use this, return the converted string at the end of the call. You do not need to use the <tt>add_hook</tt> function with this feature.

Latest revision as of 13:32, 15 December 2020

Transliteration in WHMCS

Transliteration is the practice of converting text from one writing system into another in a systematic way.

You can use this with WHMCS to automatically replace characters in client profile data that third-party systems may reject. For example, a domain registrar's API might automatically reject certain characters in received requests.

Custom Transliteration Function

WHMCS includes a default function to find and replace the most common special characters that cause problems. If you need to tailor this to your unique needs, you can define a hook_transliterate function in the /includes/hooks/ directory. This will override the default function and allow you to specify your own character replacements.

<?php

function hook_transliterate($string) {
$string = str_replace("ž","z",$string);
$string = str_replace("é","e",$string);
return $string;
}

?>

An example of the above being used: a client with the name Jéssé žuckérbérg would be converted to Jesse Zuckerberg when performing a request using a module, such as a domain registrar.

Copy-and-paste the code above into a new file and save it in the /includes/hooks/ directory. Then, you can customise the character replacements. You must specifically define this as the hook_transliterate function.

To use this, return the converted string at the end of the call. You do not need to use the add_hook function with this feature.