Discussion:
Best way to allow slug rewrite of CPT via i18n
Tom Barrett
2013-11-26 21:48:36 UTC
Permalink
Hello

What is the best way to allow the of a custom post type to change via
translation.

I'm currently doing this:
'rewrite' => array( 'slug' => __( 'glossary', WPG_TEXTDOMAIN ) ),

Is that good?

Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
Nicholas Ciske
2013-11-26 21:52:48 UTC
Permalink
You probably want to run it through sanitize_title before you attempt to use it... lest a wily translator blow up your permalinks ;-)

http://codex.wordpress.org/Function_Reference/sanitize_title
_________________________
Nick Ciske
http://thoughtrefinery.com/
@nciske
Post by Tom Barrett
Hello
What is the best way to allow the of a custom post type to change via
translation.
'rewrite' => array( 'slug' => __( 'glossary', WPG_TEXTDOMAIN ) ),
Is that good?
Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
Nikola Nikolov
2013-11-26 21:59:23 UTC
Permalink
Just a warning here, consider the following situation:

- Multilingual site(whichever plugin).
- Multiple languages, each with it's own translation file(therefore each
one declaring it's own slug for your post type).
- The user regenerates the permalinks by going to Settings > Permalinks.
Only the permalinks with the currently active language's slug are
regenerated. All translation permalinks are not.
- You go to the front-end and visit the site in a different language. Your
links now use the correct slug for that language, but they end-up in 404's.

I know that ultimately it's great to be able to have different slugs for
each language, but it's really difficult to do so.

A different approach that I can suggest is to use a plugin option to set
the slug(from a settings page). This way, the slug can still be changed and
if anyone else is trying to create multiple rewrite rules for your
plugin(for each language for instance), they are still able to do so.

While working on my own multilingual plugin, I came across that situation -
I wanted to let the user define a unique slug for each language - in the
end it mostly worked, but with a lot of hacking.

So, my advice is - make the slug dynamic via a plugin option and that's it.
Post by Nicholas Ciske
You probably want to run it through sanitize_title before you attempt to
use it... lest a wily translator blow up your permalinks ;-)
http://codex.wordpress.org/Function_Reference/sanitize_title
_________________________
Nick Ciske
http://thoughtrefinery.com/
@nciske
Post by Tom Barrett
Hello
What is the best way to allow the of a custom post type to change via
translation.
'rewrite' => array( 'slug' => __( 'glossary', WPG_TEXTDOMAIN ) ),
Is that good?
Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Otto
2013-11-26 21:59:13 UTC
Permalink
Three things:

- What Nicholas said about sanitizing it as a title, so that your
urls don't break
- You'll probably want to use _x to define a context for this, to allow it
to be a separate translation for this use of "glossary" from any others you
might have elsewhere
- You can't use a defined constant for the text domain, it needs to be a
plain string

So, like this:

'rewrite' => array( 'slug' => sanitize_title( _x( 'glossary', 'rewrite
slug', 'wp-glossary' ) ) ),

-Otto
Post by Nicholas Ciske
You probably want to run it through sanitize_title before you attempt to
use it... lest a wily translator blow up your permalinks ;-)
Post by Nicholas Ciske
http://codex.wordpress.org/Function_Reference/sanitize_title
_________________________
Nick Ciske
http://thoughtrefinery.com/
@nciske
Post by Tom Barrett
Hello
What is the best way to allow the of a custom post type to change via
translation.
'rewrite' => array( 'slug' => __( 'glossary', WPG_TEXTDOMAIN ) ),
Is that good?
Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Tom Barrett
2013-11-28 08:47:15 UTC
Permalink
Thank you!

*adds to list updates for next version*

// Sent by Nexus
Post by Otto
- What Nicholas said about sanitizing it as a title, so that your
urls don't break
- You'll probably want to use _x to define a context for this, to allow it
to be a separate translation for this use of "glossary" from any others you
might have elsewhere
- You can't use a defined constant for the text domain, it needs to be a
plain string
'rewrite' => array( 'slug' => sanitize_title( _x( 'glossary', 'rewrite
slug', 'wp-glossary' ) ) ),
-Otto
Post by Nicholas Ciske
You probably want to run it through sanitize_title before you attempt to
use it... lest a wily translator blow up your permalinks ;-)
Post by Nicholas Ciske
http://codex.wordpress.org/Function_Reference/sanitize_title
_________________________
Nick Ciske
http://thoughtrefinery.com/
@nciske
Post by Tom Barrett
Hello
What is the best way to allow the of a custom post type to change via
translation.
'rewrite' => array( 'slug' => __( 'glossary', WPG_TEXTDOMAIN ) ),
Is that good?
Thanks!
--
http://www.tcbarrett.com | http://gplus.to/tcbarrett |
http://twitter.com/tcbarrett
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...