How to translate captive portal reply messages?
-
Hi,
I installed on my server pfsense 2.6.0, I managed to make captive portal work with freeradius3.
My little concern is that I would like the reply messages to be in French. The company's employees are French-speaking. Example: I receive "Invalid credentials specified" and I would like a clearer message like "Vos identifiants sont incorrects".
I can't find how to do it. -
-
i would think this is done automatically based on the locale of the browser?
there seems to be a translation in the source:
#: src/usr/local/captiveportal/index.php:158
#: src/usr/local/captiveportal/index.php:234
msgid "Invalid credentials specified."
msgstr "Les identifiants fournis ne sont pas valides." -
-
@gertjan
I already tried to change the interface language, I got the message in french if I test in Diagnostic->Authentication but in real situation wich means if I try to give false username or password in the captive portal page I still got messages in english. -
@kabeda said in How to translate captive portal reply messages?:
in the captive portal page I still got messages in english.
....
Pas possible ....I'm using the portal for a decade or so, and today I've found out that text messages, as we can find in /usr/local/captiveportal/index.php - line 215 :
$errormsg = gettext("Invalid credentials specified.");
can not be translated.
Because, while the /usr/local/captiveportal/index.php is 'exectued' by PHP, no where the needed "set_language();" function is called to set the pfSense PHP text domain.
To make a long story short :
Open
/usr/local/captiveportal/index.phpLocate :
header("Expires: 0"); header("Cache-Control: no-cache, no-store, must-revalidate"); header("Pragma: no-cache"); header("Connection: close");
nearly at the top, and add :
if (!function_exists('set_language')) { require_once("pfsense-utils.inc"); } set_language();
I've copied these lines from /usr/local/www/guiconfig.inc - as that is the place where the pfSEnse GUI becomes 'language aware'.
Now I see :
I'll add an entry in redmine for this.
edit : done : https://redmine.pfsense.org/issues/14350 -
@gertjan Hi,
Thanks, it's ok now. -
Hi,
It would be interesting to add in the captive portal configuration the possibility to choose the language displayed to users so that the global interface is in one language and the captive portal authentication page in another language.
I'm trying to get into it but I'm not yet familiar with programming pfsense. -
Remove what you've added (see above) :
if (!function_exists('set_language')) { require_once("pfsense-utils.inc"); } set_language();
and replace it with :
global $g; $lang = "fr_FR.UTF-8"; putenv("LANG={$lang}"); setlocale(LC_ALL, $lang); textdomain("pfSense"); bindtextdomain("pfSense", "/usr/local/share/locale"); bind_textdomain_codeset("pfSense", $lang);
I presume you want 'fr_FR' ;)
Btw : I'm totally not aware what the side impacts are.
Could be nothing .... could be not nothing.
"It works for me" -
@gertjan
Thanks, I already put that yesterday and it works but in fact my real goal is to generalize the option by leaving the choice through the webgui. I know it's heavy to program but I start slowly. -
Hi,
I think I finally found how to do it.first, in
/user/local/www/services-captiveportal.phpfind and add what are in remarks
if ($a_cp[$cpzone]) { $cpzoneid = $pconfig['zoneid'] = $a_cp[$cpzone]['zoneid']; $pconfig['descr'] = $a_cp[$cpzone]['descr']; $pconfig['cinterface'] = $a_cp[$cpzone]['interface']; $pconfig['language_cp'] = $a_cp[$cpzone]['language_cp']; // get the language from the config // Check if is not set then get the global language if (!isset($pconfig['language_cp'])) { $pconfig['language_cp'] = $g['language']; } // Check if is not set then get the global language $pconfig['maxproc'] = $a_cp[$cpzone]['maxproc']; $pconfig['maxprocperip'] = $a_cp[$cpzone]['maxprocperip'];
and
$newcp['descr'] = $_POST['descr']; $newcp['language_cp']=$_POST['language_cp']; // get the language from the post variables $newcp['maxproc'] = $_POST['maxproc'];
and
$section->addInput(new Form_Select( 'cinterface', '*Interfaces', explode(",", $pconfig['cinterface']), get_configured_interface_with_descr(), true ))->addClass('general')->setHelp('Select the interface(s) to enable for captive portal.'); // add the input in the form $section->addInput(new Form_Select( 'language_cp', '*Language', $pconfig['language_cp'], get_locale_list() ))->setHelp('Choose a language for the Captive portal'); // add the input in the form $section->addInput(new Form_Input( 'maxprocperip', 'Maximum concurrent connections', 'number', $pconfig['maxprocperip'], ['min' => '0', 'max' => '100'] ))->setHelp('Limits the number of concurrent connections to the captive portal HTTP(S) server. This does not set how many users can be logged in ' . 'to the captive portal, but rather how many connections a single IP can establish to the portal web server.');
then in /usr/local/captiveportal/index.php
afterheader("Expires: 0"); header("Cache-Control: no-cache, no-store, must-revalidate"); header("Pragma: no-cache"); header("Connection: close"); global $cpzone, $cpzoneid; $cpzone = strtolower($_REQUEST['zone']); $cpcfg = $config['captiveportal'][$cpzone];
add
$lang = $config['captiveportal'][$cpzone]['language_cp']; // get the language from the config putenv("LANG={$lang}"); setlocale(LC_ALL, $lang); textdomain("pfSense"); bindtextdomain("pfSense", "/usr/local/share/locale"); bind_textdomain_codeset("pfSense", $lang); // apply like done by pfsense
That's all it works for me, I don't know how to show the changes with github.