willdurand / BazingaJsTranslationBundle

A pretty nice way to expose your Symfony translation messages to your client applications.
MIT License
572 stars 178 forks source link

Allows escaping the pipe character #342

Open michael-haberzettel opened 1 year ago

michael-haberzettel commented 1 year ago

Hello,

Do you think, it is possible to manage escaping the pipe characters in pluralization ? This issue has been fixed in Symfony here : https://github.com/symfony/symfony/pull/17662

There is an example to translate this regex in (modern) javascript and split parts :

const splitRegex = new RegExp(/(?:\|\||[^\|])+/g)
function splitChoices(message) {
    const matchResult = message.match(splitRegex)
    const parts = [...matchResult] // Convert iterable to an array

    // unescape pipes in parts
    return parts.map((result) => result.replaceAll('||', '|'))
}

Thanks for this great library!