slug translation implemented, needs review

Any suggestions on how to improve qTranslate? Post here!

slug translation implemented, needs review

Postby fabio84 » Fri Aug 28, 2009 3:08 pm

Hi

I work for an Italian consulting company that mostly builds web sites, and we have deployed wordpress and qtranslate for many customers.

We wanted to add to qTranslate the possibility to specify a different slug for each language, so I worked on it, and developed a module that implements this.

For now this works with the slug of posts and pages, tags and categories are not yet supported.
TODO List:
* generate translated slug automatically from the translated title
* check if the slug is already used, and add a progressive number in this case
* force the use of the translated slug if defined
* force to show a page/post only at the correct URL
* try to redirect from a wrong URL to a correct URL
* keep track of renamed slugs, redirecting from old to new slugs
* translate categories and tags slugs.

I see that many people here were interested in this feature, but this is just a first "alpha" release and I think it's not ready for production yet. We have not used it in production yet, so I think you shouldn't. Use at your risk, if you really want to test and develop it use an offline testing/development site, after a good backup.

This module may be activated on wordpress with qtranslate activated. Wordpress doesn't enforce dependence between modules, so if you try to activate this on a site without qtranslate, or deactivate qtranslate without deactivating this, you may break something and make your site unavailable.

It's just a first step, and it seems to work to me. I hope my code will be merged in a future release of qTranslate.

If you are interested, read the code attached, and ask. An explanation here would be too long.
Attachments
qtranslate-slug.php.0.1.txt
qTranslate slug 0.1
(23.33 KiB) Downloaded 862 times
fabio84
 
Posts: 4
Joined: Fri Aug 28, 2009 12:19 pm
Location: Faenza, Italy

Re: slug translation implemented, needs review

Postby Blutarsky » Tue Oct 06, 2009 7:23 pm

Nice mate, can you explain what the plugin does currently? I'm interested in the automated slug generation.

I wonder how your plugin works; I mean what happens when you have multiple translations for the same post? does your plugin generate translated slugs accordingly?
Blutarsky
 
Posts: 44
Joined: Tue Feb 17, 2009 11:55 am

Re: slug translation implemented, needs review

Postby Blutarsky » Wed Oct 07, 2009 1:48 pm

Quite interested in automatic tag and category generation. Could help beta testing.... Are you there?
Blutarsky
 
Posts: 44
Joined: Tue Feb 17, 2009 11:55 am

Re: slug translation implemented, needs review

Postby andrewstaffell » Fri Oct 09, 2009 10:14 am

hi, have installed the slug translation plugin - great to see this implemented...

found one problem:
the plugin doesn't remap slugs/URLs generated by qtrans_generateLanguageSelectCode()

so, let's say I'm on a page called http://mysite.com/es/contacto

the links generated by qtrans_generateLanguageSelectCode() are, eg:
http://mysite.com/contacto [should be /contact]
or
http://mysite.com/it/contacto [should be /it/contatto]

the normal links (generated by wp_list_pages() or whatever) work correctly.

tried a few things but can't see a quick fix... any tips?

thanks
andrewstaffell
 
Posts: 2
Joined: Fri Oct 09, 2009 10:08 am

Re: slug translation implemented, needs review

Postby Blutarsky » Sat Oct 10, 2009 2:31 pm

How does the plugin work? Does it generate a slug per each language? For example, 1 post can have multiple slugs?
Blutarsky
 
Posts: 44
Joined: Tue Feb 17, 2009 11:55 am

Re: slug translation implemented, needs review

Postby Qian Qin » Sat Oct 10, 2009 3:29 pm

qT doesn't generate any slugs at all. The slug you see is generated by Wordpress using the default language title. I'll look into this as soon as I have time. :)
Qian Qin
Site Admin
 
Posts: 964
Joined: Thu Jun 19, 2008 12:14 pm
Location: Germany

Re: slug translation implemented, needs review

Postby Blutarsky » Sat Oct 10, 2009 3:47 pm

Slug translation along with tags and categories, would be fantastic!

But really I don't know how you could cope dealing with 1 post + multiple slugs... while it's clear how the brilliant idea behind qtranslate works, managing language tags, it's difficult to imagine how you couldmanage multiple slugs for 1 post....
Blutarsky
 
Posts: 44
Joined: Tue Feb 17, 2009 11:55 am

Re: slug translation implemented, needs review

Postby fabio84 » Mon Oct 12, 2009 3:23 pm

Thanks for the interest... Meanwhile, i implemented a new version that fixes a couple of bugs, but this is not yet ready for all, it's just a proof of concept for developers, and it still needs some work.

From the point of view of the user, the plugin adds in the post and page edit forms a field for each language activated in qTranslate, where you can manually specify a different slug for each language.

It generates links for posts and pages using the translated slug, but to switch to another language (for now) you have to embed in the theme one of the function defined by my plugin: qTranslateSlug_generateLanguageSelectCode($style, $id) or qTranslateSlug_getSelfUrl($lang).

From the point of view of the developer, it defines a table where you can store a different slug for each language, for each page and post (and hopefully in future also tags and categories):
Code: Select all
'CREATE TABLE '.$wpdb->prefix.'qtranslate_slug (
   qts_type TINYINT(3) UNSIGNED NOT NULL,
   qts_id BIGINT(20) UNSIGNED NOT NULL,
   qts_lang VARCHAR(6) NOT NULL,
   qts_slug VARCHAR(200) NOT NULL,
   PRIMARY KEY id_lang (qts_type, qts_id, qts_lang),
   KEY post_name_lang (qts_slug, qts_type, qts_lang)
);'

Then defines a filter for the wordpress request, and checks if the requested path is a translated slug for a page or post in the current language. If it can't find it, then it continues using the normal slug system.
It defines also the filters called when pages and posts links are generated, so when wordpress generates a link for a given post or page id, the link contains the translated slug.
Attachments
qtranslate-slug.php.0.3.txt
(26.43 KiB) Downloaded 669 times
fabio84
 
Posts: 4
Joined: Fri Aug 28, 2009 12:19 pm
Location: Faenza, Italy

Re: slug translation implemented, needs review

Postby andrewstaffell » Thu Oct 15, 2009 8:50 am

thanks for the update - seems to work perfectly. would be really great to see this incorporated in the main plugin...

A
andrewstaffell
 
Posts: 2
Joined: Fri Oct 09, 2009 10:08 am

Re: slug translation implemented, needs review

Postby Madness » Tue Nov 10, 2009 2:19 pm

A question, why are you using a separate table instead of say, custom fields?

Also this board needs Openid support. :)
Madness
 
Posts: 3
Joined: Tue Nov 10, 2009 2:14 pm

Next

Return to qTranslate Suggestions Forum

Who is online

Users browsing this forum: No registered users and 0 guests