בעיה בהקידוד תווים מיוחדים בטיפים להכנסה

סיכום מבוסס בינה מלאכותית

Users reported an encoding issue with special characters—specifically apostrophes—in onboarding tooltips on Discourse, particularly affecting French translations. Canapin first highlighted the problem with a screenshot, noting it might affect all tooltips. Arkshine investigated the code and found that the escape function is applied to button labels and content, questioning whether escaping is necessary since templates may handle it automatically. pequiste suggested replacing the programming apostrophe (') with the correct French typographic apostrophe (’), which is standard on modern French keyboards (AFNOR AZERTY or BÉPO), though not on older layouts. evenlo confirmed the issue on Discourse 3.4.1 and shared a workaround using custom JavaScript to replace ' with ’ in I18n.translations, carefully preserving HTML tags. Finally, pmusaraj confirmed the issue has been resolved in Discourse via a recent commit, thanking users for the report. The core problem was improper escaping of typographic characters in translated strings, and while a workaround exists, the official fix is now merged.

See the button:

I wouldn’t be surprised if the issue was present inall the tooltips.

6 לייקים

I stumbled on the same issue.

A quick look to Discourse shows that escape is used on the button label, title and content.

https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/components/user-tip.gjs#L38-L39

https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/components/user-tip.gjs#L54-L58

What does escape:
https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/lib/escape.js

In a text context, this seems all valid characters to use.

I wonder, is it required here?
I believe html not marked with htmlSafe will be escaped by the template? :thinking:

2 לייקים

A fix could be to replace the programming apostrophe with the actual French apostrophe.

Use: ’
Not: '

This symbol does not exist on US QWERTY keyboards and does not exist either on older AZERTY ones but it does exist on both new AFNOR (Association française de normalisation) standard French keyboards, either new AZERTY or BÉPO.

It wouldn’t fix the deeper issue that the programmatic apostrophe is not correctly escaped, but the real French apostrophe is the correct one to use and should be the one most French speakers will use in typing once a majority of them will be on standard keyboards.

The old AZERTY was never actually standardized by any official body.

לייק 1

Got same issue on Discourse 3.4.1 …
I can’t possibly replace all the ' on the website. Do you have any suggestions?

I just fixed thiss issue with some custom code, replace ' to ’ in I18n.translations

withPluginApi("0.8.18", (api) => {
    const locale = I18n.currentLocale();

    function replaceSingleQuotes(obj) {
        if (typeof obj === 'string') {
            // Split the string into HTML tags and non-tag parts
            return obj.split(/(<[^>]+>)/g).map(segment => {
                // If the segment is an HTML tag, do not replace anything
                if (segment.startsWith('<') && segment.endsWith('>')) {
                    return segment;
                } else {
                    // Replace single quotes only in non-HTML parts
                    return segment.replace(/'/g, '’');
                }
            }).join('');
        } else if (typeof obj === 'object' && obj !== null) {
            // Recursively process object properties
            for (const key in obj) {
                obj[key] = replaceSingleQuotes(obj[key]);
            }
        }
        return obj;
    }

    if (I18n.translations[locale].js) {
        I18n.translations[locale].js = replaceSingleQuotes(I18n.translations[locale].js);
    }
});

לייק 1

This should be fixed now following this commit: FIX: user tips in languages with apostrophes by pmusaraj · Pull Request #34118 · discourse/discourse · GitHub

Thanks for the report!

4 לייקים

נושא זה נסגר אוטומטית לאחר 3 ימים. לא ניתן להוסיף תגובות חדשות.