jquery-fastLiveFilter icon indicating copy to clipboard operation
jquery-fastLiveFilter copied to clipboard

Accents

Open jacmaes opened this issue 12 years ago • 4 comments

Hi there,

I love this plugin, but I have one request. Would it be possible to broaden the search for accented characters in foreign language?

Let me explain with one concrete example:

In Spanish, I want to look for the word "adaptation", which would translate to "adaptación". If I type "adaptación", it works as expected. Now if I type "adaptacion", .i.e. without the accent on the "a", it fails to recognize that term.

In Spanish it is (unfortunately) a common practice to omit accents when searching for something because it requires for extra keystroke, and people are lazy.

Thanks.

jacmaes avatar Oct 19 '12 11:10 jacmaes

Good idea, and it's possible.

Probably the way to solve it is to replace the accents (latinize?) in the search cache on first load, and replace them in search term too right before querying (in case anyone does use them).

awbush avatar Oct 19 '12 12:10 awbush

Hi there,

Can you give an example of how to accomplish this ?

Thanks.

pcout avatar Jun 07 '14 00:06 pcout

+1

Thunderlab avatar May 20 '16 01:05 Thunderlab

Hi, add this code to the plugin:

        var rExps = [{
            re: /[\xC0-\xC6]/g,
            ch: "A"
        }, {
            re: /[\xE0-\xE6]/g,
            ch: "a"
        }, {
            re: /[\xC8-\xCB]/g,
            ch: "E"
        }, {
            re: /[\xE8-\xEB]/g,
            ch: "e"
        }, {
            re: /[\xCC-\xCF]/g,
            ch: "I"
        }, {
            re: /[\xEC-\xEF]/g,
            ch: "i"
        }, {
            re: /[\xD2-\xD6]/g,
            ch: "O"
        }, {
            re: /[\xF2-\xF6]/g,
            ch: "o"
        }, {
            re: /[\xD9-\xDC]/g,
            ch: "U"
        }, {
            re: /[\xF9-\xFC]/g,
            ch: "u"
        }, {
            re: /[\xC7-\xE7]/g,
            ch: "c"
        }, {
            re: /[\xD1]/g,
            ch: "N"
        }, {
            re: /[\xF1]/g,
            ch: "n"
        }];
        $.each(rExps, function() {
            filter = filter.replace(this.re, this.ch);
            innerText = innerText.replace(this.re, this.ch);
        });

before :

if (innerText.toLowerCase().indexOf(filter) >= 0) {

rodolfosaraiva avatar Sep 22 '16 13:09 rodolfosaraiva