Hello,
It’s completely up to you.
If you want to create a different variable for different languages, then create a new same code by changing the variable name and the language’s local code.
If you want to change language in the the existing one, then just change the language’s local code.
For say, you used the %current_Turkish_date%
in all of your posts and now you want to change the language without editing all of your posts. You can simply edit the code and replace the tr_TR
in tr_TR.UTF-8
to replace the language everywhere.
Example code:
add_action( 'rank_math/vars/register_extra_replacements', function(){
rank_math_register_var_replacement(
'current_Turkish_date',
[
'name' => esc_html__( 'Current Turkish Date.', 'rank-math' ),
'description' => esc_html__( current_Turkish_date_callback(), 'rank-math' ),
'variable' => 'current_Turkish_date',
'example' => current_Turkish_date_callback(),
],
'current_Turkish_date_callback'
);
});
function current_Turkish_date_callback(){
setlocale(LC_ALL, 'fi_FI.UTF-8');
$dateMonthYear = strftime("%d %B");
$year = date('Y');
return $dateMonthYear." ".$year;
}
The variable will be the same: %current_Turkish_date%
, but the output will change to the Finnish language.
You can also change the variable name when creating a new one. Simply replace the word Turkish
in the code with any other word you want.
Here’s the code for the Finnish language:
add_action( 'rank_math/vars/register_extra_replacements', function(){
rank_math_register_var_replacement(
'current_Finnish_date',
[
'name' => esc_html__( 'Current Finnish Date.', 'rank-math' ),
'description' => esc_html__( current_Finnish_date_callback(), 'rank-math' ),
'variable' => 'current_Finnish_date',
'example' => current_Finnish_date_callback(),
],
'current_Finnish_date_callback'
);
});
function current_Finnish_date_callback(){
setlocale(LC_ALL, 'fi_FI.UTF-8');
$dateMonthYear = strftime("%d %B");
$year = date('Y');
return $dateMonthYear." ".$year;
}
The variable will be: %current_Finnish_date%
Here you can find all the language codes:
https://www.webenfo.com/list-of-php-language-locale-code.html
Hope that helps, and please do not hesitate to let us know if you need our assistance with anything else.
Thank you.