Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    How to translate captive portal reply messages?

    Scheduled Pinned Locked Moved Captive Portal
    11 Posts 3 Posters 1.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kabeda
      last edited by

      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.

      GertjanG 1 Reply Last reply Reply Quote 0
      • GertjanG
        Gertjan @kabeda
        last edited by

        @kabeda

        Instead of :

        8f49079d-d5a9-4cc6-96cd-ceee312d809b-image.png

        you want :

        e1079144-a6d3-4162-8a3c-14a442d074af-image.png

        C'est ça ?

        No "help me" PM's please. Use the forum, the community will thank you.
        Edit : and where are the logs ??

        H 1 Reply Last reply Reply Quote 0
        • H
          heper @Gertjan
          last edited by

          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."

          GertjanG 1 Reply Last reply Reply Quote 1
          • GertjanG
            Gertjan @heper
            last edited by

            @heper

            Yep.
            From :
            eb01a87c-cbf6-44f8-936a-a0ffc5ce9fee-image.png
            To :
            3be6fb6b-3502-4bee-983b-5638e4260e1b-image.png

            will take care of many messages.

            No "help me" PM's please. Use the forum, the community will thank you.
            Edit : and where are the logs ??

            K 1 Reply Last reply Reply Quote 0
            • K
              kabeda @Gertjan
              last edited by

              @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.

              GertjanG 1 Reply Last reply Reply Quote 0
              • GertjanG
                Gertjan @kabeda
                last edited by Gertjan

                @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.php

                Locate :

                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 :

                d70db357-da74-4c9b-968b-f878bd0773d3-image.png

                I'll add an entry in redmine for this.
                edit : done : https://redmine.pfsense.org/issues/14350

                No "help me" PM's please. Use the forum, the community will thank you.
                Edit : and where are the logs ??

                K 1 Reply Last reply Reply Quote 0
                • K
                  kabeda @Gertjan
                  last edited by

                  @gertjan Hi,
                  Thanks, it's ok now.

                  K 1 Reply Last reply Reply Quote 0
                  • K
                    kabeda @kabeda
                    last edited by

                    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.

                    GertjanG 1 Reply Last reply Reply Quote 0
                    • GertjanG
                      Gertjan @kabeda
                      last edited by Gertjan

                      @kabeda

                      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"

                      No "help me" PM's please. Use the forum, the community will thank you.
                      Edit : and where are the logs ??

                      K 1 Reply Last reply Reply Quote 0
                      • K
                        kabeda @Gertjan
                        last edited by

                        @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.

                        K 1 Reply Last reply Reply Quote 0
                        • K
                          kabeda @kabeda
                          last edited by

                          Hi,
                          I think I finally found how to do it.

                          first, in
                          /user/local/www/services-captiveportal.php

                          find 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
                          after

                          header("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.

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.