libreform / wp-libre-form

Easy native HTML5 forms for WordPress. Version 1.5 is unmaintained, but works without issue. 2.0 has been rewritten from the ground, and can be found at https://github.com/libreform/libreform
https://wordpress.org/plugins/wp-libre-form
GNU General Public License v3.0
67 stars 27 forks source link

String translation support #33

Closed k1sul1 closed 8 years ago

k1sul1 commented 8 years ago

As discussed in #17.

This is currently dependent on Polylang, so even if you think it looks good, don't merge just yet.

Should we implement support for other multilingual plugins too?

timiwahalahti commented 8 years ago

I think there's no need to implement support for other multilingual plugins at this time. It is also kinda decision about if we wan't to encourage usage of badly coded monster sized things (wpml :trollface:).

k1sul1 commented 8 years ago

Yeah I agree.

I could rename the class to WPLF_Polylang, just for clarity. I could also make the class loading optional, if someone wants to make a WPML port of it.

I researched it briefly, and the WPML string translation logic isn't that different, but there is no way I'm going to install WPML on any of my projects.

k1sul1 commented 8 years ago

Okay, I made the changes.

What do you think @anttiviljami?

anttiviljami commented 8 years ago

Gorgeous! Merging right away!

Thank you !

jpeltoniemi commented 7 years ago

Not a big deal, but double curly braces are pretty common as placeholder delimiters, meaning that eventually there's going to be collision. In my case some placeholders for template bindings were stripped of curly braces, which resulted in some loud, naughty words and a half hour long bug hunting trip in all the wrong places.

Luckily this is an edge case and I can use alternative syntax for placeholders, but I might even try to modify the code a bit, if it could be considered an actual improvement and worthy of a pull request.

k1sul1 commented 7 years ago

I think we could provide a filter to change the delimiters? Shouldn't be too hard to implement.

I wouldn't want to break any existing functionality, even if this feature hasn't been officially released just yet, hence the filter.

anttiviljami commented 7 years ago

I like the idea of setting up custom delimiters via filter. I don't see many cases where using double handlebars is actually an issue

jpeltoniemi commented 7 years ago

Filters for delimiters might be good, but keep in mind that if at some point another plugin uses wplf+polylang, changing delimiters would probably cause trouble.

I had a different idea - I made a small change to the delimiter regex, which now matches the inner 2 curly braces instead of the outer ones, so {{{{foo}}}} becomes {{foo}} after going through WPLF-Polylang . I think this solves most of the problems in similar cases and as a bonus doesn't expose the delimiter regex to changes by short-sighted users.

classes/class-wplf-polylang.php, line 8 protected $regular_expression = "/{{[^{}]+}}/"; // matches {{, anything that is not either { or } and finally }}