translationstring icon indicating copy to clipboard operation
translationstring copied to clipboard

Apply mapped values when coercing to native string.

Open malthe opened this issue 14 years ago • 5 comments

  • When a translation string is coerced to its native string type (i.e. the built-in string or unicode type), the default translation (or msgid if not applicable) is returned with any mapped values applied.

malthe avatar Aug 15 '11 11:08 malthe

The problem with this patch seems to be that coercion isn't performed very often.

Imagine you have a test for a bit of code that produces the message "Hello, ${user}!". The test compares with "Hello, Wichert!" and passes fine. Now you add translations, and make that message translatable. Suddenly, your test will have to be made aware of the fact that it's dealing with a translationstring, and not a normal string. Despite translationstring's efforts to be really interchangeable, your test will have to call 'tstring.interpolate()' and compare with that now.

This problem persists even with malthe's patch applied. I think what we want is set the value of our translationstring to be that of the interpolated string, and not the msgid. Which probably means that translationstring needs to grow another 'msgid' attribute, which holds the original msgid.

dnouri avatar Feb 08 '12 18:02 dnouri

Makes sense.

Or: Provide a custom implementation for the __eq__ method that compares oranges with oranges, apples with apples – so to speak.

malthe avatar Feb 08 '12 19:02 malthe

I have added a test for equality. It doesn't seem to be a problem.

malthe avatar Feb 08 '12 21:02 malthe

From looking at the test, I'm not sure what it's testing. Could you add a test for:

self.assertEqual("This is Zope version 3.", inst)

dnouri avatar Feb 09 '12 11:02 dnouri

How does that look?

malthe avatar Feb 09 '12 12:02 malthe