We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22851
    • 805 Posts
    PaulSuckling Reply #1, 18 years ago
    Hi there.

    I have just deployed AjaxSearch 1.8.0 on this Japanese language website: http://strictlyfansite.webhop.net/. When doing so I noticed that the Japanese language file wasn’t complete. A couple of the sentences were still in English. It became apparent that there was a  reason for this. The text in question is passed into sprintf, and uses number and text format specifiers %d and %s which are replaced by the number of occurrences and search string. The problem is that in Japanese, the sentence structure requires that these two fields are in the opposite order.

    So, to get this to work I modified ajaxSearch.class.inc.php so that it checks the order of the %s and %d identifiers and supplies the count and search string in the correct order to the sprintf function no matter which way they are written in the language file. It would be good if this could be rolled up as a bug fix in the next release.

    Here is a patch for ajaxSearch.class.inc.php:

    469c469,477
    <         $this->varResults['resultInfoText'] = sprintf($resultsFoundText,$nbrs,$searchwords);
    ---
    >         // PMS: Allow for Japanese ordering
    >         if ( strpos($resultsFoundText,'%d') < strpos($resultsFoundText,'%s') )
    >         {
    >             $this->varResults['resultInfoText'] = sprintf($resultsFoundText,$nbrs,$searchwords);
    >         }
    >         else
    >         {
    >             $this->varResults['resultInfoText'] = sprintf($resultsFoundText,$searchwords,$nbrs);
    >         }
    471c479,487
    <         $this->varResults['resultInfoText'] = sprintf($resultsFoundText,$nbrs,$this->searchString);
    ---
    >         // PMS: Allow for Japanese ordering
    >         if ( strpos($resultsFoundText,'%d') < strpos($resultsFoundText,'%s') )
    >         {
    >             $this->varResults['resultInfoText'] = sprintf($resultsFoundText,$nbrs,$this->searchString);
    >         }
    >         else
    >         {
    >             $this->varResults['resultInfoText'] = sprintf($resultsFoundText,$this->searchString,$nbrs);
    >         }
    


    The Japanese characters in the language file were being escaped when I tried to include it as code. I’ll attach it as a file in a separate post...

    Cheers,

    Paul
      YAMS: Yet Another Multilingual Solution for MODx
      YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
      Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
      • 22851
      • 805 Posts
      PaulSuckling Reply #2, 18 years ago
      Finally (I hope). Here is the updated Japanese language file...
        YAMS: Yet Another Multilingual Solution for MODx
        YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
        Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
        • 5811
        • 1,717 Posts
        Thanks Paul for this feedback about Japanese language.

        But may be we could use the placeholders in the japanese language file and don’t change the code.
        See http://www.php.net/manual/en/function.sprintf.php - Example #3 Argument swapping.

        So I suggest to keep the code lines:
        $this->varResults['resultInfoText'] = sprintf($resultsFoundText,$nbrs,$searchwords);
        $this->varResults['resultInfoText'] = sprintf($resultsFoundText,$nbrs,$this->searchString);
        and add the placeholders in the japanese language file. $1 should stand for the number and $2 for the search terms.

        Could you change the file (I can’t in Japanese wink ) and do the tests again. Thanks.

          • 22851
          • 805 Posts
          PaulSuckling Reply #4, 18 years ago
          I can confirm that using $2 then $1 in place of the %s and %d placeholders in the language file works and avoids the need to modify the code. I wish I had known about that before!

          I have attached an updated version of the Japanese language file.

          Merci pour ton aide coroico.

          a+

          Paul
            YAMS: Yet Another Multilingual Solution for MODx
            YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
            Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
            • 5811
            • 1,717 Posts
            De rien. Merci. J’ai moi aussi découvert ces placeholders à cette occasion laugh

            A+
              • 22851
              • 805 Posts
              PaulSuckling Reply #6, 18 years ago
              Sorry. I made a mistake before. My language file had not uploaded to my server so it wasn’t being tested. There was actually a mistake in the last file I posted.

              The correct syntax to use with sprintf is actually %2$s and %1$d, rather than $2 and $1 as I described before.

              Here is the final tested Japanese language file.

              Paul
                YAMS: Yet Another Multilingual Solution for MODx
                YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.