Make WordPress Core

Opened 7 years ago

Last modified 14 months ago

#39587 new defect (bug)

link problems with language settings

Reported by: aansel's profile aansel Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7
Component: I18N Keywords: dev-feedback
Focuses: Cc:

Description (last modified by ocean90)

Dear Developers!

After WP versiion 4.7 i think i found a bug it is not listed.

In version 4.7 we have the option to have a X site language but with Y language admin dashboard. (clever idea Cheers for it!!)

But if i use the dashboard in Y language >>> it changes the links (after you edit something) language to Y language. (maybe it is related ~only in/with woocommerce)

for example the link changes from "product" to "termek" or vica-versa...

makes many pages unreachable...

let me know if you need any further information or help!

Very Best regards!!

Ben

Change History (17)

#1 @SergeyBiryukov
7 years ago

  • Component changed from General to I18N
  • Keywords reporter-feedback added

Hi @aansel, welcome to Trac! Thanks for the report.

Do you use a multilingual plugin? Does it still happen with all plugins disabled and a default theme (Twenty Seventeen or Twenty Sixteen) activated?

#2 @ocean90
7 years ago

  • Description modified (diff)
  • Keywords reporter-feedback removed

This happens because the rewrite slug of the post type product is translatable, see https://github.com/woocommerce/woocommerce/blob/7873a328ce871668143465f605df93b1683b0795/includes/class-wc-post-types.php#L258.

#3 @SergeyBiryukov
7 years ago

#39416 was marked as a duplicate.

#4 @aansel
7 years ago

okay Guys!!

sorry to took so long to reply!
Im not sure im understand well what You wrote?!
My post is a duplicate?! (becose 39416 is another post)

Please tell me if you need any further info i will reply lot quicker!

Wish You the best!!
Ben

#5 @grapplerulrich
7 years ago

No the other ticket was marked as a duplicate of this ticket.

#6 @ocean90
7 years ago

#41116 was marked as a duplicate.

#7 @bradadams
6 years ago

  • Severity changed from normal to major

This is a super critical issue, I'm unsure how it's not been addressed yet 🤔. I created the https://core.trac.wordpress.org/ticket/41116 ticket for this 5 months ago and this one has nearly been around for a year.

We just spent like 40 minutes scratching our heads as to why all our localized permalinks went down the plughole after we re-saved them. The steps were:

  1. Our user account has language set to English.
  2. Created a new site for German in multisite setup
  3. Localized some strings that are used in permalink rewrites
  4. Visited the permalink page on new German site, and hit refresh permalinks
  5. Posts across the site show the new permalink (with localized URL), but clicking them returns a 404.
  6. Visiting the posts screen in admin, and clicking "view" takes you to the correct URL (using English permalink localization in this case).

So of course we're like wtf, why's it showing english if all settings are clearly pointing to German/Deutsch?

Luckily we remembered this issue, and just had to change our user language to the relevant sites language before making the re-save on the permalinks screen.

If someone can point me in the right direction I'll try and fix it myself, either way, over the holidays I'll see if I can figure out what's causing it...

Version 0, edited 6 years ago by bradadams (next)

#8 @ocean90
6 years ago

#43991 was marked as a duplicate.

#9 @realloc
6 years ago

I had the same issue today (Version 4.9.6) and patched that by disabling the user's option (https://tfrommen.de/disable-user-admin-language-in-wordpress/) to change the language.

This is far from perfect but at least the feature creates no problems at the moment.

I understand that $wp_rewrite is global and the call to flush_rewrite_rules is hard-wired in options-permalink.php. Could a check for a difference between get_locale() and the user's language (maybe with an admin_message that informs about the implications) a good starting point to give a hand here?

#10 @eddhurst
5 years ago

@tferry noticed this issue earlier this week, and we've been investigating. I agree, this still happens and is relatively easy to reproduce:

  1. Make sure to have at least another language installed to help demo this...
  1. Set site language to German
  2. Create new custom post type, set slug to use a translatable string ("media" is good example that WP has a translatable string for in core)
  3. Regenerate permalinks

Note: Permalinks should now go to: wp.local/Medien/postname

  1. Change user preferred language to english
  2. Go to CPT page and hover on "view"

Note: Permalink should suggest that the permalink is wp.local/media/postname

  1. Regenerate permalinks again

Note: Permalinks will now actually change to wp.local/media/postname

As mentioned earlier - we can see that the slug ends up changing based on the admin preferred language rather than the site language - which isn't immediately obvious why.

Ultimately the localisation scripts are running first and doing all the translation - including the slug. This seems reasonable, as we do need the other strings (CPT labels etc) to be translated.

To fix this at the highest level it seems like it would make sense to hijack the arguments in the class definition of WP_Post_Type and re-translate based on site language, that way we can reliably ensure that it will always be correct anywhere else that it is used.

This ticket was mentioned in Slack in #core by tferry. View the logs.


5 years ago

#12 @swissspidy
21 months ago

#40298 was marked as a duplicate.

#13 @rmpel
14 months ago

I'd like to have it on record that we're now 6 years in, and this issue is still relevant.
I appreciate that it is a hard thing to fix, or that it may even be impossible or a very low prio issue, but I'd even be happy with a temporary solution.

I've tried setting the locale to german (we have the exact same situation as described above) when pagenow = options-permalinks.php, I've tried setting the global $current_user->locale to german, or unset it, nothing seems to be helping.

Perhaps I am forgetting steps to this fix, perhaps the solution lies elsewhere...

Some guidance would be greatly appreciated.

#14 follow-up: @swissspidy
14 months ago

  • Keywords dev-feedback added
  • Severity changed from major to normal

It's generally discouraged to make post type slugs translatable because you will constantly run into situations like this, or permalinks breaking because translations get updated.

In theory, on options-permalink.php we could wrap the flush_rewrite_rules() call in a switch_to_locale() to always use the site language, but this alone is no guarantee that nothing else could break. Especially since flush_rewrite_rules(); is called in many places both in core and plugins.

So I would consider closing this as a wontfix because it's plugins doing_it_wrong(). Adding dev-feedback though to get more feedback.

#15 @realloc
14 months ago

Thanks for your comment @swissspidy but I don't believe that users would be happy to see that the slugs of their custom post types are not translatable. I'd prefer to take that point of view, instead of looking only at the technical limitations.

#16 @swissspidy
14 months ago

I am not saying they should not be translatable. If you want to make post type slugs translatable it's better to do that differently though, for example via a dedicated settings field.

#17 in reply to: ↑ 14 @rmpel
14 months ago

Replying to swissspidy:

It's generally discouraged to make post type slugs translatable because you will constantly run into situations like this, or permalinks breaking because translations get updated.

If only we lived in a single-language world ;)

In theory, on options-permalink.php we could wrap the flush_rewrite_rules() call in a switch_to_locale() to always use the site language, but this alone is no guarantee that nothing else could break. Especially since flush_rewrite_rules(); is called in many places both in core and plugins.

Tried that, doesn't work. In fact; merely accessing the options-permalinks.php page already changes the permalinks in the rewrite-rules option value.

So I would consider closing this as a wontfix because it's plugins doing_it_wrong(). Adding dev-feedback though to get more feedback.

I understand a "won't fix", but at least a decent work-around would be helpful. Perhaps a filter that allows a developer to change the slug before it enters the database / htaccess / etc. ??

I am not saying they should not be translatable. If you want to make post type slugs translatable it's better to do that differently though, for example via a dedicated settings field.

Yeah, I think we are going in that direction too. Still, should not be necessary...

Thanks for your insight!

R.

Note: See TracTickets for help on using tickets.