I'm taking a beating from biblatex's punctuation tracker, and thought I'd better ask for some assistance.
I'm trying to create a macro which is meant to be used as a general flag that I have translated a certain quotation. The natural place for this would be the citation postnote, but I wouldn't want to overdo it, and I think it is enough to do it every chapter, or section.
So, I came up with the following macro:
\newcounter{mytranslationcount}[section]
\newrobustcmd*{\mytranslation}{%
\ifnum\value{mytranslationcount}=0
\addcomma\addspace\printtext{my translation, as will be all following ones
in a foreign language}%
\stepcounter{mytranslationcount}%
\fi}
It mostly works, but not quite. It does print the intended text when it should. However, it messes with biblatex's punctuation tracker, and this results in undesired output when the macro prints nothing, and there is nothing else in the postnote. In this case, the printing of the postnote, which from biblatex's point of view is not empty, triggers the punctuation tracker and we get a comma. And, as nothing else comes after it, we also lose the final period (in the case of a footnote).
A MWE:
\documentclass{article}
\usepackage[style=authoryear,autocite=footnote]{biblatex}
\addbibresource{biblatex-examples.bib}
\newcounter{mytranslationcount}[section]
\newrobustcmd*{\mytranslation}{%
\ifnum\value{mytranslationcount}=0
\addcomma\addspace\printtext{my translation, as will be all following ones
in a foreign language}%
\stepcounter{mytranslationcount}%
\fi}
\begin{document}
\section{Section 1}
% Looks good.
\autocite[\pnfmt{3333-3345}\mytranslation]{sigfridsson}
% Also good.
\autocite[\pnfmt{3333-3345}\mytranslation]{sigfridsson}
\section{Section 2}
% Still good.
\autocite[\mytranslation]{sigfridsson}
% This is the offending one. When there is nothing else in the postnote and
% \mytranslation prints nothing, biblatex has already called in the postnote
% punctuation from the tracker, so that we get an unwanted comma and lose an
% wanted period.
\autocite[\mytranslation]{sigfridsson}
\end{document}
I was hoping for one such macro I could use like this in the postnote, for the semantic value of doing it this way. Given this hope, I haven't yet tried to resort to \AtNextCite(key), or to tampering with the postnote macro directly, but I'm all ears...

\autocite[\mytranslation]{sigfridsson}thepostnoteis not (seen/checked as) empty, even if\mytranslationends up printing nothing, so the right thing to do forbiblatexis to print the postnote delimiter and then the postnote (which here prints nothing). – moewe Apr 21 '21 at 20:13postnotebibmacro, and append something which is printed conditionally to a boolean which I could set\AtNextCite. But that's not a nice way to use it in the document. – gusbrs Apr 21 '21 at 20:17\mytranslationas part of the optional argument to\autocite. Correct? – Werner Apr 21 '21 at 20:24\mytranslationdoesn't print anything in those cases, you actually have to execute the macro. But the usual\iffieldundeftest that is employed here is much simpler than that and doesn't expand the macros at all. What you could do instead (and in my book that would probably already count as hack) is to print the postnote and measure its width: If the width is 0pt, there postnote is empty. ... – moewe Apr 21 '21 at 20:34%after0in the code or the macro\addcommawould be untimely expanded. – egreg Apr 21 '21 at 21:38\AtEveryCitekey{\setbox0=\hbox{\thefield{postnote}\unskip}\ifdim\wd0=0pt \clearfield{postnote} \fi \booltrue{mytranslationbool}}, and using\ifbool{mytranslationbool}{\stepcounter{mytranslationcount}}{}to set the counter in the macro. Is that what you had in mind? It is not really pretty, but seems to be working. WDYT? Particularly, would you say that, even if not pretty, it is robust? – gusbrs Apr 22 '21 at 02:10\@startsectionand related commands. – egreg Apr 22 '21 at 20:22