Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Allow taxonomy labels to be translated #26

Open
nickcernis opened this issue Dec 1, 2015 · 14 comments
Open

Allow taxonomy labels to be translated #26

nickcernis opened this issue Dec 1, 2015 · 14 comments
Labels

Comments

@nickcernis
Copy link
Contributor

As reported by a customer here, Listing taxonomy labels are not currently translatable.

The customer provided the following screenshots from WPML support, who suggest using the gettext filter to add translation support for drop-down labels:

741574-untranslatedsearchlabels

741574-htmlformnottranslatingsearchlabels

741574-exampleflterfunction

@nickcernis nickcernis added the bug label Dec 1, 2015
@nathanrice
Copy link
Contributor

I can understand wanting to translate strings that display on the front end, but changing the name of the select element is a bad idea. It messes with the form handlers.

However, if you're talking about the $data['labels'] array, those should already be translatable.

https://github.com/copyblogger/agentpress-listings/blob/develop/includes/class-listings.php#L71-L84

@nickcernis
Copy link
Contributor Author

It looks like the WPML team highlighted the wrong section in the screenshot above. The customer needs to translate the contents of the first <option> value for each select field (the taxonomy labels).

The issue is that custom taxonomy labels that people declare at Listings → Register Taxonomies aren't currently translatable via WPML. i.e. $data['labels']['name'] on line 3 here:

<?php
echo "<select name='$tax' id='$tax' class='agentpress-taxonomy'>\n\t";
echo '<option value="" ' . selected($current == '', true, false) . ">{$data['labels']['name']}</option>\n";
foreach ((array)$terms as $term)
    echo "\t<option value='{$term->slug}' " . selected($current, $term->slug, false) . ">{$term->name}</option>\n";
echo '</select>';

[From: https://github.com/copyblogger/agentpress-listings/blob/develop/includes/class-property-search-widget.php#L46 ]

I'm talking to the WPML team to clarify what they require from us here, but at this stage it seems possible that the plugin may not be declaring the taxonomy labels using a Gettext function:

<?php
function register_taxonomies() {
    foreach ((array)$this->get_taxonomies() as $id => $data) {
        register_taxonomy($id, array('listing'), $data);
    }
}

[From: https://github.com/copyblogger/agentpress-listings/blob/develop/includes/class-taxonomies.php#L298 ]

The $data value you see there is being pulled from the wp_options table's agentpress_taxonomies row, which contains a serialised array of taxonomy data like this (for a taxonomy named “status”):

my_outpost_rocks___127_0_0_1___rmd___wp_options___phpmyadmin_4_0_10deb1

It looks like taxonomies are being registered with data that doesn't use a Gettext function, but there may be other workarounds for this. Will report back if I hear more from WPML.

@nathanrice
Copy link
Contributor

It looks like taxonomies are being registered with data that doesn't use a Gettext function

Ah, I see. Yes, that's correct. But by necessity. We allow users to create custom taxonomies for listings using an admin UI. Unfortunately, this means that they are not translatable, as they aren't hardcoded.

@NicktheGeek
Copy link
Contributor

Seems like when I worked support and this came up I suggested to users they could create additional taxonomies for the translated language and use a plugin to conditionally load the widget per the translation the site was using.

It's a bit more work but allows for better localization as you may not present the same options or present them in exactly the same way depending on the culture you are selling to.

@nickcernis
Copy link
Contributor Author

Thanks very much for confirming, Nathan. I thought that might be the case.

Many thanks also to Nick for the suggested workaround – I'll be sure to offer that as an option here.

WPML allows taxonomy label translation via WPML → Translate Taxonomies (even dynamically created ones). I was hoping we'd be able to automate translation by using the taxonomy label we already pull from wp_options to retrieve the translated equivalent from WPML, then output that as the first option label, instead of using the raw untranslated string from the options table as we do now.

Still looking into this, but will let you know if anything comes of it.

@nickcernis
Copy link
Contributor Author

I have a potential fix for this in the PR above. It relies on WPML, but most customers translating AgentPress Listings tend to use that for their translations.

@ghost
Copy link

ghost commented Nov 28, 2017

nickcernis, this fix isn't working in my case. The first field of the <Select> element isn't translated.

@nickcernis
Copy link
Contributor Author

@uritzo It's still working for me in my tests. I commented at #27 with more info about how I'm setting this up. Following up with WPML support to debug your WP/WPML installation may be worthwhile here. The fix that the pull request was based on originally came from their team.

@ghost
Copy link

ghost commented Nov 29, 2017

Thanks @nickcernis, now is working perfect thanks! Seems that in the last update of the plugin "agentpress listings 1.2.7, the solution is not implemented by default. Thank you, you saved my ass.

@ghost
Copy link

ghost commented Feb 13, 2018

Hello @nickcernis did you tried to update to the last version? Because I need to do it and I don't know if its gonna work. THANKS

@nickcernis
Copy link
Contributor Author

@uritzo I have not tried it with the latest WPML yet. Maybe take a backup or snapshot first?

@ghost
Copy link

ghost commented Feb 13, 2018

Yes I actually tried in the staging site. It's not working anymore... But I can't find why! Im not that good on solving code problems so if you find a way to keep up to date with WPML just put it here please! Thanks for the quick answer. Tested on WPML 3.9.3 AND WPML String Translation 2.7.3

@nickcernis
Copy link
Contributor Author

@uritzo You're welcome! You may be best contacting WPML support if an update has caused this; their team originally supplied the code used above.

@ghost
Copy link

ghost commented Feb 13, 2018

I found a thread talking about the same issue. They say "We previously tried to get in touch with the plugin author but never got a response"

Maybe its time to "match" and make us all happy 💯 👍 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants