php-gettext / Gettext

PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
MIT License
687 stars 132 forks source link

[question] How to store arbitrary key-value payload in Translation objects, now that it can no longer be faked using references? #290

Closed rulatir closed 3 weeks ago

rulatir commented 1 year ago

In previous versions, one could use $translation->addReference() to store arbitrary key-value payload in Translation objects. Since the $line parameter wasn't typehinted, one could use arbitrary string keys, turning the references into a key-value store.

In more current versions, to which I am trying to upgrade, the API is $translation->getReferences()->add(), and the ->add() method requires that the $line parameter be an int. Code that used references as payload store can no longer work.

What is the recommended way to store arbitrary key-value payload in Translation objects now?

If I have a .po file with non-string lines in references, created by previous version of my code, will the current version of this library be able to load these?

oscarotero commented 1 year ago

The references object is to store the different places where the translation is used. It's not meant to store arbitrary data. You can use headers for that.