Jump to content

Non latin chacters in friendly URL


alfa123

Recommended Posts

How can I display non-latin characters in friendly URLs? In my case thai letters.

 

This should be quite easy using url encoding.

 

For example, thai word for "shoe":

รองเท้า

 

with url encoding it's:

%E0%B8%A3%E0%B8%AD%E0%B8%87%E0%B9%80%E0%B8%97%E0%B9%89%E0%B8%B2

 

But prestashop filters out the % character and the result is:

E0B8A3E0B8ADE0B887E0B980E0B897E0B989E0B8B2

 

 

I've looked around on thai websites with thai letters in the URL. The HTML source contain url encoded characters such as the example above.

 

Example of such page:

http://www.bbfashion-shop.com/category/11/%E0%B8%9E%E0%B8%A3%E0%B8%B5%E0%B8%AD%E0%B8%AD%E0%B9%80%E0%B8%94%E0%B8%AD%E0%B8%A3%E0%B9%8C-%E0%B8%81%E0%B8%A3%E0%B8%B0%E0%B9%80%E0%B8%9B%E0%B9%8B%E0%B8%B2%E0%B9%81%E0%B8%9F%E0%B8%8A%E0%B8%B1%E0%B9%88%E0%B8%99/

Link to comment
Share on other sites

I've just tried to add url-encoded string into link_rewrite manually thru phpMyAdmin and it WORKS! =)

 

However, it does NOT work if I enter thai letter. It works only if I enter url encoded.

 

Here is the result:

http://veenafashion.com/th/5-%E0%B9%80%E0%B8%AA%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%9C%E0%B9%89%E0%B8%B2

 

In the address bar it shows thai letters.

Edited by alfa123 (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

To be able to input Thai letters in products, there are 3 steps:

Step 1

FIle#1: classes/Validate.php

Change from

public static function isLinkRewrite($link)
{
return preg_match('/^[_a-zA-Z0-9\-\pL]+$/u', $link);
}

To

public static function isLinkRewrite($link)
{
  return preg_match('/^[_a-zA-Z0-9ก-๙\-\pL]+$/u', $link);
}

 

Step 2

File #2: shop_root/js/admin.js, at the very beginning of the file, look for function str2url(str,encoding,ucfirst)

Change from

str = str.replace(/[^a-z0-9\s\'\:\/\[\]-]\\u00A1-\\uFFFF/g,'');

to

str = str.replace(/[^a-z0-9ก-๙\s\'\:\/\[\]-]\\u00A1-\\uFFFF/g,'');

 

Now we can enter Thai characters in Catalog > Products > SEO > Friendly URL.

 

Step 3

Finally, I guess .htaccess need to be changed (try messing around [_a-zA-Z0-9-]), but unfortunately I could not get it working. Still looking for a better solution.

Link to comment
Share on other sites

Got it working, there are only 2 files need to be changed:

1. classes/Validate.php

Search for:

return preg_match('/^[_a-zA-Z0-9\-\pL]+$/u', $link);

Replace with

return preg_match('/^[_a-zA-Z0-9\-\pL\pM]+$/u', $link);

 

 

2. classes/Dispatcher.php

Search for /pL, and replace with /pL/pM

 

Then we can input Thai and display the nice friendly URL. It turns out to be quite easy, credit must be given to the Prestashop team for delivering us such a wonderful system.

 

This is for v1.5.0.15

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...