Jump to content

Sanitizer Transliterate


Robin S
 Share

Recommended Posts

A community member raised a question and I thought a new sanitizer method for the purpose would be useful, hence...

Sanitizer Transliterate

Adds a transliterate method to $sanitizer that performs character replacements as defined in the module config. The default character replacements are based on the defaults from InputfieldPageName, but with uppercase characters included too.

Usage

Install the Sanitizer Transliterate module.

Customise the character replacements in the module config as needed.

Use the sanitizer on strings like so:

$transliterated_string = $sanitizer->transliterate($string);

transliterate

 

https://github.com/Toutouwai/SanitizerTransliterate
https://modules.processwire.com/modules/sanitizer-transliterate/

 

  • Like 11
  • Thanks 2
Link to comment
Share on other sites

Hey @bernhard - just an FYI regarding your PR which I think it a great idea by the way, but I don't think Ryan wants "all" to actually be all sanitizers:  https://github.com/processwire/processwire-issues/issues/85

Quote

excluded sanitizers are those that require secondary/non-value arguments, like match(), option() and options().

 

  • Like 1
Link to comment
Share on other sites

Hey @Robin S - this looks great!

I just noticed that the contents of your $default_replacements array is much more comprehensive than the list of character replacements in the InputfieldPageName settings in the core. Not sure whether Ryan would be willing to change those, but it seems to me that your list should be used there. Then perhaps you could pull that list in for your module and users of your module would benefit from any manual additions they have made to those settings, rather than using the character_replacements_str config setting in this module - it seems to me that users may need to add their custom replacements to both places at the moment.

  • Like 3
Link to comment
Share on other sites

1 hour ago, adrian said:

your $default_replacements array is much more comprehensive than the list of character replacements in the InputfieldPageName settings in the core

It would be great having "ő", "Ő" (=> "o") and "ű", "Ű" (=> "u") on the list. I've requested it years ago but it haven't found its way to the core.

  • Like 2
Link to comment
Share on other sites

10 hours ago, bernhard said:

I think it would be nice to also list this sanitizer in the testAll()

Sure, I will keep an eye on the core and merge your PR as soon as Ryan adds support for it.

8 hours ago, adrian said:

I just noticed that the contents of your $default_replacements array is much more comprehensive than the list of character replacements in the InputfieldPageName settings in the core.

It's actually not that much more comprehensive. ?
The only additions are the macronised vowels (āēīōū), which is something I wanted for my New Zealand context because they are used in Maori. The difference is that the list includes uppercase versions of the characters. I simply took the character list from InputfieldPageName, added the macronised vowels, and ran it through mb_strtoupper(). Adding uppercase characters to InputfieldPageName wouldn't make sense because page names are forced to lowercase.

8 hours ago, adrian said:

it seems to me that users may need to add their custom replacements to both places at the moment

I had in mind that this sanitizer could be used for broader purposes besides converting characters to ASCII. Using the character replacements from InputfieldPageName seemed like a good starting point (particularly given the question that gave rise to the module) but a person could configure all kinds of replacements to suit their needs. There could well be cases where these substitutions would not be wanted in InputfieldPageName.

2019-03-12_101843.png.66bfdb526642e8daf9d350e08aa53623.png

  • Like 2
Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...